Răsfoiți Sursa

fix streamer example black screen issue

fixes paullouisageneau/libdatachannel#858
Tom Atkinson 2 ani în urmă
părinte
comite
bedde2fc15
1 a modificat fișierele cu 5 adăugiri și 8 ștergeri
  1. 5 8
      examples/streamer/client.js

+ 5 - 8
examples/streamer/client.js

@@ -52,10 +52,9 @@ function createPeerConnection() {
     pc.ontrack = (evt) => {
         document.getElementById('media').style.display = 'block';
         const video = document.getElementById('video');
-        if (!video.srcObject) {
-          video.srcObject = evt.streams[0]; // The stream groups audio and video tracks
-          video.play();
-        }
+        // always overrite the last stream - you may want to do something more clever in practice
+        video.srcObject = evt.streams[0]; // The stream groups audio and video tracks
+        video.play();
     };
 
     // Receive data channel
@@ -175,10 +174,8 @@ function stop() {
     });
 
     // close peer connection
-    setTimeout(() => {
-        pc.close();
-        pc = null;
-    }, 500);
+    pc.close();
+    pc = null;
 }
 
 // Helper function to generate a random ID