mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-12 15:59:30 -05:00
Forcefully disconnect the user from socketio on disconnect event
This commit is contained in:
parent
fe7bd43f04
commit
1b0979e6ed
@ -83,7 +83,11 @@ class ChatModeWeb:
|
|||||||
title=self.web.settings.get("general", "title"),
|
title=self.web.settings.get("general", "title"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@self.web.app.route("/update-session-username", methods=["POST"], provide_automatic_options=False)
|
@self.web.app.route(
|
||||||
|
"/update-session-username",
|
||||||
|
methods=["POST"],
|
||||||
|
provide_automatic_options=False,
|
||||||
|
)
|
||||||
def update_session_username():
|
def update_session_username():
|
||||||
history_id = self.cur_history_id
|
history_id = self.cur_history_id
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
@ -122,6 +126,8 @@ class ChatModeWeb:
|
|||||||
A status message is broadcast to all people in the room."""
|
A status message is broadcast to all people in the room."""
|
||||||
if self.validate_username(session.get("name")):
|
if self.validate_username(session.get("name")):
|
||||||
self.connected_users.append(session.get("name"))
|
self.connected_users.append(session.get("name"))
|
||||||
|
# Store the session id for the user
|
||||||
|
session["socketio_session_id"] = request.sid
|
||||||
emit(
|
emit(
|
||||||
"status",
|
"status",
|
||||||
{
|
{
|
||||||
@ -133,7 +139,7 @@ class ChatModeWeb:
|
|||||||
broadcast=True,
|
broadcast=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ConnectionRefusedError('You are active from another session!')
|
raise ConnectionRefusedError("You are active from another session!")
|
||||||
|
|
||||||
@self.web.socketio.on("text", namespace="/chat")
|
@self.web.socketio.on("text", namespace="/chat")
|
||||||
def text(message):
|
def text(message):
|
||||||
@ -153,9 +159,9 @@ class ChatModeWeb:
|
|||||||
new_name = message.get("username", "").strip()
|
new_name = message.get("username", "").strip()
|
||||||
if self.validate_username(new_name):
|
if self.validate_username(new_name):
|
||||||
session["name"] = new_name
|
session["name"] = new_name
|
||||||
self.connected_users[
|
self.connected_users[self.connected_users.index(current_name)] = (
|
||||||
self.connected_users.index(current_name)
|
session.get("name")
|
||||||
] = session.get("name")
|
)
|
||||||
emit(
|
emit(
|
||||||
"status",
|
"status",
|
||||||
{
|
{
|
||||||
@ -178,8 +184,18 @@ class ChatModeWeb:
|
|||||||
def disconnect():
|
def disconnect():
|
||||||
"""Sent by clients when they disconnect.
|
"""Sent by clients when they disconnect.
|
||||||
A status message is broadcast to all people in the server."""
|
A status message is broadcast to all people in the server."""
|
||||||
|
user_already_disconnected = False
|
||||||
if session.get("name") in self.connected_users:
|
if session.get("name") in self.connected_users:
|
||||||
self.connected_users.remove(session.get("name"))
|
self.connected_users.remove(session.get("name"))
|
||||||
|
else:
|
||||||
|
user_already_disconnected = True
|
||||||
|
|
||||||
|
# Forcefully disconnect the user
|
||||||
|
self.web.socketio.server.disconnect(
|
||||||
|
sid=session.get("socketio_session_id"), namespace="/chat"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not user_already_disconnected:
|
||||||
emit(
|
emit(
|
||||||
"status",
|
"status",
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user