-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.py
41 lines (29 loc) · 1.19 KB
/
notification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# coding: utf-8
from __future__ import unicode_literals
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
from autobahn.twisted.wamp import ApplicationRunner
from queue import NotificationRunner
from config.settings import REALM_NAME, WEB_SOCKET_HOST, WEB_SOCKET_PORT
class ListenForEvent(ApplicationSession):
def __init__(self, config):
ApplicationSession.__init__(self)
self.config = config
self.runner = NotificationRunner(self)
def onConnect(self):
self.join(self.config.realm)
@inlineCallbacks
def onJoin(self, details):
# callback = lambda x: log.msg("Received event %s" % x)
# yield self.subscribe(callback, 'un_evenement')
print("Client session joined: {}".format(details))
yield self.runner.connect()
def onLeave(self, details):
print('Client session left: {}'.format(details))
self.disconnect()
def onDisconnect(self):
print('Client session disconnected.')
# Start reactor here
if __name__ == '__main__':
runner = ApplicationRunner("ws://%s:%d/ws" % (WEB_SOCKET_HOST, WEB_SOCKET_PORT), REALM_NAME)
runner.run(ListenForEvent)