예제 #1
0
    def __init__(self, streamer_name, namespace='/chat'):
        self._streamer_name = streamer_name
        self.namespace = namespace 
        self._website_url = 'http://www.watchpeoplecode.com/socket.io/1/'
        key, heartbeat = self._connect_to_server_helper()
        self._heartbeat = heartbeat/2 
        
        # alters URL to be more websocket...ie
        self._website_socket = self._website_url.replace('http', 'ws') + 'websocket/'
        super(ReadOnlyWebSocket, self).__init__(
                self._website_socket + key,
                on_open=self.on_open, on_close=self.on_close,
                on_message=self.on_message, 
                on_error=self.on_error)
        
        # start a thread and set the socket to run forever
        self._thread = Thread(target=self.run_forever)
        self._thread.setDaemon(True)
        self._thread.start()

        # use the trivial instance `_messager` to get around multiple inheritance
        # problems with PyQt
        self._messager = Messager()
        # Duck type the `chat_signal` onto the `Socket` instance/class
        self.chat_signal = self._messager.chat_signal