Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
fix/clients_manage_their_own_sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Apr 21, 2024
1 parent 35973c0 commit d3dad54
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions hivemind_core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,7 @@ def handle_internal_mycroft(self, message: str):
if not isinstance(target_peers, list):
target_peers = [target_peers]

new_sess = Session.from_message(message)
for peer, client in self.clients.items():
# ovos-core decides the runtime contents of the Session,
# let's sync any internal changes
if new_sess.session_id == client.sess.session_id:
LOG.debug(f"syncing session from ovos with {peer}")
client.sess = Session.from_message(message)
client.sess.site_id = client.site_id

if peer in target_peers:
# forward internal messages to clients if they are the target
LOG.debug(f"{message.msg_type} - destination: {peer}")
Expand Down Expand Up @@ -497,6 +489,10 @@ def _handle_dialog_transformers(self, message: Message) -> Message:
def handle_bus_message(
self, message: HiveMessage, client: HiveMindClientConnection
):
# update the session as received by the client
client.sess = Session.from_message(message.payload)
LOG.debug(f"Client session updated: {client.sess.serialize()}")

if message.payload.msg_type == "recognizer_loop:utterance":
message._payload = self._handle_utt_transformers(message.payload).serialize()
if message.payload.msg_type == "speak":
Expand Down Expand Up @@ -619,7 +615,7 @@ def handle_escalate_message(
bus.emit(message)

# HiveMind mycroft bus messages - from slave -> master
def update_slave_session(self, message: Message, client: HiveMindClientConnection):
def update_slave_session(self, message: Message, client: HiveMindClientConnection) -> Message:
"""slave injected a message, master decides what the session is unconditionally (active skills etc)
handle special message that influence session per client and update HM session as needed here
"""
Expand All @@ -643,11 +639,9 @@ def handle_inject_mycroft_msg(
# ensure client specific session data is injected in query to ovos
message.context["session"] = client.sess.serialize()
if message.msg_type == "speak":
message.context["destination"] = ["audio"]
message.context["destination"] = ["audio"] # make audible, this is injected "speak" command
elif message.context.get("destination") is None:
message.context[
"destination"
] = "skills" # ensure not treated as a broadcast
message.context["destination"] = "skills" # ensure not treated as a broadcast

# send client message to internal mycroft bus
LOG.info(f"Forwarding message to mycroft bus from client: {client.peer}")
Expand Down

0 comments on commit d3dad54

Please sign in to comment.