Browse Source

Merge branch 'master' of http://192.168.0.115:3000/zhouenguang/PrimordialUniverse

zhouenguang 3 years ago
parent
commit
997fb97a29
5 changed files with 565 additions and 249 deletions
  1. 17 13
      index.html
  2. 93 74
      webrtc/srs.js
  3. 169 0
      webrtc/srsRtc copy 2.js
  4. 102 76
      webrtc/srsRtc copy.js
  5. 184 86
      webrtc/srsRtc.js

+ 17 - 13
index.html

@@ -27,19 +27,23 @@
       </style>
     </head>
     <body>
-      <video id="testVideoFeed" crossorigin="anonymous" playsinline autoplay muted  style="
-      position: fixed;
-      width: 600px;
-      height: 600px;
-      z-index: 10000;
-      top: 0;
-      left: 0;
-    "></video>
+      <video
+        id="testVideoFeed"
+        crossorigin="anonymous"
+        playsinline
+        autoplay
+        muted
+        style="
+          position: fixed;
+          width: 600px;
+          height: 600px;
+          z-index: 10000;
+          top: 0;
+          left: 0;
+        "
+      ></video>
       <canvas id="renderCanvas"></canvas>
 
-     
-     
-
       <div id="videoTextureBox">
         <video
           id="houseTexture0"
@@ -53,7 +57,7 @@
       </div>
 
       <!-- Babylon.js -->
-      <script  src="./libs/jquery-1.10.2.min.js"></script>
+      <script src="./libs/jquery-1.10.2.min.js"></script>
       <script src="./libs/dat.gui.min.js"></script>
       <script src="./libs/ammo.js"></script>
       <script src="./libs/cannon.js"></script>
@@ -138,6 +142,6 @@
       <script src="./worker/index.js" type="module"></script>
       <script type="module" src="./webrtc/srs.js"></script>
     </body>
-    <script src="https://web.sdk.qcloud.com/trtc/webrtc/demo/latest/dist/trtc.js"></script>
+    <!-- <script src="https://web.sdk.qcloud.com/trtc/webrtc/demo/latest/dist/trtc.js"></script> -->
   </html>
 </html>

+ 93 - 74
webrtc/srs.js

@@ -1,25 +1,26 @@
-
-import {SrsRTC } from './SrsRTC.js';
-import { Connection } from './connection.js';
+import { SrsRTC } from "./srsRtc.js";
+import { Connection } from "./connection.js";
 const sdk = new SrsRTC();
-const testConfig ={
-    sceneCode:"testApp",
-    userId: 'testUser',
-    roomId: '8888',
-}
-const connection =new Connection(testConfig);
-
-console.log('sdk',sdk)
-console.log('sdk',connection)
-
-// console.log('第一个')
-connection.socket.emit('pushVideo',{
-    videoList:['sample-5s','output','sample-5s','output','sample-5s','output','sample-5s','output'],
-    sessionId:'1',
-    sceneCode:testConfig.sceneCode,
-    roomId:testConfig.roomId,
-    userId:testConfig.userId,
-})
+const testConfig = {
+  sceneCode: "testApp",
+  userId: "testUser",
+  roomId: "8888",
+};
+const connection = new Connection(testConfig);
+
+console.log("sdk", sdk);
+console.log("sdk", connection);
+const url = "webrtc://demo-kms.4dage.com/live/test1";
+sdk.start(url);
+
+console.log("第一个");
+// connection.socket.emit("pushVideo", {
+//   videoList: ["0/0_1_0", "0/0_1_1"],
+//   sessionId: "1",
+//   sceneCode: testConfig.sceneCode,
+//   roomId: testConfig.roomId,
+//   userId: testConfig.userId,
+// });
 // setTimeout(()=>{
 //     console.log('第二个')
 
@@ -58,8 +59,6 @@ connection.socket.emit('pushVideo',{
 //     })
 // },14000)
 
-
-
 // setTimeout(()=>{
 //     console.log('第三个')
 //     connection.socket.emit('pushVideo',{
@@ -71,57 +70,77 @@ connection.socket.emit('pushVideo',{
 //     })
 // },20000)
 
-window.connection =connection;
-
-// connection.socket.on('getVideo',async(streamUrl)=>{
-//     if(streamUrl){
-//         const url ='webrtc://demo-kms.4dage.com/' + streamUrl;
-//         console.log('getVideo',streamUrl);
-//         sdk.close();
-//         await getVideo(url)
-//     }
-// })
-const downloadURL = function(r, n) {
-    const o = document.createElement("a");
-    o.href = r,
-    o.download = n,
+window.connection = connection;
+
+// connection.socket.on("getVideo", async (streamUrl) => {
+//   if (streamUrl) {
+//     const url = "webrtc://demo-kms.4dage.com/" + streamUrl;
+//     console.log("getVideo", streamUrl);
+//     sdk.close();
+//     await getVideo(url);
+//   }
+// });
+// 正转
+// connection.socket.emit("getVideo", {
+//   videoList: ["0/0_1_0", "0/0_1_1", "0/0_1_2"],
+//   //   sessionId: "1",
+//   sceneCode: testConfig.sceneCode,
+//   roomId: testConfig.roomId,
+//   userId: testConfig.userId,
+// });
+
+// connection.socket.emit("getRotateVideo", {
+//   videoPath: "0/0_1_0",
+//   //   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);
+  downloadBlob(data, "getSocketVideo.mp4", "application/video");
+});
+
+const downloadURL = function (r, n) {
+  const o = document.createElement("a");
+  (o.href = r),
+    (o.download = n),
     document.body.appendChild(o),
-    o.style.display = "none",
+    (o.style.display = "none"),
     o.click(),
-    o.remove()
-}
+    o.remove();
+};
 let downloadBlob = (data, fileName, mimeType) => {
-    const blob = new Blob([data], {
-      type: mimeType,
-    })
-    const url = URL.createObjectURL(blob)
-    downloadURL(url, fileName)
-    setTimeout(function () {
-      return URL.revokeObjectURL(url)
-    }, 3000)
-  }
-
-connection.socket.emit('pushVideo_test',async(data)=>{
-   console.log(data)
-})
-connection.socket.on('pushVideo_test',async(data)=>{
-   console.log(data)
-   downloadBlob(data, 'test.mp4', 'application/video')
-})
-
-
-
-const getVideo =(videoUrl)=>{
-    $('#testVideoFeed').prop('srcObject', sdk.stream);
-    sdk.getVideo(videoUrl).then(function(session){
-        console.log('session',session.sessionid)
-    
-    }).catch(function (reason) {
-        console.error(reason);
-    })
-}
-
-
-
-
-
+  const blob = new Blob([data], {
+    type: mimeType,
+  });
+  const url = URL.createObjectURL(blob);
+  downloadURL(url, fileName);
+  setTimeout(function () {
+    return URL.revokeObjectURL(url);
+  }, 3000);
+};
+
+// connection.socket.emit("pushVideo_test", {
+//   videoPath: "sample-5s",
+// });
+// connection.socket.on("pushVideo_test", async (data) => {
+//   console.log(data);
+//   //    downloadBlob(data, 'test.mp4', 'application/video')
+// });
+
+// const getVideo = (videoUrl) => {
+//   $("#testVideoFeed").prop("srcObject", sdk.stream);
+//   sdk
+//     .getVideo(videoUrl)
+//     .then(function (session) {
+//       console.log("session", session.sessionid);
+//     })
+//     .catch(function (reason) {
+//       console.error(reason);
+//     });
+// };

+ 169 - 0
webrtc/srsRtc copy 2.js

@@ -0,0 +1,169 @@
+export class SrsRTC {
+  constructor(url) {
+    this.stream = new MediaStream();
+    this.url = url;
+    this.offer = null;
+    // this.pc = null;
+    this.pc = new RTCPeerConnection({
+      encodedInsertableStreams: true,
+    });
+    this.pc.addEventListener('icecandidate', e => 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);
+    //   };
+    // };
+  }
+  onIceCandidate(event){
+    console.log('icecandidate',event)
+  }
+  ondatachannel(event){
+    console.log('ondatachannel',ondatachannel)
+  }
+
+  close() {
+    var remoteVideo = document.querySelector("#testVideoFeed");
+    if (remoteVideo.srcObject) {
+      remoteVideo.srcObject.getTracks().forEach((track) => track.stop());
+    }
+    this.pc && this.pc.close();
+    this.pc = null;
+  }
+
+  start(clipUrl) {
+    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
+      var data = {
+        api: serverApi,
+        tid: tid,
+        streamurl: clipUrl,
+        clientip: null,
+        sdp: offer.sdp,
+      };
+      console.log("Generated offer: ", data);
+      $.ajax({
+        type: "POST",
+        url: serverApi,
+        data: JSON.stringify(data),
+        contentType: "application/json",
+        dataType: "json",
+      })
+        .done(function (data) {
+          console.log("Got answer: ", data);
+          if (data.code) {
+            reject(data);
+            return;
+          }
+
+          resolve(data);
+        })
+        .fail(function (reason) {
+          reject(reason);
+        });
+    });
+    await this.pc.setRemoteDescription(
+      new RTCSessionDescription({ type: "answer", sdp: session.sdp })
+    );
+
+  }
+
+  async getVideo(clipUrl) {
+    if (!this.pc) {
+      this.pc = new RTCPeerConnection(null);
+      this.pc.ontrack = (event) => {
+        // https://webrtc.org/getting-started/remote-streams
+        console.log("event", event);
+        if (this.stream) {
+          // this.stream.removeTrack(event.track));
+          const videoTrack = this.stream
+            .getVideoTracks()
+            .find((i) => i.kind === "video");
+          console.log("旧videoTrack", videoTrack);
+          if (videoTrack) {
+            this.stream.removeTrack(videoTrack);
+          }
+          // if(this.stream.removeTrack())
+          this.stream.addTrack(event.track);
+        }
+        //    mediaRecorder.
+      };
+
+      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.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
+      var data = {
+        api: serverApi,
+        tid: tid,
+        streamurl: clipUrl,
+        clientip: null,
+        sdp: offer.sdp,
+      };
+      console.log("Generated offer: ", data);
+      $.ajax({
+        type: "POST",
+        url: serverApi,
+        data: JSON.stringify(data),
+        contentType: "application/json",
+        dataType: "json",
+      })
+        .done(function (data) {
+          console.log("Got answer: ", data);
+          if (data.code) {
+            reject(data);
+            return;
+          }
+
+          resolve(data);
+        })
+        .fail(function (reason) {
+          reject(reason);
+        });
+    });
+    await this.pc.setRemoteDescription(
+      new RTCSessionDescription({ type: "answer", sdp: session.sdp })
+    );
+
+    return session;
+  }
+}

+ 102 - 76
webrtc/srsRtc copy.js

@@ -1,83 +1,109 @@
-
 export class SrsRTC {
-    constructor(url){
-       
-        this.stream = new MediaStream();
-        this.url = url;
-        this.offer = null;
-        this.pc  =null;
-        // this.pc = new RTCPeerConnection(null);
-        // this.pc.ontrack =  (event) => {
-        //         // https://webrtc.org/getting-started/remote-streams
-        //     console.warn('event',event.track)
-        //     if(this.stream){
-        //         this.stream.addTrack(event.track);
-        //     }
-        // };
-
-    }
-    close(){
-        this.pc && this.pc.close();
-        this.pc = null;
+  constructor(url) {
+    this.stream = new MediaStream();
+    this.url = url;
+    this.offer = null;
+    this.pc = null;
+    this.pc = new RTCPeerConnection(null);
+    // this.pc.ontrack =  (event) => {
+    //         // https://webrtc.org/getting-started/remote-streams
+    //     console.warn('event',event.track)
+    //     if(this.stream){
+    //         this.stream.addTrack(event.track);
+    //     }
+    // };
+  }
+  close() {
+    var remoteVideo = document.querySelector("#testVideoFeed");
+    if (remoteVideo.srcObject) {
+      remoteVideo.srcObject.getTracks().forEach((track) => track.stop());
     }
- 
-    async getVideo(clipUrl){
+    this.pc && this.pc.close();
+    this.pc = null;
+  }
 
-        if(!this.pc){
-            this.pc = new RTCPeerConnection(null);  
-            this.pc.ontrack =  (event) => {
-                // https://webrtc.org/getting-started/remote-streams
-                console.log('event',event.track)
-                if(this.stream){
-                    // this.stream.removeTrack(event.track));
-                    const videoTrack = this.stream.getVideoTracks().find(i=>i.kind ==='video')
-                    console.log('videoTrack',videoTrack)
-                    if(videoTrack){
-                        this.stream.removeTrack(videoTrack);
-                    }
-                    // if(this.stream.removeTrack())
-                    this.stream.addTrack(event.track);
-                }
-            };
+  start() {}
+
+  async getVideo(clipUrl) {
+    if (!this.pc) {
+      this.pc = new RTCPeerConnection(null);
+      this.pc.ontrack = (event) => {
+        // https://webrtc.org/getting-started/remote-streams
+        console.log("event", event);
+        if (this.stream) {
+          // this.stream.removeTrack(event.track));
+          const videoTrack = this.stream
+            .getVideoTracks()
+            .find((i) => i.kind === "video");
+          console.log("旧videoTrack", videoTrack);
+          if (videoTrack) {
+            this.stream.removeTrack(videoTrack);
+          }
+          // if(this.stream.removeTrack())
+          this.stream.addTrack(event.track);
         }
-     
-        this.pc.addTransceiver("video", {direction: "recvonly"});
+        //    mediaRecorder.
+      };
 
-        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
-            var data = {
-                api: serverApi,
-                tid: tid,
-                streamurl: clipUrl,
-                clientip: null, 
-                sdp: offer.sdp
-            };
-            console.log("Generated offer: ", data);
-            $.ajax({
-                type: "POST", url: serverApi, data: JSON.stringify(data),
-                contentType:'application/json', dataType: 'json'
-            }).done(function(data) {
-                console.log("Got answer: ", data);
-                if (data.code) {
-                    reject(data); return;
-                }
+      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);
+        };
+      };
+    }
 
-                resolve(data);
-            }).fail(function(reason){
-                reject(reason);
-            });
+    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
+      var data = {
+        api: serverApi,
+        tid: tid,
+        streamurl: clipUrl,
+        clientip: null,
+        sdp: offer.sdp,
+      };
+      console.log("Generated offer: ", data);
+      $.ajax({
+        type: "POST",
+        url: serverApi,
+        data: JSON.stringify(data),
+        contentType: "application/json",
+        dataType: "json",
+      })
+        .done(function (data) {
+          console.log("Got answer: ", data);
+          if (data.code) {
+            reject(data);
+            return;
+          }
+
+          resolve(data);
+        })
+        .fail(function (reason) {
+          reject(reason);
         });
-        await this.pc.setRemoteDescription(
-            new RTCSessionDescription({type: 'answer', sdp: session.sdp})
-        );
-        
-    
-        return session;
-        
-    }
-}
+    });
+    await this.pc.setRemoteDescription(
+      new RTCSessionDescription({ type: "answer", sdp: session.sdp })
+    );
+
+    return session;
+  }
+}

+ 184 - 86
webrtc/srsRtc.js

@@ -1,95 +1,193 @@
-
 export class SrsRTC {
-    constructor(url){
-       
-        this.stream = new MediaStream();
-        this.url = url;
-        this.offer = null;
-        this.pc  =null;
-        // this.pc = new RTCPeerConnection(null);
-        // this.pc.ontrack =  (event) => {
-        //         // https://webrtc.org/getting-started/remote-streams
-        //     console.warn('event',event.track)
-        //     if(this.stream){
-        //         this.stream.addTrack(event.track);
-        //     }
-        // };
+  constructor(url) {
+    this.stream = new MediaStream();
+    this.url = url;
+    this.offer = null;
 
+    const supportsInsertableStreams =
+      !!RTCRtpSender.prototype.createEncodedStreams;
+    console.log("supportsInsertableStreams", supportsInsertableStreams);
+    // this.pc.ontrack =  (event) => {
+    //         // https://webrtc.org/getting-started/remote-streams
+    //     console.warn('event',event.track)
+    //     if(this.stream){
+    //         this.stream.addTrack(event.track);
+    //     }
+    // };
+
+    this.pc = new RTCPeerConnection({
+      encodedInsertableStreams: true,
+    });
+    this.pc.addEventListener("icecandidate", (e) =>
+      this.onIceCandidate(this.pc, e)
+    );
+    this.pc.addEventListener("datachannel", this.ondatachannel);
+    // var dc = this.pc.createDataChannel("datachannel");
+    // dc.onmessage = function (event) {
+    //   console.log("received: " + event.data);
+    // };
+
+    // dc.onopen = function () {
+    //   console.log("datachannel open");
+    // };
+
+    // dc.onclose = function () {
+    //   console.log("datachannel close");
+    // };
+    // this.pc.ondatachannel = (event) => {
+    //   console.log("ondatachannel", event);
+    //   //   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.warn("icecandidate", event);
+  }
+  ondatachannel(event) {
+    console.warn("ondatachannel", ondatachannel);
+  }
+
+  close() {
+    var remoteVideo = document.querySelector("#testVideoFeed");
+    if (remoteVideo.srcObject) {
+      remoteVideo.srcObject.getTracks().forEach((track) => track.stop());
     }
-    close(){
-        var remoteVideo = document.querySelector("#testVideoFeed");
-        if(remoteVideo.srcObject){
-            remoteVideo.srcObject.getTracks().forEach(track => track.stop()); 
-        }
-        this.pc && this.pc.close();
-        this.pc = null;
-    }
- 
-    async getVideo(clipUrl){
+    this.pc && this.pc.close();
+    this.pc = null;
+  }
 
-        if(!this.pc){
-            this.pc = new RTCPeerConnection(null);  
-            this.pc.ontrack =  (event) => {
-                // https://webrtc.org/getting-started/remote-streams
-                console.log('event',event)
-                if(this.stream){
-                    // this.stream.removeTrack(event.track));
-                    const videoTrack = this.stream.getVideoTracks().find(i=>i.kind ==='video')
-                    console.log('旧videoTrack',videoTrack)
-                    if(videoTrack){
-                        this.stream.removeTrack(videoTrack);
-                    }
-                    // if(this.stream.removeTrack())
-                    this.stream.addTrack(event.track);
-                }      
-            //    mediaRecorder.
-            };
-            this.pc.ondatachannel =(data)=>{
-                console.log('data',data)
-            }
-            this.pc.onaddstream = function (obj) {
-                console.error(obj)
-            }
+  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();
+    await this.pc.setLocalDescription(offer);
+    const session = await new Promise(function (resolve, reject) {
+      // @see https://github.com/rtcdn/rtcdn-draft
+      var data = {
+        api: serverApi,
+        tid: tid,
+        streamurl: clipUrl,
+        clientip: null,
+        sdp: offer.sdp,
+      };
+      console.log("Generated offer: ", data);
+      $.ajax({
+        type: "POST",
+        url: serverApi,
+        data: JSON.stringify(data),
+        contentType: "application/json",
+        dataType: "json",
+      })
+        .done(function (data) {
+          console.log("Got answer: ", data);
+          if (data.code) {
+            reject(data);
+            return;
+          }
 
+          resolve(data);
+        })
+        .fail(function (reason) {
+          reject(reason);
+        });
+    });
+    await this.pc.setRemoteDescription(
+      new RTCSessionDescription({ type: "answer", sdp: session.sdp })
+    );
+  }
+
+  async getVideo(clipUrl) {
+    if (!this.pc) {
+      this.pc = new RTCPeerConnection(null);
+      this.pc.ontrack = (event) => {
+        // https://webrtc.org/getting-started/remote-streams
+        console.log("event", event);
+        if (this.stream) {
+          // this.stream.removeTrack(event.track));
+          const videoTrack = this.stream
+            .getVideoTracks()
+            .find((i) => i.kind === "video");
+          console.log("旧videoTrack", videoTrack);
+          if (videoTrack) {
+            this.stream.removeTrack(videoTrack);
+          }
+          // if(this.stream.removeTrack())
+          this.stream.addTrack(event.track);
         }
-     
-        this.pc.addTransceiver("video", {direction: "recvonly"});
+        //    mediaRecorder.
+      };
+
+      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);
+        };
+      };
+    }
 
-        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
-            var data = {
-                api: serverApi,
-                tid: tid,
-                streamurl: clipUrl,
-                clientip: null, 
-                sdp: offer.sdp
-            };
-            console.log("Generated offer: ", data);
-            $.ajax({
-                type: "POST", url: serverApi, data: JSON.stringify(data),
-                contentType:'application/json', dataType: 'json'
-            }).done(function(data) {
-                console.log("Got answer: ", data);
-                if (data.code) {
-                    reject(data); return;
-                }
+    this.pc.addTransceiver("video", { direction: "recvonly" });
 
-                resolve(data);
-            }).fail(function(reason){
-                reject(reason);
-            });
+    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
+      var data = {
+        api: serverApi,
+        tid: tid,
+        streamurl: clipUrl,
+        clientip: null,
+        sdp: offer.sdp,
+      };
+      console.log("Generated offer: ", data);
+      $.ajax({
+        type: "POST",
+        url: serverApi,
+        data: JSON.stringify(data),
+        contentType: "application/json",
+        dataType: "json",
+      })
+        .done(function (data) {
+          console.log("Got answer: ", data);
+          if (data.code) {
+            reject(data);
+            return;
+          }
+
+          resolve(data);
+        })
+        .fail(function (reason) {
+          reject(reason);
         });
-        await this.pc.setRemoteDescription(
-            new RTCSessionDescription({type: 'answer', sdp: session.sdp})
-        );
-        
-    
-        return session;
-        
-    }
-}
+    });
+    await this.pc.setRemoteDescription(
+      new RTCSessionDescription({ type: "answer", sdp: session.sdp })
+    );
+
+    return session;
+  }
+}