gemercheung 3 years ago
parent
commit
d735223e79
2 changed files with 36 additions and 32 deletions
  1. 1 1
      packages/core/package.json
  2. 35 31
      packages/core/src/lib/basicSimaqRecorder.ts

+ 1 - 1
packages/core/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@simaq/core",
-  "version": "1.0.12",
+  "version": "1.0.13",
   "main": "dist/index",
   "types": "dist/index",
   "files": [

+ 35 - 31
packages/core/src/lib/basicSimaqRecorder.ts

@@ -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> {