pc-video-size1.html (1765B)
1 <html class="reftest-wait"> 2 <script> 3 document.addEventListener("DOMContentLoaded", async () => { 4 SpecialPowers.wrap(document).notifyUserGestureActivation(); 5 let stream; 6 try { 7 stream = await navigator.mediaDevices.getDisplayMedia({ 8 video: { 9 resizeMode: "crop-and-scale", 10 width: 1, 11 height: 1, 12 }, 13 }); 14 const localVideo = document.createElement("video"); 15 document.body.appendChild(localVideo); 16 localVideo.srcObject = stream; 17 localVideo.style = "width:320px;height:240px;background-color:#000;"; 18 localVideo.play(); 19 20 const pc1 = new RTCPeerConnection(); 21 const pc2 = new RTCPeerConnection(); 22 for (const track of stream.getTracks()) { 23 pc1.addTrack(track); 24 } 25 pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate); 26 pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate); 27 const trackPromise = new Promise(r => pc2.ontrack = r); 28 await pc1.setLocalDescription(); 29 await pc2.setRemoteDescription(pc1.localDescription); 30 await pc2.setLocalDescription(); 31 await pc1.setRemoteDescription(pc2.localDescription); 32 const {track: remoteTrack} = await trackPromise; 33 const remoteVideo = document.createElement("video"); 34 document.body.appendChild(remoteVideo); 35 remoteVideo.srcObject = new MediaStream([remoteTrack]); 36 remoteVideo.style = "width:320px;height:240px;background-color:#AAA;"; 37 remoteVideo.play(); 38 await new Promise(r => remoteVideo.onloadeddata = r); 39 } catch(e) { 40 dump(`##### ERROR ${e.name}: ${e.message}\n${e.stack}\n`); 41 } finally { 42 if (stream) { 43 for (const track of stream.getTracks()) { 44 track.stop(); 45 } 46 } 47 document.documentElement.removeAttribute("class"); 48 } 49 }); 50 </script> 51 </html>