-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
16 changed files
with
600 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Union | ||
from grpclib.client import Channel | ||
from grpclib import GRPCError | ||
from nitric.exception import exception_from_grpc_error | ||
from nitric.utils import new_default_channel | ||
from nitric.proto.nitric.websocket.v1 import ( | ||
WebsocketServiceStub, | ||
WebsocketSendRequest, | ||
) | ||
|
||
|
||
class Websocket(object): | ||
"""Nitric generic Websocket client.""" | ||
|
||
def __init__(self): | ||
"""Construct a Nitric Websocket Client.""" | ||
self._channel: Union[Channel, None] = new_default_channel() | ||
# Had to make unprotected (publically accessible in order to use as part of bucket reference) | ||
self.websocket_stub = WebsocketServiceStub(channel=self._channel) | ||
|
||
async def send(self, socket: str, connection_id: str, data: bytes): | ||
"""Send data to a connection on a socket.""" | ||
try: | ||
await self.websocket_stub.send( | ||
websocket_send_request=WebsocketSendRequest(socket=socket, connection_id=connection_id, data=data) | ||
) | ||
except GRPCError as grpc_err: | ||
raise exception_from_grpc_error(grpc_err) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.