Exemplo n.º 1
0
    def process_message(self, client, payload, isBinary):
        """
       Process message from client, decide what to do internally here
       """
        LOG.info("processing message from client: " + str(client.peer))
        client_data = self.clients[client.peer]
        client_protocol, ip, sock_num = client.peer.split(":")

        if isBinary:
            # TODO receive files
            pass
        else:
            # add context for this message
            payload = payload.decode("utf-8")
            message = Message.deserialize(payload)
            message.context["source"] = client.peer
            message.context["destination"] = "skills"
            if "platform" not in message.context:
                message.context["platform"] = client_data.get(
                    "platform", "unknown")

            # messages/skills/intents per user
            if message.type in client.blacklist.get("messages", []):
                LOG.warning(client.peer + " sent a blacklisted message " \
                                          "type: " + message.type)
                return
            # TODO check intent / skill that will trigger

            # send client message to internal mycroft bus
            self.mycroft_send(message.type, message.data, message.context)
Exemplo n.º 2
0
 def handle_receive_server_message(self, message):
     server_msg = message.data.get("payload")
     is_file = message.data.get("isBinary")
     if is_file:
         # TODO received file
         pass
     else:
         # forward server message to internal bus
         message = Message.deserialize(server_msg)
         self.bus.emit(message)
Exemplo n.º 3
0
 def handle_message(self, message=None):
     # forward internal messages to clients if they are the target
     message = Message.deserialize(message)
     if message.type == "complete_intent_failure":
         message.type = "hive.complete_intent_failure"
     message.context = message.context or {}
     peer = message.context.get("destination")
     if peer and peer in self.clients:
         client_data = self.clients[peer] or {}
         client = client_data.get("object")
         message = message.serialize()
         client.sendMessage(bytes(message, encoding="utf-8"), False)
Exemplo n.º 4
0
 def handle_send_server_message(self, message):
     server_msg = message.data.get("payload")
     is_file = message.data.get("isBinary")
     if is_file:
         # TODO send file
         pass
     else:
         # send message to server
         server_msg = Message.deserialize(server_msg)
         server_msg.context["platform"] = platform
         self.sendMessage(server_msg.type, server_msg.data,
                          server_msg.context)
Exemplo n.º 5
0
 def wrapper(cl, message):
     message = Message.deserialize(message)
     self.handle_message(message)