Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

How can I utilize broadcaster to subscribe multiple channel? #28

@vaibhavmule

Description

@vaibhavmule

I know a way to have a dynamic channel by having chatroom id in URL, /ws/{chat_id}

I want to send {'type': 'subscribe', 'chat_id': 'dsfjkhdskjfhdskjhfkjdsahfa'}

@app.websocket("/ws")
async def ws_manager(websocket: WebSocket):
    await websocket.accept()
    async for message in websocket.iter_json():
        if message['type'] == 'subscribe':
             chat_id = message['chat_id']
             async with broadcast.subscribe(channel=chat_id) as subscriber:
                   async for event in subscriber:
                       await websocket.send_text(event.message)

how can i have multiple subscriber for same socket connection?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions