Add callbacks for connect, disconnect and stop
This commit is contained in:
parent
7f187583aa
commit
a0bd6b71bf
1 changed files with 15 additions and 0 deletions
|
|
@ -12,6 +12,14 @@ class Connection():
|
||||||
"""
|
"""
|
||||||
Stays connected to a room in its own thread.
|
Stays connected to a room in its own thread.
|
||||||
Callback functions are called when a packet is received.
|
Callback functions are called when a packet is received.
|
||||||
|
|
||||||
|
Callbacks:
|
||||||
|
- all the message types from api.euphoria.io
|
||||||
|
These pass the packet data as argument to the called functions.
|
||||||
|
The other callbacks don't pass any special arguments.
|
||||||
|
- "connect"
|
||||||
|
- "disconnect"
|
||||||
|
- "stop"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, room):
|
def __init__(self, room):
|
||||||
|
|
@ -46,6 +54,9 @@ class Connection():
|
||||||
ROOM_FORMAT.format(self.room),
|
ROOM_FORMAT.format(self.room),
|
||||||
enable_multithread=True
|
enable_multithread=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.call_callback("connect")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except WSException:
|
except WSException:
|
||||||
if tries > 0:
|
if tries > 0:
|
||||||
|
|
@ -65,6 +76,8 @@ class Connection():
|
||||||
if self.ws:
|
if self.ws:
|
||||||
self.ws.close()
|
self.ws.close()
|
||||||
self.ws = None
|
self.ws = None
|
||||||
|
|
||||||
|
self.call_callback("disconnect")
|
||||||
|
|
||||||
def launch(self):
|
def launch(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -104,6 +117,8 @@ class Connection():
|
||||||
|
|
||||||
self.stopping = True
|
self.stopping = True
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
|
self.call_callback("stop")
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue