浏览代码

feat(core): update

gemercheung 3 年之前
父节点
当前提交
ecdfc3918b
共有 2 个文件被更改,包括 30 次插入32 次删除
  1. 12 12
      webrtc/srs.js
  2. 18 20
      webrtc/srsRtc.js

+ 12 - 12
webrtc/srs.js

@@ -10,8 +10,8 @@ const connection = new Connection(testConfig);
 
 console.log("sdk", sdk);
 console.log("sdk", connection);
-// const url = "webrtc://demo-kms.4dage.com/live/test2222";
-// sdk.start(url);
+const url = "webrtc://demo-kms.4dage.com/live/livestream";
+sdk.start(url);
 
 console.log("第一个");
 // connection.socket.emit("pushVideo", {
@@ -89,16 +89,16 @@ connection.socket.emit("getVideo", {
   userId: testConfig.userId,
 });
 
-// connection.socket.emit("getRotateVideo", {
-//   videoPath: "sample-5s",
-//   sessionId: "3",
-//   sceneCode: testConfig.sceneCode,
-//   roomId: testConfig.roomId,
-//   userId: testConfig.userId,
-//   sangle: "0",
-//   eangle: "360",
-//   reverses: false,
-// });
+connection.socket.emit("getRotateVideo", {
+  videoPath: "sample-5s",
+  sessionId: "3",
+  sceneCode: testConfig.sceneCode,
+  roomId: testConfig.roomId,
+  userId: testConfig.userId,
+  sangle: "0",
+  eangle: "360",
+  reverses: true,
+});
 
 connection.socket.on("getSocketVideo", async (data) => {
   console.log("getSocketVideo", data);

+ 18 - 20
webrtc/srsRtc.js

@@ -3,8 +3,7 @@ export class SrsRTC {
     this.stream = new MediaStream();
     this.url = url;
     this.offer = null;
-    this.pc = null;
-    // this.pc = new RTCPeerConnection(null);
+
     const supportsInsertableStreams =
       !!RTCRtpSender.prototype.createEncodedStreams;
     console.log("supportsInsertableStreams", supportsInsertableStreams);
@@ -23,26 +22,26 @@ export class SrsRTC {
       this.onIceCandidate(this.pc, e)
     );
     this.pc.addEventListener("datachannel", this.ondatachannel);
-    // this.pc.ondatachannel = (event) => {
-    //   console.log("ondatachannel", ondatachannel);
-    //   this.inputChannel.onopen = () => {
-    //     console.log("连接");
-    //   };
-    //   this.inputChannel.onmessage = (event) => {
-    //     // mark00 rtcp接收
-    //     console.log("连接", event);
-    //   };
-    //   this.inputChannel.close = (event) => {
-    //     // mark00 rtcp接收
-    //     console.log("close", event);
-    //   };
-    // };
+    this.pc.ondatachannel = (event) => {
+      console.log("ondatachannel", ondatachannel);
+      this.inputChannel.onopen = () => {
+        console.log("连接");
+      };
+      this.inputChannel.onmessage = (event) => {
+        // mark00 rtcp接收
+        console.log("连接", event);
+      };
+      this.inputChannel.close = (event) => {
+        // mark00 rtcp接收
+        console.log("close", event);
+      };
+    };
   }
   onIceCandidate(event) {
-    console.log("icecandidate", event);
+    console.warn("icecandidate", event);
   }
   ondatachannel(event) {
-    console.log("ondatachannel", ondatachannel);
+    console.warn("ondatachannel", ondatachannel);
   }
 
   close() {
@@ -55,12 +54,12 @@ export class SrsRTC {
   }
 
   async start(clipUrl) {
+    this.pc.addTransceiver("video", { direction: "recvonly" });
     const serverApi = "https://demo-kms.4dage.com:443/rtc/v1/play/";
     const tid = Number(parseInt(new Date().getTime() * Math.random() * 100))
       .toString(16)
       .slice(0, 7);
     var offer = await this.pc.createOffer();
-    this.offer = offer;
     await this.pc.setLocalDescription(offer);
     const session = await new Promise(function (resolve, reject) {
       // @see https://github.com/rtcdn/rtcdn-draft
@@ -92,7 +91,6 @@ export class SrsRTC {
           reject(reason);
         });
     });
-    console.log("session", session);
     await this.pc.setRemoteDescription(
       new RTCSessionDescription({ type: "answer", sdp: session.sdp })
     );