Exemplo n.º 1
0
    def notify_user_message(self, user, session_id, message):
        """Triggered by a client 'sendMessage' call.
        The message encodes a chat message from the client.
        """
        if message is None:
            self.log.warning("None message received")
            raise NotificationError("None message received")

        # Message must be in the form "CHAT|<message>".
        msg_tokens = message.split('|')
        if len(msg_tokens) != 2 or msg_tokens[0] != "CHAT":
            self.log.warning("Wrong message received")
            raise NotificationError("Wrong message received")

        # Retrieves the user session info associated with the session_id.
        with self.sessions_lock:
            session_info = self.sessions.get(session_id)
            if session_info is None:
                raise NotificationError(("Session lost! Please reload the "
                                         "browser page(s)."))

        # Extracts from the info the IP and the user agent, to identify the
        # originator of the # message.
        ipaddress = session_info["REMOTE_IP"]
        user_agent = session_info["USER_AGENT"]

        # Sends the message to be pushed to the browsers.
        self.data_adapter.send_message(ipaddress, user_agent, msg_tokens[1])
Exemplo n.º 2
0
 def test_nns_notification_error(self):
     """Tests the response to a NNS request in case of a
     NotificationError.
     """
     error = NotificationError("error")
     res = metadata_protocol.write_notify_new_session(error)
     self.assertEqual("NNS|EN|error", res)
Exemplo n.º 3
0
 def test_nsc_notification_error(self):
     """Tests the response to a NSC request in case of a NotficationError.
     """
     error = NotificationError("Notification Error")
     res = metadata_protocol.write_notify_session_close(error)
     self.assertEqual("NSC|EN|Notification+Error", res)
Exemplo n.º 4
0
 def test_num_notification_error(self):
     """Tests the response to a NUM request in case of a NotificationError.
     """
     error = NotificationError("Notification Error")
     res = metadata_protocol.write_notify_user_message(error)
     self.assertEqual("NUM|EN|Notification+Error", res)