浏览代码

基本上socket和webrtc全部屏蔽了。

xushiting 3 年之前
父节点
当前提交
2c20faafe8
共有 7 个文件被更改,包括 336 次插入161 次删除
  1. 40 43
      src/NetworkController.js
  2. 20 19
      src/Rtcp.js
  3. 167 0
      src/ServerData.js
  4. 1 1
      src/Signal.js
  5. 52 52
      src/Socket.js
  6. 50 45
      src/Workers.js
  7. 6 1
      src/Xverse_Room.js

+ 40 - 43
src/NetworkController.js

@@ -77,24 +77,21 @@ export default class NetworkController extends EventEmitter {
     }
 
     startGame(){
-        return new Promise((e,t)=>{
-            if (!this.rtcp.connected)
-                return t(new InternalError("Game cannot load. Please refresh"));
-            if (!this.rtcp.inputReady)
-                return t(new InternalError("Game is not ready yet. Please wait"));
-            this.socket.on("gameRoomAvailable", r=>{
-               
-                this.setState("connected"),
-                e(r),
-                this.rtcp.heartbeat.start()
-            }
-            ),
-            this.socket.on("socketClosed", r=>{
-                t(r)
-            }
-            ),
-            this.socket.startGame()
-        })
+        // return new Promise((e,t)=>{
+        //     if (!this.rtcp.connected)
+        //         return t(new InternalError("Game cannot load. Please refresh"));
+        //     if (!this.rtcp.inputReady)
+        //         return t(new InternalError("Game is not ready yet. Please wait"));
+        //     this.socket.on("gameRoomAvailable", r=>{
+        //         this.setState("connected"),
+        //         e(r),
+        //         this.rtcp.heartbeat.start()
+        //     }),
+        //     this.socket.on("socketClosed", r=>{
+        //         t(r)
+        //     });
+        //     this.socket.startGame()
+        // })
     }
 
     addBlockedActions(e) {
@@ -121,31 +118,31 @@ export default class NetworkController extends EventEmitter {
             reconnect: e
         });
         return new Promise((t,r)=>{
-      
-            this.rtcp.on("rtcConnected", ()=>{
-                this.setState("connected"),
-                t()
-            }
-            ),
-            this.rtcp.on("rtcDisconnected", ()=>{
-                logger.info("rtc disconnected"),
-                this._state === "connecting" ? (this.setState("disconnected"),
-                r(new InternalError("rtc connect failed"))) : (this.setState("disconnected"),
-                logger.info("rtc disconnected, start to reconnect"),
-                this.reconnect())
-            }
-            ),
-            this.socket.on("socketQuit", ()=>{
-                logger.info("socket quit success"),
-                this.setState("closed")
-            }
-            ),
-            this.socket.on("socketClosed", n=>{
-                this._state === "connecting" && (this.setState("disconnected"),
-                r(n)),
-                r(n)
-            }
-            ),
+            t()
+            // this.rtcp.on("rtcConnected", ()=>{
+            //     this.setState("connected"),
+            //     t()
+            // }
+            // ),
+            // this.rtcp.on("rtcDisconnected", ()=>{
+            //     logger.info("rtc disconnected"),
+            //     this._state === "connecting" ? (this.setState("disconnected"),
+            //     r(new InternalError("rtc connect failed"))) : (this.setState("disconnected"),
+            //     logger.info("rtc disconnected, start to reconnect"),
+            //     this.reconnect())
+            // }
+            // ),
+            // this.socket.on("socketQuit", ()=>{
+            //     logger.info("socket quit success"),
+            //     this.setState("closed")
+            // }
+            // ),
+            // this.socket.on("socketClosed", n=>{
+            //     this._state === "connecting" && (this.setState("disconnected"),
+            //     r(n)),
+            //     r(n)
+            // }
+            // ),
             this.socket.start()
         }
         )

+ 20 - 19
src/Rtcp.js

@@ -158,30 +158,30 @@ export default class Rtcp extends EventEmitter {
            
             this.inputChannel = t.channel;
             this.inputChannel.onopen = ()=>{
-                var r;
-                logger.info("The input channel has opened, id:", (r = this.inputChannel) == null ? void 0 : r.id),
-                this.inputReady = !0,
-                this.emit("rtcConnected"),
-                this.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
-                    metric: "datachannelOpenedAt",
-                    startTime: this.network.room._startTime,
-                    group: "joinRoom"
-                }),
-                logger.infoAndReportMeasurement({
-                    metric: "datachannelOpenedCost",
-                    startTime: e,
-                    group: "joinRoom"
-                }))
-                console.log('this.inputChannel',this.inputChannel)
+                // var r;
+                // logger.info("The input channel has opened, id:", (r = this.inputChannel) == null ? void 0 : r.id),
+                // this.inputReady = !0;
+                // this.emit("rtcConnected");
+                // this.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
+                //     metric: "datachannelOpenedAt",
+                //     startTime: this.network.room._startTime,
+                //     group: "joinRoom"
+                // }),
+                // logger.infoAndReportMeasurement({
+                //     metric: "datachannelOpenedCost",
+                //     startTime: e,
+                //     group: "joinRoom"
+                // }))
+                // console.log('this.inputChannel',this.inputChannel)
             }
             ,
             this.inputChannel.onclose = ()=>{
-                var r;
-                return logger.info("The input channel has closed, id:", (r = this.inputChannel) == null ? void 0 : r.id)
+                // var r;
+                // 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)
+                // console.log('inputChannel',r.data)
                 this.workers.dataHandle(r.data)
             }
         }
@@ -189,7 +189,8 @@ export default class Rtcp extends EventEmitter {
         this.connection.oniceconnectionstatechange = this.onIceConnectionStateChange,
         this.connection.onicegatheringstatechange = this.onIceStateChange,
         this.connection.onicecandidate = this.onIcecandidate,
-        this.connection.onicecandidateerror = this.onIcecandidateerror,
+        this.connection.onicecandidateerror = this.onIcecandidateerror;
+
         this.network.socket.send({
             id: "init_webrtc",
             data: JSON.stringify({

+ 167 - 0
src/ServerData.js

@@ -0,0 +1,167 @@
+var ServerData = {
+    "star":{
+        "signal":{
+            "traceIds": [],
+            "vehicle": null,
+            "newUserStates": [{
+                "userId": "f5e382f1758a8",
+                "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": -375,
+                            "y": 1250,
+                            "z": 0
+                        },
+                        "angle": {
+                            "pitch": 0,
+                            "yaw": 0,
+                            "roll": 0
+                        }
+                    },
+                    "camera": {
+                        "position": {
+                            "x": -775,
+                            "y": 1250,
+                            "z": 150
+                        },
+                        "angle": {
+                            "pitch": 0,
+                            "yaw": 0,
+                            "roll": 0
+                        }
+                    },
+                    "cameraCenter": {
+                        "x": -375,
+                        "y": 1250,
+                        "z": 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": null,
+                "relation": 1
+            }],
+            "actionResponses": [],
+            "getStateType": 0,
+            "code": 0,
+            "msg": "OK"
+        },
+        "pts": 1,
+        "alreadyUpdateYUV": true
+    },
+    "module":{
+        "signal": {
+            "traceIds": [],
+            "vehicle": null,
+            "newUserStates": [{
+                "userId": null,    //要补充
+                "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": null,
+                            "y": null,
+                            "z": null
+                        },
+                        "angle": {                 //要补充
+                            "pitch": 0,
+                            "yaw": 0,
+                            "roll": 0
+                        }
+                    },
+                    "camera": {
+                        "position": {              //要补充
+                            "x": null,
+                            "y": null,
+                            "z": null
+                        },
+                        "angle": {                 //要补充
+                            "pitch": 0,          
+                            "yaw": 0,
+                            "roll": 0
+                        }
+                    },
+                    "cameraCenter": {               //要补充
+                        "x": null,
+                        "y": null,
+                        "z": 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": null,
+                "relation": 1
+            }],
+            "actionResponses": [],
+            "getStateType": 0,
+            "code": 0,
+            "msg": "OK"
+        },
+        "pts": null,
+        "alreadyUpdateYUV": true
+    }
+}
+
+export default ServerData

+ 1 - 1
src/Signal.js

@@ -19,7 +19,7 @@ export default class Signal {
         {
             return;
         }
-        console.log('执行handleSignal:'+e.signal)
+        console.log('执行handleSignal:'+JSON.stringify(e.signal))
         const {signal: signal, alreadyUpdateYUV: alreadyUpdateYUV} = e;
         this.handleActionResponses(signal);
         //this._room.handleSignalHook(signal);

+ 52 - 52
src/Socket.js

@@ -110,25 +110,25 @@ export default class Socket extends EventEmitter {
             const r = `Failed to open websocket in ${DEFAULT_OPEN_TIMEOUT_MS} ms`;
             this._hasTimeout = !0,
             this.emit("socketClosed", new InitNetworkTimeoutError(r))
-        }
-        ,DEFAULT_OPEN_TIMEOUT_MS),
-        this._ws.onopen = ()=>{
-            var r;
-            (r = this._openTimer) == null || r.clear(),
-            this.connected = !0,
-            this.heartbeat.start(),
-            this.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
-                metric: "wsOpenedAt",
-                group: "joinRoom",
-                startTime: this.network.room._startTime
-            }),
-            logger.infoAndReportMeasurement({
-                metric: "wsOpenedCost",
-                group: "joinRoom",
-                startTime: t
-            }))
-        }
-        ,
+        },DEFAULT_OPEN_TIMEOUT_MS),
+
+        // this._ws.onopen = ()=>{
+        //     var r;
+        //     (r = this._openTimer) == null || r.clear(),
+        //     this.connected = !0,
+        //     this.heartbeat.start(),
+        //     this.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
+        //         metric: "wsOpenedAt",
+        //         group: "joinRoom",
+        //         startTime: this.network.room._startTime
+        //     }),
+        //     logger.infoAndReportMeasurement({
+        //         metric: "wsOpenedCost",
+        //         group: "joinRoom",
+        //         startTime: t
+        //     }))
+        // },
+        this.connected = !0;
         this.handleWSEvent()
     }
     getAddress() {
@@ -186,9 +186,9 @@ export default class Socket extends EventEmitter {
                         }
                         this.network.rtcp.start();
                         break;
-                    case "heartbeat":
-                        //this.heartbeat.pong(r.data);
-                        break;
+                    // case "heartbeat":
+                    //     this.heartbeat.pong(r.data);
+                    //     break;
                     case "offer":
                         this.network.rtcp.setRemoteDescription(r.data, this.network.stream.el);
                         break;
@@ -198,36 +198,36 @@ export default class Socket extends EventEmitter {
                     case "start":
                         this.emit("gameRoomAvailable", r);
                         break;
-                    case "error":
-                        try {
-                            const {Code: o, Msg: a} = JSON.parse(r.data);
-                            if (o) {
-                                if (o == 3003)
-                                    return this.emit("socketClosed", new TokenExpiredError);
-                                if (authenticationErrorCodes.indexOf(o) > -1)
-                                    return this.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
-                                {
-                                    const s = util.getErrorByCode(o);
-                                    this.emit("socketClosed", new s(a))
-                                }
-                            }
-                        } catch (o) {
-                            logger.error(o),
-                            this.emit("socketClosed", new InternalError(r.data))
-                        }
-                        break;
-                    case "checkLatency":
-                        {
-                            const o = r.packet_id
-                            , a = r.data.split(",");
-                            this.onLatencyCheck({
-                                packetId: o,
-                                addresses: a
-                            });
-                            break
-                        }
-                    default:
-                        logger.warn("unkown ws message type", n, r)
+                    // case "error":
+                    //     try {
+                    //         const {Code: o, Msg: a} = JSON.parse(r.data);
+                    //         if (o) {
+                    //             if (o == 3003)
+                    //                 return this.emit("socketClosed", new TokenExpiredError);
+                    //             if (authenticationErrorCodes.indexOf(o) > -1)
+                    //                 return this.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
+                    //             {
+                    //                 const s = util.getErrorByCode(o);
+                    //                 this.emit("socketClosed", new s(a))
+                    //             }
+                    //         }
+                    //     } catch (o) {
+                    //         logger.error(o),
+                    //         this.emit("socketClosed", new InternalError(r.data))
+                    //     }
+                    //     break;
+                    // case "checkLatency":
+                    //     {
+                    //         const o = r.packet_id
+                    //         , a = r.data.split(",");
+                    //         this.onLatencyCheck({
+                    //             packetId: o,
+                    //             addresses: a
+                    //         });
+                    //         break
+                    //     }
+                    // default:
+                    //     logger.warn("unkown ws message type", n, r)
                 }
             }
         }

+ 50 - 45
src/Workers.js

@@ -12,6 +12,7 @@ const USER_ID = "987412365"
   , FRAME_COMPOSE_LENGTH = 5;
 
 import CircularArray from "./CircularArray.js"
+import ServerData from "./ServerData.js"
 
 export default class Workers {
     constructor(e, t) {
@@ -641,18 +642,21 @@ export default class Workers {
                 }),
                 this.firstUpdateYUV = !1
             }
+            
             this.cachedStreams[e] != null && this.executeFunction("stream", {
                 stream: this.cachedStreams[e],
                 width: this.cachedResolution[e].width,
                 height: this.cachedResolution[e].height,
                 pts: this.cachedPtss[e]
             });
-            const o = Date.now();
-            this.cachedStreams[e] != null && this.decoderWorker.postMessage({
-                t: 2,
-                frameCnt: this.cachedPtss[e],
-                buffer: this.cachedStreams[e]
-            }, [this.cachedStreams[e].buffer]);
+
+            // const o = Date.now();
+            // this.cachedStreams[e] != null && this.decoderWorker.postMessage({
+            //     t: 2,
+            //     frameCnt: this.cachedPtss[e],
+            //     buffer: this.cachedStreams[e]
+            // }, [this.cachedStreams[e].buffer]);
+
             // const a = Date.now()
             //   , s = o - n
             //   , l = a - o;
@@ -690,12 +694,12 @@ export default class Workers {
             //     this.lastMoveDisplayTime = h
             // }
 
-            
             this.executeFunction("signal", {
-                signal: this.cachedMetas[e],
-                pts: this.cachedPtss[e],
+                signal: ServerData.star.signal,     //this.cachedMetas[e],
+                pts: ServerData.star.pts,           //this.cachedPtss[e],
                 alreadyUpdateYUV: !0
             })
+            
             this.cachedRender[e] = !0;
             this.getPtr = (this.getPtr + 1) % this.cachedLength
             
@@ -970,11 +974,11 @@ export default class Workers {
                     };
                     if (this.inPanoMode)
                     {
-                        this.executeFunction("signal", {
-                            signal: L,
-                            pts: -1,
-                            alreadyUpdateYUV: !0
-                        });
+                        // this.executeFunction("signal", {
+                        //     signal: L,
+                        //     pts: -1,
+                        //     alreadyUpdateYUV: !0
+                        // });
                         return !0;
                     }
                     this.decoderWorker.postMessage(z, [D.buffer]);
@@ -1026,45 +1030,46 @@ export default class Workers {
         defaultLogger.debug("hhh")
     }
     dataHandle(e) {
-        if(this.saveframe){
-            this.decoderWorker.postMessage({
-                t: 6
-            }),
-            this.saveframe = !1
-        }
+        // if(this.saveframe){
+        //     this.decoderWorker.postMessage({
+        //         t: 6
+        //     }),
+        //     this.saveframe = !1
+        // }
 
-        if(this.SaveMediaStream){
-            this.decoderWorker.postMessage({
-                t: 7
-            }),
-            this.SaveMediaStream = !1
-        }
+        // if(this.SaveMediaStream){
+        //     this.decoderWorker.postMessage({
+        //         t: 7
+        //     }),
+        //     this.SaveMediaStream = !1
+        // }
 
         const t = new Uint8Array(e);
         if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0)
         {
             return;
         }
+        
         if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
-            if(this.reconnectSignal){
-                this.executeFunction("reconnectedFrame", {});
-                this.reconnectSignal = !1
-            }
+            // if(this.reconnectSignal){
+            //     this.executeFunction("reconnectedFrame", {});
+            //     this.reconnectSignal = !1
+            // }
             return
         }
-        if (t.length > 20 && this.unmarshalPano(t.buffer) == !0)
-        {
-            return;
-        }
-        this.noWasmBytesReceived += e.byteLength;
-        const r = JSON.parse(this.Stringify(t));
+        // if (t.length > 20 && this.unmarshalPano(t.buffer) == !0)
+        // {
+        //     return;
+        // }
+        // this.noWasmBytesReceived += e.byteLength;
+        // const r = JSON.parse(this.Stringify(t));
 
-        console.log('接收webrtc的json数据:'+JSON.stringify(r));
-        this.executeFunction("signal", {
-            signal: r,
-            pts: -1,
-            alreadyUpdateYUV: !0
-        })
+        // console.log('接收webrtc的json数据:'+JSON.stringify(r));
+        // this.executeFunction("signal", {
+        //     signal: r,
+        //     pts: -1,
+        //     alreadyUpdateYUV: !0
+        // })
     }
     changePanoMode(e) {
         this.inPanoMode = e
@@ -1235,8 +1240,8 @@ export default class Workers {
             maxServerDiff: J,
             streamType: WASM_Version
         };
-        return this.lastReturnFrames = this.returnFrames,
-        this.lastReceivedEmit = this.receivedEmit,
-        re
+        this.lastReturnFrames = this.returnFrames;
+        this.lastReceivedEmit = this.receivedEmit;
+        return re
     }
 }

+ 6 - 1
src/Xverse_Room.js

@@ -537,7 +537,12 @@ export default class Xverse_Room extends EventEmitter {
             return t;
         try {
             await this.beforeStartGameHook(this.options);
-            const {room_id: room_id, data: n, session_id: session_id} = await this.networkController.startGame();
+            //const {room_id: room_id, data: n, session_id: session_id} = await this.networkController.startGame();
+            this.networkController.socket.startGame()
+            const room_id = this.options.roomId;
+            const n = JSON.stringify(this.options.camera);
+            const session_id = '';
+
             this._id = room_id;
             const a = JSON.parse(n);
             this.isHost = a.IsHost,