@@ -40,7 +40,7 @@ def __init__(self, socket: Socket, topic: str, params: Dict[str, Any] = {}) -> N
40
40
self .listeners : List [CallbackListener ] = []
41
41
self .joined = False
42
42
self .join_ref = str (uuid .uuid4 ())
43
- self .join_msg_ref = str ( uuid . uuid4 ())
43
+ self .control_msg_ref = ""
44
44
45
45
def join (self ) -> Channel :
46
46
"""
@@ -62,22 +62,23 @@ async def _join(self) -> None:
62
62
payload = {}, ref = None )
63
63
elif self .socket .version == 2 :
64
64
#[join_reference, message_reference, topic_name, event_name, payload]
65
- join_req = [self .join_ref , self .join_msg_ref , self .topic , ChannelEvents .join , {}]
65
+ self .control_msg_ref = str (uuid .uuid4 ())
66
+ join_req = [self .join_ref , self .control_msg_ref , self .topic , ChannelEvents .join , {}]
66
67
67
68
try :
68
69
await self .socket .ws_connection .send (json .dumps (join_req ))
69
70
except Exception as e :
70
71
print (str (e )) # TODO: better error propagation
71
72
return
72
73
73
- def leave (self ) -> Channel :
74
+ def leave (self ) -> None :
74
75
"""
75
76
Wrapper for async def _leave() to expose a non-async interface
76
77
Essentially gets the only event loop and attempt leaving a topic
77
- :return: Channel
78
+ :return: None
78
79
"""
79
80
loop = asyncio .get_event_loop () # TODO: replace with get_running_loop
80
- loop .run_until_complete (self ._join ())
81
+ loop .run_until_complete (self ._leave ())
81
82
return self
82
83
83
84
async def _leave (self ) -> None :
@@ -86,13 +87,13 @@ async def _leave(self) -> None:
86
87
:return: None
87
88
"""
88
89
if self .socket .version == 1 :
89
- join_req = dict (topic = self .topic , event = ChannelEvents .leave ,
90
+ leave_req = dict (topic = self .topic , event = ChannelEvents .leave ,
90
91
payload = {}, ref = None )
91
92
elif self .socket .version == 2 :
92
- join_req = [self .join_ref , None , self .topic , ChannelEvents .leave , {}]
93
+ leave_req = [self .join_ref , None , self .topic , ChannelEvents .leave , {}]
93
94
94
95
try :
95
- await self .socket .ws_connection .send (json .dumps (join_req ))
96
+ await self .socket .ws_connection .send (json .dumps (leave_req ))
96
97
except Exception as e :
97
98
print (str (e )) # TODO: better error propagation
98
99
return
0 commit comments