Spaces:
Building
Building
Update chat_session/state_orchestrator.py
Browse files
chat_session/state_orchestrator.py
CHANGED
@@ -87,6 +87,9 @@ class StateOrchestrator:
|
|
87 |
self.event_bus.subscribe(EventType.SESSION_STARTED, self._handle_session_started)
|
88 |
self.event_bus.subscribe(EventType.SESSION_ENDED, self._handle_session_ended)
|
89 |
|
|
|
|
|
|
|
90 |
# STT events
|
91 |
self.event_bus.subscribe(EventType.STT_READY, self._handle_stt_ready)
|
92 |
self.event_bus.subscribe(EventType.STT_RESULT, self._handle_stt_result)
|
@@ -106,6 +109,24 @@ class StateOrchestrator:
|
|
106 |
# Error events
|
107 |
self.event_bus.subscribe(EventType.CRITICAL_ERROR, self._handle_critical_error)
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
async def _handle_conversation_started(self, event: Event) -> None:
|
110 |
"""Handle conversation start within existing session"""
|
111 |
session_id = event.session_id
|
|
|
87 |
self.event_bus.subscribe(EventType.SESSION_STARTED, self._handle_session_started)
|
88 |
self.event_bus.subscribe(EventType.SESSION_ENDED, self._handle_session_ended)
|
89 |
|
90 |
+
# ✅ WebSocket events
|
91 |
+
self.event_bus.subscribe(EventType.WEBSOCKET_DISCONNECTED, self._handle_websocket_disconnected)
|
92 |
+
|
93 |
# STT events
|
94 |
self.event_bus.subscribe(EventType.STT_READY, self._handle_stt_ready)
|
95 |
self.event_bus.subscribe(EventType.STT_RESULT, self._handle_stt_result)
|
|
|
109 |
# Error events
|
110 |
self.event_bus.subscribe(EventType.CRITICAL_ERROR, self._handle_critical_error)
|
111 |
|
112 |
+
async def _handle_websocket_disconnected(self, event: Event):
|
113 |
+
"""Handle WebSocket disconnection"""
|
114 |
+
session_id = event.session_id
|
115 |
+
context = self.sessions.get(session_id)
|
116 |
+
|
117 |
+
if not context:
|
118 |
+
return
|
119 |
+
|
120 |
+
log_info(f"🔌 Handling WebSocket disconnect | session_id={session_id}, state={context.state.value}")
|
121 |
+
|
122 |
+
# Eğer conversation aktifse, önce conversation'ı sonlandır
|
123 |
+
if context.state not in [ConversationState.IDLE, ConversationState.ENDED]:
|
124 |
+
await self._handle_conversation_ended(Event(
|
125 |
+
type=EventType.CONVERSATION_ENDED,
|
126 |
+
session_id=session_id,
|
127 |
+
data={"reason": "websocket_disconnected"}
|
128 |
+
))
|
129 |
+
|
130 |
async def _handle_conversation_started(self, event: Event) -> None:
|
131 |
"""Handle conversation start within existing session"""
|
132 |
session_id = event.session_id
|