Skip to content
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

start channels (django) support #190

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
---------

v0.4.16
=======
- Channels (django) (https://github.com/django/channels) server support

v0.4.15
=======
- Websockets server support (https://github.com/python-websockets/websockets)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You may also install using some **extras**:
| rx | ReactiveX ([v3](https://pypi.org/project/Rx/)) integration | [Tutorial](https://rsocket.io/guides/rsocket-py/tutorial/reactivex) |
| reactivex | [ReactiveX](https://reactivex.io/) ([v4](https://pypi.org/project/reactivex/)) integration | [Tutorial](https://rsocket.io/guides/rsocket-py/tutorial/reactivex) |
| aiohttp | [aiohttp](https://docs.aiohttp.org/en/stable/) Websocket transport (server/client) | [Tutorial](https://rsocket.io/guides/rsocket-py/tutorial/websocket) |
| channels | Websocket transport (server only) using channels (django) | |
| quart | [Quart](https://pgjones.gitlab.io/quart/) Websocket transport (server only) | |
| quic | [QUIC](https://github.com/aiortc/aioquic) transport | |
| websockets | [Websockets](https://github.com/python-websockets/websockets) transport (server only) | |
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ pydantic==1.10.13
Werkzeug==3.0.1
graphql-core==3.2.3
gql==3.4.1
channels==4.0.0
websockets==12.0
asyncwebsockets==0.9.4
asyncwebsockets==0.9.4
29 changes: 29 additions & 0 deletions rsocket/transports/channels_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json

from channels.generic.websocket import WebsocketConsumer

from rsocket.frame import Frame
from rsocket.transports.abstract_messaging import AbstractMessagingTransport


class RSocketConsumer(WebsocketConsumer):
def connect(self):
self.accept()

def disconnect(self, close_code):
pass

def receive(self, text_data=None, bytes_data=None):
text_data_json = json.loads(text_data)
message = text_data_json["message"]

self.send(text_data=json.dumps({"message": message}))


class ChannelsTransport(AbstractMessagingTransport):

async def send_frame(self, frame: Frame):
pass

async def close(self):
pass
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ graphql =
graphql-core>=3.2.0
gql>=3.4.0
websockets = websockets>=11.0.0
channels = channels>=4.0.0
asyncwebsockets = asyncwebsockets>=0.9.4

[options.entry_points]
Expand Down