ciyidogan commited on
Commit
5709c7e
·
verified ·
1 Parent(s): fa108c9

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

Browse files
flare-ui/src/app/components/chat/realtime-chat.component.ts CHANGED
@@ -586,30 +586,39 @@ export class RealtimeChatComponent implements OnInit, OnDestroy, AfterViewChecke
586
  const ctx = canvas.getContext('2d');
587
  if (!ctx) return;
588
 
 
 
589
  // Subscribe to volume changes
590
  this.subscriptions.add(
591
  this.audioService.volumeLevel$.subscribe(volume => {
592
- // Use actual volume data for visualization
593
- if (this.isRecording && volume > 0) {
594
- this.drawVolumeLevel(ctx, canvas, volume);
595
- }
596
  })
597
  );
598
 
599
- // Start animation loop
600
  const draw = () => {
601
  if (!this.isConversationActive) {
602
  this.clearVisualization();
603
  return;
604
  }
605
 
 
606
  ctx.fillStyle = '#333';
607
  ctx.fillRect(0, 0, canvas.width, canvas.height);
608
 
609
- if (!this.isRecording) {
610
- // Not recording, just show empty background
611
- this.animationId = requestAnimationFrame(draw);
612
- return;
 
 
 
 
 
 
 
 
 
613
  }
614
 
615
  this.animationId = requestAnimationFrame(draw);
 
586
  const ctx = canvas.getContext('2d');
587
  if (!ctx) return;
588
 
589
+ let lastVolume = 0;
590
+
591
  // Subscribe to volume changes
592
  this.subscriptions.add(
593
  this.audioService.volumeLevel$.subscribe(volume => {
594
+ lastVolume = volume;
 
 
 
595
  })
596
  );
597
 
598
+ // Animation loop
599
  const draw = () => {
600
  if (!this.isConversationActive) {
601
  this.clearVisualization();
602
  return;
603
  }
604
 
605
+ // Clear canvas
606
  ctx.fillStyle = '#333';
607
  ctx.fillRect(0, 0, canvas.width, canvas.height);
608
 
609
+ if (this.isRecording && lastVolume > 0) {
610
+ // Draw volume visualization
611
+ ctx.fillStyle = '#4caf50';
612
+ const barCount = 50;
613
+ const barWidth = canvas.width / barCount;
614
+
615
+ for (let i = 0; i < barCount; i++) {
616
+ const barHeight = (Math.random() * 0.5 + 0.5) * lastVolume * canvas.height;
617
+ const x = i * barWidth;
618
+ const y = canvas.height - barHeight;
619
+
620
+ ctx.fillRect(x, y, barWidth - 2, barHeight);
621
+ }
622
  }
623
 
624
  this.animationId = requestAnimationFrame(draw);