xushiting 3 anos atrás
pai
commit
b5b1018ebd
4 arquivos alterados com 171 adições e 218 exclusões
  1. 0 2
      src/Rtcp.js
  2. 1 0
      src/Signal.js
  3. 92 53
      src/Workers.js
  4. 78 163
      src/接口数据.txt

+ 0 - 2
src/Rtcp.js

@@ -180,8 +180,6 @@ export default class Rtcp extends EventEmitter {
                 return logger.info("The input channel has closed, id:", (r = this.inputChannel) == null ? void 0 : r.id)
             },
             this.inputChannel.onmessage = r=>{
-                // console.log('this.workers',this.workers)
-                //console.log('inputChannel',r.data)
                 this.workers.dataHandle(r.data)
             }
         }

+ 1 - 0
src/Signal.js

@@ -46,6 +46,7 @@ export default class Signal {
                 signal: s,
                 alreadyUpdateYUV: c
             } = e;
+            
         this.handleActionResponses(s), this._room.handleSignalHook(s);
         const d = Date.now();
         if (this.handleSignalPartialArray2.add(d - o), !c) {

+ 92 - 53
src/Workers.js

@@ -423,8 +423,8 @@ export default class Workers {
         var b;
         const i = Date.now()
           , o = i - e.data.postTs;
-        if (this.postMessageWaitArray.add(o),
-        !this.firstYUVReceived) {
+        this.postMessageWaitArray.add(o);
+        if (!this.firstYUVReceived) {
             this.firstYUVDecoded = e.data.yuv_ts;
             const k = this.firstYUVDecoded - this.rtcp.network.room._startTime;
             defaultLogger.infoAndReportMeasurement({
@@ -442,54 +442,66 @@ export default class Workers {
             this.firstYUVReceived = !0,
             this.lastRenderTs = Date.now()
         }
-        !this.cachedRender[this.setPtr] && this.cachedMetas[this.setPtr] != null && (this.cachedStreams[this.setPtr] != null && this.cachedStreams[this.setPtr].byteLength != 0 && (e.data.data == null ? (this.executeFunction("stream", {
-            stream: this.cachedStreams[this.setPtr],
-            width: this.cachedResolution[this.setPtr].width,
-            height: this.cachedResolution[this.setPtr].height,
-            pts: this.cachedPtss[this.setPtr]
-        }),
-        this.executeFunction("signal", {
-            signal: this.cachedMetas[this.setPtr],
-            pts: this.cachedPtss[this.setPtr],
-            alreadyUpdateYUV: !0
-        })) : this.updateDropFrame += 1,
-        this.decoderWorker.postMessage({
-            t: 2,
-            frameCnt: this.cachedPtss[this.setPtr],
-            buffer: this.cachedStreams[this.setPtr]
-        }, [this.cachedStreams[this.setPtr].buffer])),
-        this.getPtr = (this.getPtr + 1) % this.cachedLength);
+        if(!this.cachedRender[this.setPtr] && this.cachedMetas[this.setPtr] != null){
+            if(this.cachedStreams[this.setPtr] != null && this.cachedStreams[this.setPtr].byteLength != 0){
+                if(e.data.data == null)
+                {
+                    this.executeFunction("stream", {
+                        stream: this.cachedStreams[this.setPtr],
+                        width: this.cachedResolution[this.setPtr].width,
+                        height: this.cachedResolution[this.setPtr].height,
+                        pts: this.cachedPtss[this.setPtr]
+                    });
+
+                    this.executeFunction("signal", {
+                        signal: this.cachedMetas[this.setPtr],
+                        pts: this.cachedPtss[this.setPtr],
+                        alreadyUpdateYUV: !0
+                    })
+                }
+                else{
+                    this.updateDropFrame += 1
+                }
+    
+                this.decoderWorker.postMessage({
+                    t: 2,
+                    frameCnt: this.cachedPtss[this.setPtr],
+                    buffer: this.cachedStreams[this.setPtr]
+                }, [this.cachedStreams[this.setPtr].buffer])
+            }
+
+            this.getPtr = (this.getPtr + 1) % this.cachedLength
+        }
         const s = e.data.metadata;
         if ((b = s == null ? void 0 : s.traceIds) != null && b.length)
             for (const k of s.traceIds) {
                 if (this.traceIdMap.has(k)) {
                     const j = this.traceIdMap.get(k);
-                    j != null && (j.readyTime = Date.now(),
-                    j.status = 2)
+                    j != null && (j.readyTime = Date.now(),j.status = 2)
                 }
                 if (this.joyStickTraceIdMap.has(k)) {
                     const j = this.joyStickTraceIdMap.get(k);
-                    j != null && (j.readyTime = Date.now(),
-                    j.status = 2)
+                    j != null && (j.readyTime = Date.now(),j.status = 2)
                 }
             }
-        if (e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs),
-        this.userId_test = this.rtcp.network.room.userId,
-        this.inMovingMode) {
+
+        e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs);
+        this.userId_test = this.rtcp.network.room.userId;
+        if (this.inMovingMode) {
             const k = Date.now()
               , j = k - this.lastMoveProcessTime;
             this.moveProcessCircular.add(j),
             this.lastMoveProcessTime = k
         }
         const c = this.setPtr;
-        this.cachedStreams[c] = e.data.data,
-        this.cachedMetas[c] = e.data.metadata,
-        this.cachedPtss[c] = e.data.pts,
-        this.cachedRender[c] = !1,
+        this.cachedStreams[c] = e.data.data;
+        this.cachedMetas[c] = e.data.metadata;
+        this.cachedPtss[c] = e.data.pts;
+        this.cachedRender[c] = !1;
         this.cachedResolution[c] = {
             width: e.data.width,
             height: e.data.height
-        },
+        };
         this.setPtr = (this.setPtr + 1) % this.cachedLength;
         const _ = Date.now() - i;
         this.receiveYUVExecutionArray.add(_)
@@ -582,7 +594,7 @@ export default class Workers {
         const i = new Blob([decoder],{
             type: "application/javascript"
         });
-        return this.decoderWorker = new Worker(URL.createObjectURL(i)),
+        this.decoderWorker = new Worker(URL.createObjectURL(i)),
         this.decoderWorker.postMessage({
             t: 9,
             url: WASM_URLS[WASM_Version],
@@ -591,8 +603,9 @@ export default class Workers {
         this.decoderWorker.postMessage({
             t: 1,
             config: e
-        }),
-        new Promise(o=>{
+        });
+
+        return new Promise(o=>{
             this.decoderWorker.onmessage = s=>{
                 switch (s.data.t) {
                 case 0:
@@ -615,6 +628,7 @@ export default class Workers {
                         break
                     }
                 case 5:
+                    console.log('接受webrtc请求(来自worker):'+JSON.stringify(s.data.metadata))
                     this.executeFunction("signal", {
                         signal: s.data.metadata,
                         pts: -1,
@@ -743,13 +757,15 @@ export default class Workers {
                         }
                     }
                 }
-            if (this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs),
-            this.inMovingMode) {
+
+            this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs);
+            if (this.inMovingMode) {
                 const $ = Date.now()
                     , _e = $ - this.lastMoveDisplayTime;
                 this.moveDisplayCircular.add(_e),
                 this.lastMoveDisplayTime = $
             }
+            console.log('接受webrtc请求(定时执行UpdateYUV):'+JSON.stringify(this.cachedMetas[e]))
             this.executeFunction("signal", {
                 signal: this.cachedMetas[e],
                 pts: this.cachedPtss[e],
@@ -934,12 +950,15 @@ export default class Workers {
                 position: st
             };
             if (this.inPanoMode)
-                return this.executeFunction("signal", {
+            {
+                console.log('接受webrtc请求:'+JSON.stringify(Mt));
+                this.executeFunction("signal", {
                     signal: Mt,
                     pts: -1,
                     alreadyUpdateYUV: !0
-                }),
-                !0;
+                });
+                return !0;
+            }
             if (this.decoderWorker.postMessage(Dt, [At.buffer]),
             !this.firstMediaReceived) {
                 this.firstMediaArraval = Date.now();
@@ -1004,12 +1023,15 @@ export default class Workers {
                         position: st
                     };
                     if (this.inPanoMode)
-                        return this.executeFunction("signal", {
-                            signal: Rt,
-                            pts: -1,
-                            alreadyUpdateYUV: !0
-                        }),
-                        !0;
+                    {
+                        console.log('接受webrtc请求:'+JSON.stringify(Rt));
+                        this.executeFunction("signal", {
+                           signal: Rt,
+                           pts: -1,
+                           alreadyUpdateYUV: !0
+                       });
+                       return !0;
+                    }
                     if (this.decoderWorker.postMessage(It, [gt.buffer]),
                     !this.firstMediaReceived) {
                         this.firstMediaArraval = Date.now();
@@ -1057,26 +1079,43 @@ export default class Workers {
         defaultLogger.debug("hhh")
     }
     dataHandle(e) {
-        this.saveframe && (this.decoderWorker.postMessage({
-            t: 6
-        }),
-        this.saveframe = !1),
-        this.SaveMediaStream && (this.decoderWorker.postMessage({
-            t: 7
-        }),
-        this.SaveMediaStream = !1);
+
+        if(this.saveframe){
+            console.log('接受webrtc请求:录制视频')
+            this.decoderWorker.postMessage({
+                t: 6
+            });
+            this.saveframe = !1
+        }
+
+        if(this.SaveMediaStream){
+            console.log('接受webrtc请求:下载视频')
+            this.decoderWorker.postMessage({
+                t: 7
+            }),
+            this.SaveMediaStream = !1
+        }
+
         const i = new Uint8Array(e);
         if (i.length >= 4 && this.isHeartBeatPacket(i.buffer, i.length) == !0)
+        {
+            console.log('接受webrtc请求:心跳')
             return;
+        }
         if (i.length > 36 && this.unmarshalStream(i.buffer) == !0) {
             this.reconnectSignal && (this.executeFunction("reconnectedFrame", {}),
             this.reconnectSignal = !1);
+            console.log('接受webrtc请求:视频流')
             return
         }
         if (i.length > 20 && this.unmarshalPano(i.buffer) == !0)
+        {
+            console.log('接受webrtc请求:全景图')
             return;
+        }
         this.noWasmBytesReceived += e.byteLength;
         const o = JSON.parse(this.Stringify(i));
+        console.log('接受webrtc请求:'+JSON.stringify(o));
         this.executeFunction("signal", {
             signal: o,
             pts: -1,

+ 78 - 163
src/接口数据.txt

@@ -253,176 +253,92 @@
 /*****************************************************接收webrtc**********************************************************/
 备注:都是二进制数据,在函数dataHandle的参数上
 
-1. 心跳数据
+1. 心跳数据(isHeartBeatPacket)
 2. 视频流
 3. 全景图片
-4.定时
-{
-	"actionType":1009,
-	"pointType":100,
-	"extra":"",
-	"traceId":"68a36026-74b3-4435-a6df-8aba5661cbaa",
-	"packetId":"",
-	"nps":[],
-	"peopleNum":0,
-	"zoneId":"",
-	"echoMsg":"1650888984547",
-	"reserveDetail":null,
-	"userWithAvatarList":[],
-	"newUserStates":[],
-	"code":0,
-	"msg":""
-}
-5.定时
+
+4.定时(来自worker):this.decoderWorker.onmessage
+5.定时:this.inputChannel.onmessage。actionType: 1009
+6.定时:this.inputChannel.onmessage。actionType: 1024
+7. 旋转:
 {
-	"actionType":1024,
-	"pointType":100,
-	"extra":"",
-	"traceId":"f302b7fe-6231-4ba1-b865-8daf3ebd9494",
-	"packetId":"",
-	"nps":[],
-	"peopleNum":0,
-	"zoneId":"",
-	"echoMsg":"",
-	"reserveDetail":null,
-	"userWithAvatarList":[],
-	"newUserStates":
-	[
-		{
-			"userId":"72b61ff6370ca",
-			"playerState":{
-				"roomTypeId":"",
-				"person":0,
-				"avatarId":"KGe_Boy",
-				"skinId":"10089",
-				"roomId":"e629ef3e-022d-4e64-8654-703bb96410eb",
-				"isHost":false,
-				"isFollowHost":false,
-				"skinDataVersion":"1008900008",
-				"avatarComponents":"",
-				"nickName":"72b61ff6370ca",
-				"movingMode":0,
-				"attitude":"walk",
-				"areaName":"",
-				"pathName":"",
-				"pathId":"",
-				"avatarSize":1,
-				"extra":"{"removeWhenDisconnected":true}",
-				"prioritySync":false,
-				"player":{
-					"position":{"x":-755,"y":-1450,"z":-34},
-					"angle":{"pitch":0,"yaw":0,"roll":0}
+	"traceIds": [],
+	"vehicle": null,
+	"newUserStates": [{
+		"userId": "0ba70fda86406",
+		"playerState": {
+			"roomTypeId": "",
+			"person": 0,
+			"avatarId": "",
+			"skinId": "",
+			"roomId": "",
+			"isHost": false,
+			"isFollowHost": false,
+			"skinDataVersion": "",
+			"avatarComponents": "",
+			"nickName": "",
+			"movingMode": 0,
+			"attitude": "",
+			"areaName": "",
+			"pathName": "",
+			"pathId": "",
+			"avatarSize": 1,
+			"extra": "",
+			"prioritySync": false,
+			"player": {
+				"position": {
+					"x": -755,
+					"y": -1450,
+					"z": -34
 				},
-				"camera":null,
-				"cameraCenter":null
-			},
-			"renderInfo":
-			{
-				"renderType":0,
-				"videoFrame":null,
-				"cameraStateType":0,
-				"isMoving":0,
-				"needIfr":0,
-				"isVideo":0,
-				"stillFrame":0,
-				"isRotating":0,
-				"isFollowing":0,
-				"clientPanoTitlesBitmap":[],
-				"clientPanoTreceId":"",
-				"prefetchVideoId":"",
-				"noMedia":false
-			},
-			"event":
-			{
-			"id":"",
-			"type":0,
-			"points":[],
-			"rotateEvent":null,
-			"removeVisitorEvent":null
+				"angle": {
+					"pitch": 0,
+					"yaw": 0,
+					"roll": 0
+				}
 			},
-			"relation":0
-		},
-		{
-			"userId":"4c4e24740f427",
-			"playerState":
-			{
-				"roomTypeId":"",
-				"person":0,
-				"avatarId":"KGe_Boy",
-				"skinId":"10089",
-				"roomId":"e629ef3e-022d-4e64-8654-703bb96410eb",
-				"isHost":false,
-				"isFollowHost":false,
-				"skinDataVersion":"1008900008",
-				"avatarComponents":"",
-				"nickName":"4c4e24740f427",
-				"movingMode":0,
-				"attitude":"walk",
-				"areaName":"",
-				"pathName":"",
-				"pathId":"",
-				"avatarSize":1,
-				"extra":
-				{
-					"removeWhenDisconnected":true
-				},
-				"prioritySync":false,
-				"player":
-				{
-					"position":{"x":-755,"y":-1450,"z":-34},
-					"angle":{"pitch":0,"yaw":0,"roll":0}
+			"camera": {
+				"position": {
+					"x": -748.74274,
+					"y": -1577.3701,
+					"z": 86
 				},
-				"camera":null,
-				"cameraCenter":null
+				"angle": {
+					"pitch": 0,
+					"yaw": 92.8125,
+					"roll": 0
+				}
 			},
-			"renderInfo":
-			{
-				"renderType":0,
-				"videoFrame":null,
-				"cameraStateType":0,
-				"isMoving":0,
-				"needIfr":0,
-				"isVideo":0,
-				"stillFrame":0,
-				"isRotating":0,
-				"isFollowing":0,
-				"clientPanoTitlesBitmap":[],
-				"clientPanoTreceId":"",
-				"prefetchVideoId":"",
-				"noMedia":false
-			},
-			"event":
-			{
-				"id":"",
-				"type":0,
-				"points":[],
-				"rotateEvent":null,
-				"removeVisitorEvent":null
-			},
-			"relation":0
-		}
-	],
-	"code":0,
-	"msg":""
-}
-6. 旋转:
-{
-	"actionType":1014,
-	"pointType":100,
-	"extra":"",
-	"traceId":"b12a3b92-1e49-4764-851d-32f0466286bf",
-	"packetId":"",
-	"nps":[],
-	"peopleNum":0,
-	"zoneId":"",
-	"echoMsg":"",
-	"reserveDetail":null,
-	"userWithAvatarList":[],
-	"newUserStates":[],
-	"code":0,
-	"msg":""
+			"cameraCenter": {
+				"x": -755,
+				"y": -1450,
+				"z": -34
+			}
+		},
+		"renderInfo": {
+			"renderType": 0,
+			"videoFrame": null,
+			"cameraStateType": 0,
+			"isMoving": 0,
+			"needIfr": 0,
+			"isVideo": 0,
+			"stillFrame": 0,
+			"isRotating": 0,
+			"isFollowing": 0,
+			"clientPanoTitlesBitmap": [],
+			"clientPanoTreceId": "",
+			"prefetchVideoId": "",
+			"noMedia": false
+		},
+		"event": null,
+		"relation": 1
+	}],
+	"actionResponses": [],
+	"getStateType": 0,
+	"code": 0,
+	"msg": "OK"
 }
-7. 获取呼吸点
+8. 获取呼吸点
 {
 	"actionType":1004,
 	"pointType":100,
@@ -528,5 +444,4 @@
 	"code":0,
 	"msg":""
 }
-8.
 /*************************************************************************************************************************/