-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Payload option for Channel.join() function #136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -36,23 +36,27 @@ def __init__(self, socket: Socket, topic: str, params: Dict[str, Any] = {}) -> N | |||||||||||||||||
self.listeners: List[CallbackListener] = [] | ||||||||||||||||||
self.joined = False | ||||||||||||||||||
|
||||||||||||||||||
def join(self) -> Channel: | ||||||||||||||||||
def join(self, payload: Dict[str, Any] = {}) -> Channel: | ||||||||||||||||||
""" | ||||||||||||||||||
Wrapper for async def _join() to expose a non-async interface | ||||||||||||||||||
Essentially gets the only event loop and attempt joining a topic | ||||||||||||||||||
:param payload: Optional, additional payload, which is sent to the | ||||||||||||||||||
server, when a channel is joined. | ||||||||||||||||||
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_clarification): Clarify the impact of the 'payload' on the server's response or channel state. Expanding on how the payload affects the server's handling of the join request or the state of the channel could provide clearer guidance to developers using this method.
Suggested change
|
||||||||||||||||||
:return: Channel | ||||||||||||||||||
""" | ||||||||||||||||||
loop = asyncio.get_event_loop() # TODO: replace with get_running_loop | ||||||||||||||||||
loop.run_until_complete(self._join()) | ||||||||||||||||||
loop.run_until_complete(self._join(payload)) | ||||||||||||||||||
return self | ||||||||||||||||||
|
||||||||||||||||||
async def _join(self) -> None: | ||||||||||||||||||
async def _join(self, payload: Dict[str, Any]) -> None: | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Parameter 'payload' in '_join' should be optional to match the public 'join' method. Making 'payload' optional in '_join' ensures that calls without a payload do not fail and maintains consistency with the public interface.
Suggested change
|
||||||||||||||||||
""" | ||||||||||||||||||
Coroutine that attempts to join Phoenix Realtime server via a certain topic | ||||||||||||||||||
:param payload: Optional, additional payload, which is sent to the | ||||||||||||||||||
server, when a channel is joined. | ||||||||||||||||||
:return: None | ||||||||||||||||||
""" | ||||||||||||||||||
join_req = dict(topic=self.topic, event="phx_join", | ||||||||||||||||||
payload={}, ref=None) | ||||||||||||||||||
payload=payload, ref=None) | ||||||||||||||||||
|
||||||||||||||||||
try: | ||||||||||||||||||
await self.socket.ws_connection.send(json.dumps(join_req)) | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code_clarification): Consider documenting the default behavior when 'payload' is not provided.
It might be helpful for users of this method to understand what the default payload behavior entails, especially if it affects the channel's state or interaction with the server.