mirror of
https://git.hmsn.ink/call/client.git
synced 2026-03-20 00:02:15 +09:00
first
This commit is contained in:
43
src/webrtc/audioRecorder.js
Normal file
43
src/webrtc/audioRecorder.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// audioRecorder.js
|
||||
|
||||
export class AudioRecorder {
|
||||
constructor() {
|
||||
this.mediaRecorder = null;
|
||||
this.audioChunks = [];
|
||||
this.onRecordingComplete = null; // 외부 콜백
|
||||
}
|
||||
|
||||
start(stream) {
|
||||
this.audioChunks = [];
|
||||
const options = { mimeType: 'audio/webm;codecs=opus' };
|
||||
this.mediaRecorder = new MediaRecorder(stream, options);
|
||||
|
||||
this.mediaRecorder.ondataavailable = (event) => {
|
||||
if (event.data.size > 0) {
|
||||
this.audioChunks.push(event.data);
|
||||
}
|
||||
};
|
||||
|
||||
this.mediaRecorder.onstop = () => {
|
||||
const audioBlob = new Blob(this.audioChunks, { type: 'audio/webm' });
|
||||
const audioUrl = URL.createObjectURL(audioBlob);
|
||||
if (this.onRecordingComplete) {
|
||||
this.onRecordingComplete(audioUrl, audioBlob);
|
||||
}
|
||||
};
|
||||
|
||||
this.mediaRecorder.start();
|
||||
console.log('⏺️ Recording started');
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
|
||||
this.mediaRecorder.stop();
|
||||
console.log('⏹️ Recording stopped');
|
||||
}
|
||||
}
|
||||
|
||||
isRecording() {
|
||||
return this.mediaRecorder?.state === 'recording';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user