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

Type handlers #2

Open
taoufik07 opened this issue Mar 1, 2019 · 2 comments
Open

Type handlers #2

taoufik07 opened this issue Mar 1, 2019 · 2 comments

Comments

@taoufik07
Copy link
Owner

Hey,

Channels allows code decoupling by dispatching messages to handlers chat.join triggers chat_join.

I've made something similar while playing with asyncio and decided to try to implement it in nejma (checkout this branch).

Usage (a gist with the whole app)

@app.websocket_route("/ws")
class Chat(WebSocketEndpoint):
    encoding = "json"

    async def on_receive(self, websocket, data):
        ...
        group = f"group_{room_id}"

        self.channel_layer.add(group, self.channel)
        
        await self.channel_layer.group_send(group, {
            "type": "hello.world",
            "message": "Hello world !",
        })

    async def hello_world(self, payload):
        await self.send(payload)

I wanna know what you guys and if it should be in master ?

@taoufik07
Copy link
Owner Author

it's integrated with starlette for now, it's just a test and the implementation need to be reviewed to have loose coupling and reusable components.
Also feedback about the implementation will be appreciated.

@taoufik07
Copy link
Owner Author

@andrewgodwin @ERM @kcrebound @tomchristie
if you got some free time, your feedback will be greatly appreciated :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant