|
@@ -18,6 +18,7 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
};
|
|
|
private isStartRecoding = false;
|
|
|
private stream: MediaStream;
|
|
|
+ private audioInput: MediaStream;
|
|
|
private mediaRecorder: MediaRecorder;
|
|
|
// public record = new BehaviorSubject<Blob>(null);
|
|
|
private recordChunks: Blob[] = [];
|
|
@@ -40,9 +41,9 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
return;
|
|
|
}
|
|
|
this.isStartRecoding = true;
|
|
|
- this.emit('startRecord');
|
|
|
const media = await this.getDisplayMedia();
|
|
|
if (media) {
|
|
|
+ this.emit('startRecord');
|
|
|
// console.log('media', media);
|
|
|
const video: HTMLVideoElement = getVideo();
|
|
|
if (video) {
|
|
@@ -63,6 +64,11 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
private getDisplayMedia(): Promise<MediaStream | null> {
|
|
|
return new Promise(async (resolve) => {
|
|
|
try {
|
|
|
+ const audioInput = await this.getDeaultAudio();
|
|
|
+ if (audioInput) {
|
|
|
+ this.audioInput = audioInput;
|
|
|
+ }
|
|
|
+ console.log('audioInput', audioInput);
|
|
|
if (navigator.mediaDevices.getDisplayMedia) {
|
|
|
const res = await navigator.mediaDevices.getDisplayMedia(
|
|
|
this.displayMediaStreamConstraints,
|
|
@@ -76,12 +82,28 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private async getDeaultAudio(): Promise<MediaStream> {
|
|
|
+ return new Promise(async (resolve) => {
|
|
|
+ try {
|
|
|
+ if (navigator.mediaDevices.getUserMedia) {
|
|
|
+ const res = await navigator.mediaDevices.getUserMedia({
|
|
|
+ audio: true,
|
|
|
+ video: false,
|
|
|
+ });
|
|
|
+ return resolve(res);
|
|
|
+ }
|
|
|
+ return resolve(null);
|
|
|
+ } catch (error) {
|
|
|
+ return resolve(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public endRecord(): void {
|
|
|
this.isStartRecoding = false;
|
|
|
this.streamStop();
|
|
|
this.emit('endRecord');
|
|
|
}
|
|
|
-
|
|
|
private streamStop(): void {
|
|
|
if (this.stream) {
|
|
|
this.stream.getTracks().forEach((track) => track.stop());
|
|
@@ -89,11 +111,17 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
if (this.mediaRecorder) {
|
|
|
this.mediaRecorder.stop();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private createMediaRecoder(): void {
|
|
|
console.log('video-flag', videoConstraints.value);
|
|
|
+ // let mergeSteam: MediaStream;
|
|
|
+ let audioTrack: MediaStreamTrack, videoTrack: MediaStreamTrack;
|
|
|
+ if (this.audioInput) {
|
|
|
+ [videoTrack] = this.stream.getVideoTracks();
|
|
|
+ [audioTrack] = this.audioInput.getAudioTracks();
|
|
|
+ this.stream = new MediaStream([videoTrack, audioTrack]);
|
|
|
+ }
|
|
|
const mediaRecorder = new MediaRecorder(this.stream, {
|
|
|
mimeType: 'video/webm;codecs=H264,opus',
|
|
|
audioBitsPerSecond: videoConstraints.value.audioBitsPerSecond,
|
|
@@ -103,11 +131,6 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
this.mediaRecorder.ondataavailable = (event) => {
|
|
|
// console.log('ondataavailable', event.data);
|
|
|
this.recordChunks.push(event.data);
|
|
|
- // this.record.next(
|
|
|
- // new Blob([event.data], {
|
|
|
- // type: 'video/mp4; codecs=h264',
|
|
|
- // }),
|
|
|
- // );
|
|
|
this.emit(
|
|
|
'record',
|
|
|
new Blob([event.data], {
|