xushiting 3 年之前
父節點
當前提交
87f983f403
共有 3 個文件被更改,包括 69 次插入57 次删除
  1. 9 2
      src/Rtcp.js
  2. 58 55
      src/Socket.js
  3. 2 0
      src/Workers.js

+ 9 - 2
src/Rtcp.js

@@ -115,8 +115,15 @@ export default class Rtcp extends EventEmitter {
         }
         );
         E(this, "input", e=>{
-            var t;
-            !this.actived || !this.inputChannel || this.inputChannel.readyState === "open" && ((t = this.inputChannel) == null || t.send(e))
+            // var t = this.inputChannel
+            // if(!this.actived || !this.inputChannel || this.inputChannel.readyState === "open"){
+            //     if(t!=null){
+            //         //发送webrtc数据
+            //         console.log('发送webrtc数据:'+e)
+            //         t.send(e)
+            //     }
+            // }
+            //!this.actived || !this.inputChannel || this.inputChannel.readyState === "open" && (t == null || t.send(e))
         }
         );
         this.network = e,

+ 58 - 55
src/Socket.js

@@ -160,6 +160,7 @@ export default class Socket extends EventEmitter {
             let r = null;
             try {
                 r = JSON.parse(t.data)
+                console.log('接收socket数据:'+t.data)
             } catch (o) {
                 logger.error(o);
                 return
@@ -169,64 +170,66 @@ export default class Socket extends EventEmitter {
             const n = r.id;
             
             if (!!n)
-                switch (n !== "heartbeat" && logger.info(`receive ws frame: ${t.data}`),
-                n) {
-                case "fail":
-                    break;
-                case "init":
-                    try {
-                        const o = r.data.slice(-37, -1);
-                        reporter.updateBody({
-                            serverSession: o
-                        })
-                    } catch (o) {
-                        console.error(o)
-                    }
-                    this.network.rtcp.start();
-                    break;
-                case "heartbeat":
-                    this.heartbeat.pong(r.data);
-                    break;
-                case "offer":
-                    this.network.rtcp.setRemoteDescription(r.data, this.network.stream.el);
-                    break;
-                case "ice_candidate":
-                    this.network.rtcp.addCandidate(r.data);
-                    break;
-                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))
+            {
+                n !== "heartbeat" && logger.info(`receive ws frame: ${t.data}`);
+                switch (n) {
+                    case "fail":
+                        break;
+                    case "init":
+                        try {
+                            const o = r.data.slice(-37, -1);
+                            reporter.updateBody({
+                                serverSession: o
+                            })
+                        } catch (o) {
+                            console.error(o)
+                        }
+                        this.network.rtcp.start();
+                        break;
+                    case "heartbeat":
+                        //this.heartbeat.pong(r.data);
+                        break;
+                    case "offer":
+                        this.network.rtcp.setRemoteDescription(r.data, this.network.stream.el);
+                        break;
+                    case "ice_candidate":
+                        this.network.rtcp.addCandidate(r.data);
+                        break;
+                    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))
                         }
-                    } 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)
+                        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)
                 }
+            }
         }
         )
     }

+ 2 - 0
src/Workers.js

@@ -1058,6 +1058,8 @@ export default class Workers {
         }
         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,