File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
template_fastapi/repositories Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,15 @@ def __init__(self):
34
34
35
35
async def handle_client_message (self , data : str , websocket : WebSocket , client_id : int ):
36
36
"""Handle a message from a client."""
37
- await self .manager .send_personal_message (f"You wrote: { data } " , websocket )
38
- await self .manager .broadcast (f"Client #{ client_id } says: { data } " )
37
+ # await self.manager.send_personal_message(f"You wrote: {data}", websocket)
38
+
39
+ # client_id が一致する client 以外にのみ data を送信する
40
+ for connection in self .manager .active_connections :
41
+ if connection != websocket :
42
+ await self .manager .send_personal_message (f"Client #{ client_id } says: { data } " , connection )
43
+
44
+ # もし全クライアントにブロードキャストしたい場合は以下の行を有効にしてください
45
+ # await self.manager.broadcast(f"Client #{client_id} says: {data}")
39
46
40
47
async def handle_client_disconnect (self , client_id : int ):
41
48
"""Handle a client disconnect."""
You can’t perform that action at this time.
0 commit comments