Skip to content

Commit

Permalink
Remove sid on disconnect to avoid sending packets in headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
deiteris committed Aug 3, 2024
1 parent 4c8f0d1 commit b1aa1c5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/sio/MMVC_Namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = logging.getLogger(__name__)

class MMVC_Namespace(socketio.AsyncNamespace):
sid: int = 0
sid: str | None = None

async def emitTo(self, vol, perf, err):
if err is not None:
Expand All @@ -19,7 +19,8 @@ async def emitTo(self, vol, perf, err):
await self.emit("server_stats", [vol, perf], to=self.sid)

def emit_coroutine(self, vol, perf, err):
asyncio.run(self.emitTo(vol, perf, err))
if self.sid:
asyncio.run(self.emitTo(vol, perf, err))

def __init__(self, namespace: str, voiceChangerManager: VoiceChangerManager):
super().__init__(namespace)
Expand Down Expand Up @@ -55,4 +56,5 @@ async def on_request_message(self, sid, msg):
await self.emit("response", [send_timestamp, out_audio, ping, vol, perf], to=sid)

def on_disconnect(self, sid):
self.sid = None
logger.info(f"Disconnected SID: {sid}")

0 comments on commit b1aa1c5

Please sign in to comment.