|
@@ -2,8 +2,8 @@ import { audioConstraints } from './audioConstraints';
|
|
|
import { videoConstraints } from './videoConstraints';
|
|
|
import { isSupport } from './isSupport';
|
|
|
import { getVideo } from './videoElement';
|
|
|
-import { BehaviorSubject } from 'rxjs';
|
|
|
-
|
|
|
+// import { BehaviorSubject } from 'rxjs';
|
|
|
+import { EventEmitter } from 'eventemitter3';
|
|
|
export type ResolutionType = '1080p' | '2k' | '4k';
|
|
|
export interface InitConfigType extends DisplayMediaStreamConstraints {
|
|
|
uploadUrl: '';
|
|
@@ -11,7 +11,7 @@ export interface InitConfigType extends DisplayMediaStreamConstraints {
|
|
|
autoDownload?: boolean;
|
|
|
debug?: boolean;
|
|
|
}
|
|
|
-export class BasicSimaqRecorder {
|
|
|
+export class BasicSimaqRecorder extends EventEmitter {
|
|
|
displayMediaStreamConstraints: DisplayMediaStreamConstraints = {
|
|
|
video: videoConstraints.getValue(),
|
|
|
audio: audioConstraints.getValue(),
|
|
@@ -19,11 +19,12 @@ export class BasicSimaqRecorder {
|
|
|
private isStartRecoding = false;
|
|
|
private stream: MediaStream;
|
|
|
private mediaRecorder: MediaRecorder;
|
|
|
- public record = new BehaviorSubject<Blob>(null);
|
|
|
+ // public record = new BehaviorSubject<Blob>(null);
|
|
|
private recordChunks: Blob[] = [];
|
|
|
private autoDownload = false;
|
|
|
|
|
|
constructor(arg: InitConfigType) {
|
|
|
+ super();
|
|
|
console.log('arg', arg);
|
|
|
this.autoDownload = arg.autoDownload;
|
|
|
videoConstraints.subscribe((value) => {
|
|
@@ -39,6 +40,7 @@ export class BasicSimaqRecorder {
|
|
|
return;
|
|
|
}
|
|
|
this.isStartRecoding = true;
|
|
|
+ this.emit('startRecord');
|
|
|
const media = await this.getDisplayMedia();
|
|
|
if (media) {
|
|
|
// console.log('media', media);
|
|
@@ -78,6 +80,7 @@ export class BasicSimaqRecorder {
|
|
|
public endRecord(): void {
|
|
|
this.isStartRecoding = false;
|
|
|
this.streamStop();
|
|
|
+ this.emit('endRecord');
|
|
|
}
|
|
|
|
|
|
private streamStop(): void {
|
|
@@ -87,6 +90,7 @@ export class BasicSimaqRecorder {
|
|
|
if (this.mediaRecorder) {
|
|
|
this.mediaRecorder.stop();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private createMediaRecoder(): void {
|
|
@@ -100,7 +104,13 @@ export class BasicSimaqRecorder {
|
|
|
this.mediaRecorder.ondataavailable = (event) => {
|
|
|
// console.log('ondataavailable', event.data);
|
|
|
this.recordChunks.push(event.data);
|
|
|
- this.record.next(
|
|
|
+ // this.record.next(
|
|
|
+ // new Blob([event.data], {
|
|
|
+ // type: 'video/mp4; codecs=h264',
|
|
|
+ // }),
|
|
|
+ // );
|
|
|
+ this.emit(
|
|
|
+ 'record',
|
|
|
new Blob([event.data], {
|
|
|
type: 'video/mp4; codecs=h264',
|
|
|
}),
|
|
@@ -110,7 +120,7 @@ export class BasicSimaqRecorder {
|
|
|
setTimeout(() => {
|
|
|
this.handleAutoDownload();
|
|
|
this.recordChunks = [];
|
|
|
- this.record.next(null);
|
|
|
+ // this.record.next(null);
|
|
|
}, 1000);
|
|
|
};
|
|
|
}
|