From 65fde4712089b5852bc18c33ff453a709c045bb8 Mon Sep 17 00:00:00 2001 From: Lars Benner Date: Sun, 5 May 2024 15:53:56 +0200 Subject: [PATCH] Added payload to join function. --- realtime/channel.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/realtime/channel.py b/realtime/channel.py index e4ac908..5f90544 100644 --- a/realtime/channel.py +++ b/realtime/channel.py @@ -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. :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: """ 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))