Spaces:
Paused
Paused
Update flare-ui/src/app/components/chat/realtime-chat.component.ts
Browse files
flare-ui/src/app/components/chat/realtime-chat.component.ts
CHANGED
@@ -106,15 +106,9 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
|
|
106 |
console.log('📊 Conversation state:', state);
|
107 |
this.currentState = state;
|
108 |
|
109 |
-
//
|
110 |
-
|
111 |
-
|
112 |
-
// Start/stop visualization based on state
|
113 |
-
if (state === 'listening' && this.isConversationActive) {
|
114 |
-
this.startVisualization();
|
115 |
-
} else {
|
116 |
-
this.stopVisualization();
|
117 |
-
}
|
118 |
});
|
119 |
|
120 |
// Subscribe to errors
|
@@ -163,46 +157,6 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
|
|
163 |
}
|
164 |
}
|
165 |
|
166 |
-
async startConversation(): Promise<void> {
|
167 |
-
try {
|
168 |
-
this.loading = true;
|
169 |
-
this.error = '';
|
170 |
-
|
171 |
-
// Clear existing messages - welcome will come via WebSocket
|
172 |
-
this.conversationManager.clearMessages();
|
173 |
-
|
174 |
-
await this.conversationManager.startConversation(this.sessionId!);
|
175 |
-
this.isConversationActive = true;
|
176 |
-
|
177 |
-
// Visualization'ı başlat ve aktif olarak işaretle
|
178 |
-
this.startVisualization();
|
179 |
-
console.log('✅ Conversation and visualization started');
|
180 |
-
|
181 |
-
this.snackBar.open('Konuşma başlatıldı', 'Close', {
|
182 |
-
duration: 2000
|
183 |
-
});
|
184 |
-
} catch (error: any) {
|
185 |
-
console.error('Failed to start conversation:', error);
|
186 |
-
this.error = 'Konuşma başlatılamadı. Lütfen tekrar deneyin.';
|
187 |
-
this.snackBar.open(this.error, 'Close', {
|
188 |
-
duration: 5000,
|
189 |
-
panelClass: 'error-snackbar'
|
190 |
-
});
|
191 |
-
} finally {
|
192 |
-
this.loading = false;
|
193 |
-
}
|
194 |
-
}
|
195 |
-
|
196 |
-
private stopConversation(): void {
|
197 |
-
this.conversationManager.stopConversation();
|
198 |
-
this.isConversationActive = false;
|
199 |
-
this.stopVisualization();
|
200 |
-
|
201 |
-
this.snackBar.open('Konuşma sonlandırıldı', 'Close', {
|
202 |
-
duration: 2000
|
203 |
-
});
|
204 |
-
}
|
205 |
-
|
206 |
async retryConnection(): Promise<void> {
|
207 |
this.error = '';
|
208 |
if (!this.isConversationActive && this.sessionId) {
|
@@ -305,7 +259,49 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
|
|
305 |
}
|
306 |
}
|
307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
private startVisualization(): void {
|
|
|
309 |
if (!this.audioVisualizer || this.animationId) {
|
310 |
return;
|
311 |
}
|
@@ -338,7 +334,8 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
|
|
338 |
|
339 |
// Animation loop
|
340 |
const animate = () => {
|
341 |
-
|
|
|
342 |
this.clearVisualization();
|
343 |
return;
|
344 |
}
|
|
|
106 |
console.log('📊 Conversation state:', state);
|
107 |
this.currentState = state;
|
108 |
|
109 |
+
// Recording state'i conversation active olduğu sürece true tut
|
110 |
+
// Sadece error state'inde false yap
|
111 |
+
this.isRecording = this.isConversationActive && state !== 'error';
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
});
|
113 |
|
114 |
// Subscribe to errors
|
|
|
157 |
}
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
async retryConnection(): Promise<void> {
|
161 |
this.error = '';
|
162 |
if (!this.isConversationActive && this.sessionId) {
|
|
|
259 |
}
|
260 |
}
|
261 |
|
262 |
+
async startConversation(): Promise<void> {
|
263 |
+
try {
|
264 |
+
this.loading = true;
|
265 |
+
this.error = '';
|
266 |
+
|
267 |
+
// Clear existing messages - welcome will come via WebSocket
|
268 |
+
this.conversationManager.clearMessages();
|
269 |
+
|
270 |
+
await this.conversationManager.startConversation(this.sessionId!);
|
271 |
+
this.isConversationActive = true;
|
272 |
+
this.isRecording = true; // Konuşma başladığında recording'i aktif et
|
273 |
+
|
274 |
+
// Visualization'ı başlat
|
275 |
+
this.startVisualization();
|
276 |
+
|
277 |
+
this.snackBar.open('Konuşma başlatıldı', 'Close', {
|
278 |
+
duration: 2000
|
279 |
+
});
|
280 |
+
} catch (error: any) {
|
281 |
+
console.error('Failed to start conversation:', error);
|
282 |
+
this.error = 'Konuşma başlatılamadı. Lütfen tekrar deneyin.';
|
283 |
+
this.snackBar.open(this.error, 'Close', {
|
284 |
+
duration: 5000,
|
285 |
+
panelClass: 'error-snackbar'
|
286 |
+
});
|
287 |
+
} finally {
|
288 |
+
this.loading = false;
|
289 |
+
}
|
290 |
+
}
|
291 |
+
|
292 |
+
private stopConversation(): void {
|
293 |
+
this.conversationManager.stopConversation();
|
294 |
+
this.isConversationActive = false;
|
295 |
+
this.isRecording = false; // Konuşma bittiğinde recording'i kapat
|
296 |
+
this.stopVisualization();
|
297 |
+
|
298 |
+
this.snackBar.open('Konuşma sonlandırıldı', 'Close', {
|
299 |
+
duration: 2000
|
300 |
+
});
|
301 |
+
}
|
302 |
+
|
303 |
private startVisualization(): void {
|
304 |
+
// Eğer zaten çalışıyorsa tekrar başlatma
|
305 |
if (!this.audioVisualizer || this.animationId) {
|
306 |
return;
|
307 |
}
|
|
|
334 |
|
335 |
// Animation loop
|
336 |
const animate = () => {
|
337 |
+
// isConversationActive kontrolü ile devam et
|
338 |
+
if (!this.isConversationActive) {
|
339 |
this.clearVisualization();
|
340 |
return;
|
341 |
}
|