-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import asyncio | ||
import json | ||
from typing import Any, Dict | ||
from realtime.channel import Channel | ||
import logging | ||
|
||
class Push: | ||
def __init__(self, channel: Channel, event: str, payload: Dict[str, Any] = {}): | ||
self.channel = channel | ||
self.event = event | ||
self.payload = payload | ||
self.ref = "" | ||
|
||
|
||
def send(self): | ||
asyncio.get_event_loop().run_until_complete(self._send()) | ||
|
||
async def _send(self): | ||
self.ref = self.channel.socket._make_ref() | ||
|
||
message = { | ||
"topic": self.channel.topic, | ||
"event": self.event, | ||
"payload": self.payload, | ||
"ref": self.ref, | ||
} | ||
|
||
try: | ||
await self.socket.ws_connection.send(json.dumps(message)) | ||
except Exception as e: | ||
logging.error(f"send push failed: {e}") | ||
|
||
|
||
|
||
def update_payload(self, payload: Dict[str, Any]): | ||
self.payload = { **self.payload, **payload } |
File renamed without changes.