def __init__(self, *args, **kw):
     self.subscribe = Subscribe(self)
     self.redis = redis_client
     self.logger = logging.getLogger(__name__)
     self.conf = SockJSServerSettings()
     self.id = self._generate_connection_id()
     super(SockJSConnection, self).__init__(*args, **kw)
class SockJSConnection(sockjs.tornado.SockJSConnection):

    sockjs_server = None  # should be initialized by router

    def __init__(self, *args, **kw):
        self.subscribe = Subscribe(self)
        self.redis = redis_client
        self.logger = logging.getLogger(__name__)
        self.conf = SockJSServerSettings()
        self.id = self._generate_connection_id()
        super(SockJSConnection, self).__init__(*args, **kw)

    def on_open(self, info):
        self.sockjs_server.add_event_listener(self)

    def on_close(self):
        self.subscribe.remove()
        self.sockjs_server.remove_event_listener(self)

    def on_message(self, message):
        self.logger.debug('Get message %s' % message)
        self.subscribe.add(message)

    def _generate_connection_id(self):
        client = self
        now = datetime.datetime.utcnow()
        seconds = time.mktime(now.timetuple()) + now.microsecond / 1e6
        connection_id = hashlib.md5("{} {}".format(seconds, id(client)).encode()).hexdigest()
        return connection_id
Ejemplo n.º 3
0
class SockJSConnection(sockjs.tornado.SockJSConnection):

    sockjs_server = None  # should be initialized by router

    def __init__(self, *args, **kw):
        self.subscribe = Subscribe(self)
        self.redis = redis_client
        self.logger = logging.getLogger(__name__)
        self.conf = SockJSServerSettings()
        self.id = self._generate_connection_id()
        super(SockJSConnection, self).__init__(*args, **kw)

    def on_open(self, info):
        self.sockjs_server.add_event_listener(self)

    def on_close(self):
        self.subscribe.remove()
        self.sockjs_server.remove_event_listener(self)

    def on_message(self, message):
        self.logger.debug('Get message %s' % message)
        self.subscribe.add(message)

    def _generate_connection_id(self):
        client = self
        now = datetime.datetime.utcnow()
        seconds = time.mktime(now.timetuple()) + now.microsecond / 1e6
        connection_id = hashlib.md5(
            "%s %s" % (
                seconds,
                id(client)
            )
        ).hexdigest()
        return connection_id
Ejemplo n.º 4
0
 def __init__(self, *args, **kw):
     self.subscribe = Subscribe(self)
     self.redis = redis_client
     self.logger = logging.getLogger(__name__)
     self.conf = SockJSServerSettings()
     self.id = self._generate_connection_id()
     super(SockJSConnection, self).__init__(*args, **kw)
Ejemplo n.º 5
0
class SockJSConnection(sockjs.tornado.SockJSConnection):

    sockjs_server = None  # should be initialized by router

    def __init__(self, *args, **kw):
        self.subscribe = Subscribe(self)
        self.redis = redis_client
        self.logger = logging.getLogger(__name__)
        self.conf = SockJSServerSettings()
        self.id = self._generate_connection_id()
        super(SockJSConnection, self).__init__(*args, **kw)

    def on_open(self, info):
        self.sockjs_server.add_event_listener(self)

    def on_close(self):
        self.subscribe.remove()
        self.sockjs_server.remove_event_listener(self)

    def on_message(self, message: str):
        '''
        message like this: {'token': '548121dc2872a5fcca14685eb5ae90c9', 'data': {'to_channel': 'Ezreal'}}
        '''
        # from system.tools import user_has_channel
        # json_obj = json.loads(message)
        # self.logger.debug('On message >>> %s' % json_obj)
        # if json_obj['host'] == 'MQ1':
        #     self.logger.debug('Get message %s' % message)
        #     self.subscribe.add(message)
        # token = json_obj['token']
        # channel_id = self.redis.get(token)
        # has_channel = user_has_channel(token, channel_id)
        # has_channel = True
        # if has_channel:
        #     s = SockJsServerClient()
        #     s.publish_message(json_obj, 'MQ1')    # put into MQ1
        self.logger.debug('Get message %s' % message)
        self.subscribe.add(message)

    def _generate_connection_id(self):
        client = self
        now = datetime.datetime.utcnow()
        seconds = time.mktime(now.timetuple()) + now.microsecond / 1e6
        connection_id = hashlib.md5("{} {}".format(
            seconds, id(client)).encode(encoding='utf-8')).hexdigest()
        return connection_id
Ejemplo n.º 6
0
class SockJSConnection(sockjs.tornado.SockJSConnection):

    pika_client = None  # should be initialized by router

    def __init__(self, *args, **kw):
        self.subscribe_list = set()
        self.subscribe = Subscribe(self)
        self.logger = logging.getLogger(__name__)
        super(SockJSConnection, self).__init__(*args, **kw)

    def on_open(self, info):
        self.pika_client.add_event_listener(self)

    def on_close(self):
        self.subscribe.remove()
        self.pika_client.remove_event_listener(self)

    def on_message(self, message):
        self.logger.debug('Get message %s' % message)
        self.subscribe.add(message)
Ejemplo n.º 7
0
class SockJSConnection(sockjs.tornado.SockJSConnection):

    pika_client = None  # should be initialized by router

    def __init__(self, *args, **kw):
        self.subscribe_list = set()
        self.subscribe = Subscribe(self)
        self.redis = redis_client
        self.logger = logging.getLogger(__name__)
        self.conf = SockJSServerSettings()
        super(SockJSConnection, self).__init__(*args, **kw)

    def on_open(self, info):
        self.pika_client.add_event_listener(self)

    def on_close(self):
        self.subscribe.remove()
        self.pika_client.remove_event_listener(self)

    def on_message(self, message):
        self.logger.debug('Get message %s' % message)
        self.subscribe.add(message)
Ejemplo n.º 8
0
 def __init__(self, *args, **kw):
     self.subscribe_list = set()
     self.subscribe = Subscribe(self)
     self.logger = logging.getLogger(__name__)
     super(SockJSConnection, self).__init__(*args, **kw)