@chat21/chat21-web-widget 5.0.89-rc.2 → 5.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -5
- package/package.json +1 -1
- package/src/app/app.module.ts +2 -5
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +3 -14
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.scss +10 -26
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +41 -123
- package/src/app/component/message/audio/audio.component.html +20 -0
- package/src/app/component/message/audio/audio.component.scss +122 -0
- package/src/app/component/message/{audio-track/audio-track.component.spec.ts → audio/audio.component.spec.ts} +6 -6
- package/src/app/component/message/audio/audio.component.ts +122 -0
- package/src/app/component/message/bubble-message/bubble-message.component.html +5 -30
- package/src/app/component/message/bubble-message/bubble-message.component.scss +0 -7
- package/src/app/component/message/bubble-message/bubble-message.component.ts +0 -1
- package/src/app/utils/globals.ts +1 -1
- package/src/assets/twp/index-dev.html +0 -1
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.html +0 -29
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.scss +0 -103
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.spec.ts +0 -23
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.ts +0 -96
- package/src/app/component/message/audio-track/audio-track.component.html +0 -32
- package/src/app/component/message/audio-track/audio-track.component.scss +0 -107
- package/src/app/component/message/audio-track/audio-track.component.ts +0 -147
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { Component, ElementRef, AfterViewInit, Input, ViewChild } from '@angular/core';
|
|
2
|
-
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
|
3
|
-
import { convertColorToRGBA } from 'src/chat21-core/utils/utils';
|
|
4
|
-
|
|
5
|
-
@Component({
|
|
6
|
-
selector: 'chat-audio-track',
|
|
7
|
-
templateUrl: './audio-track.component.html',
|
|
8
|
-
styleUrls: ['./audio-track.component.scss']
|
|
9
|
-
})
|
|
10
|
-
export class AudioTrackComponent implements AfterViewInit {
|
|
11
|
-
|
|
12
|
-
@ViewChild('audioElement', { static: true }) audioElement!: ElementRef<HTMLAudioElement>;
|
|
13
|
-
@ViewChild('canvasElement', { static: true }) waveformCanvas!: ElementRef<HTMLCanvasElement>;
|
|
14
|
-
|
|
15
|
-
@Input() audioBlob: Blob | null = null;
|
|
16
|
-
@Input() metadata: any | null = null;
|
|
17
|
-
@Input() color: string;
|
|
18
|
-
@Input() fontSize: string;
|
|
19
|
-
@Input() stylesMap: Map<string, string>;
|
|
20
|
-
|
|
21
|
-
audioUrl: SafeUrl | null = null;
|
|
22
|
-
rawAudioUrl: string | null = null;
|
|
23
|
-
audioContext!: AudioContext;
|
|
24
|
-
audioBuffer!: AudioBuffer;
|
|
25
|
-
audioDuration: number | null = null;
|
|
26
|
-
currentTime: number = 0;
|
|
27
|
-
isPlaying: boolean = false;
|
|
28
|
-
|
|
29
|
-
constructor(private sanitizer: DomSanitizer) {}
|
|
30
|
-
|
|
31
|
-
ngAfterViewInit() {
|
|
32
|
-
console.log('stylesssss', this.stylesMap)
|
|
33
|
-
if (this.audioBlob) {
|
|
34
|
-
this.rawAudioUrl = URL.createObjectURL(this.audioBlob);
|
|
35
|
-
this.audioUrl = this.sanitizer.bypassSecurityTrustUrl(this.rawAudioUrl);
|
|
36
|
-
this.setupAudioContext();
|
|
37
|
-
} else {
|
|
38
|
-
this.rawAudioUrl = this.metadata.src;
|
|
39
|
-
this.audioUrl = this.sanitizer.bypassSecurityTrustUrl(this.rawAudioUrl);
|
|
40
|
-
this.setupAudioContext();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async setupAudioContext() {
|
|
45
|
-
this.audioContext = new AudioContext();
|
|
46
|
-
if (this.rawAudioUrl) {
|
|
47
|
-
const response = await fetch(this.rawAudioUrl);
|
|
48
|
-
const audioData = await response.arrayBuffer();
|
|
49
|
-
this.audioBuffer = await this.audioContext.decodeAudioData(audioData);
|
|
50
|
-
this.getAudioDuration();
|
|
51
|
-
this.drawWaveform(this.audioBuffer);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
drawWaveform(audioBuffer: AudioBuffer) {
|
|
56
|
-
const canvas = this.waveformCanvas.nativeElement;
|
|
57
|
-
const canvasCtx = canvas.getContext('2d');
|
|
58
|
-
if (!canvasCtx) return;
|
|
59
|
-
const width = canvas.width;
|
|
60
|
-
const height = canvas.height;
|
|
61
|
-
const rawData = audioBuffer.getChannelData(0);
|
|
62
|
-
|
|
63
|
-
const samples = 60;
|
|
64
|
-
const blockSize = Math.floor(rawData.length / samples);
|
|
65
|
-
const waveform = new Float32Array(samples);
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < samples; i++) {
|
|
68
|
-
let sum = 0;
|
|
69
|
-
for (let j = 0; j < blockSize; j++) {
|
|
70
|
-
sum += Math.abs(rawData[i * blockSize + j]);
|
|
71
|
-
}
|
|
72
|
-
waveform[i] = sum / blockSize;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
canvasCtx.clearRect(0, 0, width, height);
|
|
76
|
-
const padding = 1;
|
|
77
|
-
const barWidth = (width / samples) - padding * 2;
|
|
78
|
-
const audio = this.audioElement.nativeElement;
|
|
79
|
-
const playedPercent = audio.currentTime / this.audioDuration;
|
|
80
|
-
// console.log('playedPercent: ', audio.currentTime, this.audioDuration);
|
|
81
|
-
|
|
82
|
-
for (let i = 0; i < samples; i++) {
|
|
83
|
-
var barHeight = waveform[i] * height * 4;
|
|
84
|
-
if (barHeight < 4) barHeight = 4;
|
|
85
|
-
const x = i * (barWidth + padding * 2) + padding;
|
|
86
|
-
|
|
87
|
-
if (i / samples < playedPercent) {
|
|
88
|
-
canvasCtx.fillStyle = this.color;
|
|
89
|
-
} else {
|
|
90
|
-
canvasCtx.fillStyle = convertColorToRGBA(this.color, 50);;
|
|
91
|
-
}
|
|
92
|
-
canvasCtx.fillRect(x, height / 2 - barHeight, barWidth, barHeight);
|
|
93
|
-
canvasCtx.fillRect(x, height / 2, barWidth, barHeight);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
playPauseAudio() {
|
|
98
|
-
const audio = this.audioElement.nativeElement;
|
|
99
|
-
if (audio.paused) {
|
|
100
|
-
this.isPlaying = true;
|
|
101
|
-
this.updateWaveform();
|
|
102
|
-
audio.play();
|
|
103
|
-
this.audioContext.resume();
|
|
104
|
-
} else {
|
|
105
|
-
audio.pause();
|
|
106
|
-
this.isPlaying = false;
|
|
107
|
-
}
|
|
108
|
-
audio.ontimeupdate = () => {
|
|
109
|
-
this.currentTime = audio.currentTime;
|
|
110
|
-
this.updateWaveform();
|
|
111
|
-
};
|
|
112
|
-
audio.onended = () => {
|
|
113
|
-
this.isPlaying = false;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
updateWaveform() {
|
|
119
|
-
this.drawWaveform(this.audioBuffer);
|
|
120
|
-
if (this.isPlaying) {
|
|
121
|
-
requestAnimationFrame(() => this.updateWaveform());
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
formatTime(seconds: number): string {
|
|
126
|
-
const minutes = Math.floor(seconds / 60);
|
|
127
|
-
const sec = Math.floor(seconds % 60);
|
|
128
|
-
return `${minutes}:${sec < 10 ? '0' + sec : sec}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getAudioDuration() {
|
|
132
|
-
const audio = new Audio();
|
|
133
|
-
audio.src = this.rawAudioUrl!;
|
|
134
|
-
audio.addEventListener('loadedmetadata', () => {
|
|
135
|
-
if (audio.duration === Infinity) {
|
|
136
|
-
audio.currentTime = Number.MAX_SAFE_INTEGER;
|
|
137
|
-
audio.ontimeupdate = () => {
|
|
138
|
-
audio.ontimeupdate = null;
|
|
139
|
-
audio.currentTime = 0;
|
|
140
|
-
this.audioDuration = audio.duration;
|
|
141
|
-
};
|
|
142
|
-
} else {
|
|
143
|
-
this.audioDuration = audio.duration;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|