ciyidogan commited on
Commit
42708da
·
verified ·
1 Parent(s): 2dfdba6

Update flare-ui/src/app/components/chat/realtime-chat.component.ts

Browse files
flare-ui/src/app/components/chat/realtime-chat.component.ts CHANGED
@@ -584,8 +584,18 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
584
  const ctx = canvas.getContext('2d');
585
  if (!ctx) return;
586
 
587
- // Get volume level and visualize
588
- const draw = async () => {
 
 
 
 
 
 
 
 
 
 
589
  if (!this.isConversationActive) {
590
  this.clearVisualization();
591
  return;
@@ -594,37 +604,10 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
594
  ctx.fillStyle = '#333';
595
  ctx.fillRect(0, 0, canvas.width, canvas.height);
596
 
597
- if (this.isRecording) {
598
- // Get actual volume level
599
- try {
600
- const volume = await this.audioService.getVolumeLevel();
601
-
602
- // Draw volume bars
603
- ctx.fillStyle = '#4caf50';
604
- const barCount = 50;
605
- const barWidth = canvas.width / barCount;
606
-
607
- for (let i = 0; i < barCount; i++) {
608
- const barHeight = Math.random() * volume * canvas.height;
609
- const x = i * barWidth;
610
- const y = canvas.height - barHeight;
611
-
612
- ctx.fillRect(x, y, barWidth - 2, barHeight);
613
- }
614
- } catch (error) {
615
- // Fallback to random visualization
616
- ctx.fillStyle = '#4caf50';
617
- const barCount = 50;
618
- const barWidth = canvas.width / barCount;
619
-
620
- for (let i = 0; i < barCount; i++) {
621
- const barHeight = Math.random() * canvas.height * 0.8;
622
- const x = i * barWidth;
623
- const y = canvas.height - barHeight;
624
-
625
- ctx.fillRect(x, y, barWidth - 2, barHeight);
626
- }
627
- }
628
  }
629
 
630
  this.animationId = requestAnimationFrame(draw);
@@ -632,6 +615,23 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
632
 
633
  draw();
634
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
 
636
  private stopVisualization(): void {
637
  if (this.animationId) {
 
584
  const ctx = canvas.getContext('2d');
585
  if (!ctx) return;
586
 
587
+ // Subscribe to volume changes
588
+ this.subscriptions.add(
589
+ this.audioService.volumeLevel$.subscribe(volume => {
590
+ // Use actual volume data for visualization
591
+ if (this.isRecording && volume > 0) {
592
+ this.drawVolumeLevel(ctx, canvas, volume);
593
+ }
594
+ })
595
+ );
596
+
597
+ // Start animation loop
598
+ const draw = () => {
599
  if (!this.isConversationActive) {
600
  this.clearVisualization();
601
  return;
 
604
  ctx.fillStyle = '#333';
605
  ctx.fillRect(0, 0, canvas.width, canvas.height);
606
 
607
+ if (!this.isRecording) {
608
+ // Not recording, just show empty background
609
+ this.animationId = requestAnimationFrame(draw);
610
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
  }
612
 
613
  this.animationId = requestAnimationFrame(draw);
 
615
 
616
  draw();
617
  }
618
+
619
+ private drawVolumeLevel(ctx: CanvasRenderingContext2D, canvas: HTMLCanvasElement, volume: number): void {
620
+ ctx.fillStyle = '#333';
621
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
622
+
623
+ ctx.fillStyle = '#4caf50';
624
+ const barCount = 50;
625
+ const barWidth = canvas.width / barCount;
626
+
627
+ for (let i = 0; i < barCount; i++) {
628
+ const barHeight = (Math.random() * 0.5 + 0.5) * volume * canvas.height;
629
+ const x = i * barWidth;
630
+ const y = canvas.height - barHeight;
631
+
632
+ ctx.fillRect(x, y, barWidth - 2, barHeight);
633
+ }
634
+ }
635
 
636
  private stopVisualization(): void {
637
  if (this.animationId) {