Spaces:
Running
Running
Update flare-ui/src/app/components/chat/realtime-chat.component.ts
Browse files
flare-ui/src/app/components/chat/realtime-chat.component.ts
CHANGED
@@ -66,83 +66,82 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
|
|
66 |
this.projectName = data.projectName || null;
|
67 |
}
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
// Check if we have initial welcome message
|
83 |
-
if (messages.length > 0) {
|
84 |
-
const lastMessage = messages[messages.length - 1];
|
85 |
-
console.log('📝 Last message:', lastMessage.role, lastMessage.text?.substring(0, 50) + '...');
|
86 |
-
}
|
87 |
-
});
|
88 |
|
89 |
-
// Check
|
90 |
-
if (
|
91 |
-
|
92 |
-
|
93 |
-
duration: 5000,
|
94 |
-
panelClass: 'error-snackbar'
|
95 |
-
});
|
96 |
-
return;
|
97 |
}
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
this.
|
104 |
-
|
105 |
-
|
106 |
-
console.log('📊 Conversation state:', state);
|
107 |
-
this.currentState = state;
|
108 |
-
|
109 |
-
// Update recording state based on conversation state
|
110 |
-
if (state === 'listening') {
|
111 |
-
this.isRecording = true;
|
112 |
-
// Make sure visualization is running
|
113 |
-
if (!this.animationId && this.isConversationActive) {
|
114 |
-
this.startVisualization();
|
115 |
-
}
|
116 |
-
} else {
|
117 |
-
this.isRecording = false;
|
118 |
-
}
|
119 |
-
});
|
120 |
-
|
121 |
-
// Subscribe to transcription - HER ZAMAN GÖSTER
|
122 |
-
this.conversationManager.transcription$.pipe(
|
123 |
-
takeUntil(this.destroyed$)
|
124 |
-
).subscribe(text => {
|
125 |
-
console.log('🎙️ Transcription update:', text);
|
126 |
-
this.currentTranscription = text;
|
127 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
//
|
130 |
-
|
131 |
-
|
132 |
-
).subscribe(error => {
|
133 |
-
console.error('Conversation error:', error);
|
134 |
-
this.error = error.message;
|
135 |
-
});
|
136 |
|
137 |
-
//
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
this.messages = initialMessages;
|
142 |
-
this.shouldScrollToBottom = true;
|
143 |
}
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
ngAfterViewChecked(): void {
|
147 |
if (this.shouldScrollToBottom) {
|
148 |
this.scrollToBottom();
|
@@ -303,19 +302,6 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
|
|
303 |
}
|
304 |
}
|
305 |
|
306 |
-
private updateRecordingState(state: ConversationState): void {
|
307 |
-
// State'e göre recording durumunu güncelle
|
308 |
-
this.isRecording = state === 'listening';
|
309 |
-
|
310 |
-
// Visualizer'ı güncelle
|
311 |
-
if (this.isRecording && this.isConversationActive) {
|
312 |
-
// Eğer visualizer çalışmıyorsa başlat
|
313 |
-
if (!this.animationId) {
|
314 |
-
this.startVisualization();
|
315 |
-
}
|
316 |
-
}
|
317 |
-
}
|
318 |
-
|
319 |
private scrollToBottom(): void {
|
320 |
try {
|
321 |
if (this.scrollContainer?.nativeElement) {
|
|
|
66 |
this.projectName = data.projectName || null;
|
67 |
}
|
68 |
|
69 |
+
ngOnInit(): void {
|
70 |
+
console.log('🎤 RealtimeChat component initialized');
|
71 |
+
console.log('Session ID:', this.sessionId);
|
72 |
+
console.log('Project Name:', this.projectName);
|
73 |
+
|
74 |
+
// Subscribe to messages FIRST - before any connection
|
75 |
+
this.conversationManager.messages$.pipe(
|
76 |
+
takeUntil(this.destroyed$)
|
77 |
+
).subscribe(messages => {
|
78 |
+
console.log('💬 Messages updated:', messages.length, 'messages');
|
79 |
+
this.messages = messages;
|
80 |
+
this.shouldScrollToBottom = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
// Check if we have initial welcome message
|
83 |
+
if (messages.length > 0) {
|
84 |
+
const lastMessage = messages[messages.length - 1];
|
85 |
+
console.log('📝 Last message:', lastMessage.role, lastMessage.text?.substring(0, 50) + '...');
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
+
});
|
88 |
+
|
89 |
+
// Check browser support
|
90 |
+
if (!AudioStreamService.checkBrowserSupport()) {
|
91 |
+
this.error = 'Tarayıcınız ses kaydını desteklemiyor. Lütfen modern bir tarayıcı kullanın.';
|
92 |
+
this.snackBar.open(this.error, 'Close', {
|
93 |
+
duration: 5000,
|
94 |
+
panelClass: 'error-snackbar'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
});
|
96 |
+
return;
|
97 |
+
}
|
98 |
+
|
99 |
+
// Check microphone permission
|
100 |
+
this.checkMicrophonePermission();
|
101 |
+
|
102 |
+
// Subscribe to conversation state
|
103 |
+
this.conversationManager.currentState$.pipe(
|
104 |
+
takeUntil(this.destroyed$)
|
105 |
+
).subscribe(state => {
|
106 |
+
console.log('📊 Conversation state:', state);
|
107 |
+
this.currentState = state;
|
108 |
|
109 |
+
// Update recording state based on conversation state
|
110 |
+
// SADECE listening state'inde recording true olmalı
|
111 |
+
this.isRecording = (state === 'listening');
|
|
|
|
|
|
|
|
|
112 |
|
113 |
+
// Eğer listening state'e geçtiyse ve konuşma aktifse visualization'ı başlat
|
114 |
+
if (state === 'listening' && this.isConversationActive && !this.animationId) {
|
115 |
+
console.log('🎤 Starting visualization for listening state');
|
116 |
+
this.startVisualization();
|
|
|
|
|
117 |
}
|
118 |
+
});
|
119 |
+
|
120 |
+
// Subscribe to transcription
|
121 |
+
this.conversationManager.transcription$.pipe(
|
122 |
+
takeUntil(this.destroyed$)
|
123 |
+
).subscribe(text => {
|
124 |
+
console.log('🎙️ Transcription update:', text);
|
125 |
+
this.currentTranscription = text;
|
126 |
+
});
|
127 |
+
|
128 |
+
// Subscribe to errors
|
129 |
+
this.conversationManager.error$.pipe(
|
130 |
+
takeUntil(this.destroyed$)
|
131 |
+
).subscribe(error => {
|
132 |
+
console.error('Conversation error:', error);
|
133 |
+
this.error = error.message;
|
134 |
+
});
|
135 |
|
136 |
+
// Load initial messages from session if available
|
137 |
+
const initialMessages = this.conversationManager.getMessages();
|
138 |
+
console.log('📋 Initial messages:', initialMessages.length);
|
139 |
+
if (initialMessages.length > 0) {
|
140 |
+
this.messages = initialMessages;
|
141 |
+
this.shouldScrollToBottom = true;
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
ngAfterViewChecked(): void {
|
146 |
if (this.shouldScrollToBottom) {
|
147 |
this.scrollToBottom();
|
|
|
302 |
}
|
303 |
}
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
private scrollToBottom(): void {
|
306 |
try {
|
307 |
if (this.scrollContainer?.nativeElement) {
|