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

Error in room #4

Closed
wants to merge 1 commit into from
Closed

Conversation

lautarodapin
Copy link

You are passing "server" as user_id to the broadcast method, this user_id will never exists.
Thunder endpoint

@app.post("/thunder")
async def thunder(request: Request, distance: ThunderDistance = Body(...)):
    """Broadcast an ambient message to all chat room users.
    """
    room: Optional[Room] = request.get("room")
    if room is None:
        raise HTTPException(500, detail="Global `Room` instance unavailable!")
    if distance.category == Distance.Near:
        await room.broadcast_message("server", "Thunder booms overhead")
    elif distance.category == Distance.Far:
        await room.broadcast_message("server", "Thunder rumbles in the distance")
    else:
        await room.broadcast_message("server", "You feel a faint tremor")

``broadcast_messagemethod inRoom` class

async def broadcast_message(self, user_id: str, msg: str):
        """Broadcast message to all connected users.
        """
        # self._user_meta[user_id].message_count += 1 
        for websocket in self._users.values():
            await websocket.send_json(
                {"type": "MESSAGE", "data": {"user_id": user_id, "msg": msg}}
            )

@coolmian
Copy link

coolmian commented Nov 1, 2021

if user_id in self._user_meta:
self._user_meta[user_id].message_count += 1

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

Successfully merging this pull request may close these issues.

None yet

2 participants