|
@@ -52,40 +52,44 @@ export class BasicSimaqRecorder extends EventEmitter {
|
|
|
private sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
|
|
public async startRecord(): Promise<void> {
|
|
|
- if (!this.isStartRecoding) {
|
|
|
- console.log('开始录屏!', isSupport());
|
|
|
- if (!isSupport()) {
|
|
|
- console.error('当前浏览器不支持录屏或不存在https环境');
|
|
|
- return;
|
|
|
- }
|
|
|
+ try {
|
|
|
+ if (!this.isStartRecoding) {
|
|
|
+ console.log('开始录屏!', isSupport());
|
|
|
+ if (!isSupport()) {
|
|
|
+ console.error('当前浏览器不支持录屏或不存在https环境');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- const media = this.isElectron
|
|
|
- ? await this.getEletronDisplayMedia()
|
|
|
- : await this.getDisplayMedia();
|
|
|
- console.log('media', media);
|
|
|
- if (media) {
|
|
|
- this.emit('startRecord');
|
|
|
- this.isStartRecoding = true;
|
|
|
- this.status = RecorderStatusType.start;
|
|
|
- // console.log('media', media);
|
|
|
- const video: HTMLVideoElement = getVideo();
|
|
|
- if (video) {
|
|
|
- // console.log('video', video);
|
|
|
- video.srcObject = media;
|
|
|
- this.stream = media;
|
|
|
- this.createMediaRecoder();
|
|
|
- this.mediaRecorder.start();
|
|
|
- this.stream.getVideoTracks()[0].onended = () => {
|
|
|
- console.log('stop-share');
|
|
|
- this.endRecord();
|
|
|
- };
|
|
|
+ const media = this.isElectron
|
|
|
+ ? await this.getEletronDisplayMedia()
|
|
|
+ : await this.getDisplayMedia();
|
|
|
+ console.log('media', media);
|
|
|
+ if (media) {
|
|
|
+ this.emit('startRecord');
|
|
|
+ this.isStartRecoding = true;
|
|
|
+ this.status = RecorderStatusType.start;
|
|
|
+ // console.log('media', media);
|
|
|
+ const video: HTMLVideoElement = getVideo();
|
|
|
+ if (video) {
|
|
|
+ // console.log('video', video);
|
|
|
+ video.srcObject = media;
|
|
|
+ this.stream = media;
|
|
|
+ this.createMediaRecoder();
|
|
|
+ this.mediaRecorder.start();
|
|
|
+ this.stream.getVideoTracks()[0].onended = () => {
|
|
|
+ console.log('stop-share');
|
|
|
+ this.endRecord();
|
|
|
+ };
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.streamStop();
|
|
|
+ this.isStartRecoding = false;
|
|
|
+ this.status = RecorderStatusType.end;
|
|
|
+ this.emit('cancelRecord');
|
|
|
}
|
|
|
- } else {
|
|
|
- this.streamStop();
|
|
|
- this.isStartRecoding = false;
|
|
|
- this.status = RecorderStatusType.end;
|
|
|
- this.emit('cancelRecord');
|
|
|
}
|
|
|
+ } catch (error) {
|
|
|
+ console.error('startRecord::', error);
|
|
|
}
|
|
|
}
|
|
|
private getEletronDisplayMedia(): Promise<MediaStream | null> {
|