Skip to content

Commit

Permalink
cleanup socket mgmt
Browse files Browse the repository at this point in the history
  • Loading branch information
callmephilip committed Nov 20, 2024
1 parent 303f83a commit d17d92e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,12 @@ async def dispatch_incoming_message(m: ChannelMessage):
logger.debug(f"sockets {s}")
# send message to each socket
for c_s in s:
logger.debug(f"sending message to {c_s.sid} {connections[c_s.sid]}")
await connections[c_s.sid](Div(id=f"channel-{m.channel}", hx_swap="scroll:bottom", hx_swap_oob="afterbegin")(m_with_ctx))
conn = connections.get(c_s.sid)
if not conn: continue
logger.debug(f"sending message to {c_s.sid}")
try:
await conn(Div(id=f"channel-{m.channel}", hx_swap="scroll:bottom", hx_swap_oob="afterbegin")(m_with_ctx))
except: logger.error(f"Error sending message to {c_s.sid}")

@rt('/messages/send/{cid}', methods=['POST'])
async def send_msg(msg:str, cid:int, req: Request):
Expand Down

0 comments on commit d17d92e

Please sign in to comment.