RTCPeerConnection-remote-track-mute.https.html (5625B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <meta name="timeout" content="long"> 4 <title>RTCPeerConnection-transceivers.https.html</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="RTCPeerConnection-helper.js"></script> 8 <script> 9 'use strict'; 10 11 async function waitForTimeout(t, timeout_ms = 5000) { 12 return new Promise(r => t.step_timeout(r, timeout_ms)); 13 } 14 15 // The following helper functions are called from RTCPeerConnection-helper.js: 16 // exchangeOffer 17 // exchangeOfferAndListenToOntrack 18 // exchangeAnswer 19 // exchangeAnswerAndListenToOntrack 20 // addEventListenerPromise 21 // createPeerConnectionWithCleanup 22 // createTrackAndStreamWithCleanup 23 // findTransceiverForSender 24 25 promise_test(async t => { 26 const pc1 = createPeerConnectionWithCleanup(t); 27 pc1.addTrack(... await createTrackAndStreamWithCleanup(t)); 28 const pc2 = createPeerConnectionWithCleanup(t); 29 exchangeIceCandidates(pc1, pc2); 30 31 let muteWatcher; 32 let unmutePromise; 33 // The unmuting it timing sensitive so we hook up to the event directly 34 // instead of wrapping it in an EventWatcher which uses promises. 35 pc2.ontrack = t.step_func(e => { 36 assert_true(e.track.muted, 'track is muted in ontrack'); 37 muteWatcher = new EventWatcher(t, e.track, ['unmute'], 38 () => waitForTimeout(t)); 39 unmutePromise = muteWatcher.wait_for('unmute'); 40 pc2.ontrack = t.step_func(e => { 41 assert_unreached('ontrack fired unexpectedly'); 42 }); 43 }); 44 await exchangeOfferAnswer(pc1, pc2); 45 await unmutePromise; 46 }, 'ontrack: track goes from muted to unmuted'); 47 48 promise_test(async t => { 49 const pc1 = createPeerConnectionWithCleanup(t); 50 const pc1Sender = pc1.addTrack(... await createTrackAndStreamWithCleanup(t)); 51 const localTransceiver = findTransceiverForSender(pc1, pc1Sender); 52 const pc2 = createPeerConnectionWithCleanup(t); 53 exchangeIceCandidates(pc1, pc2); 54 55 let muteWatcher; 56 let unmutePromise; 57 pc2.ontrack = t.step_func(e => { 58 muteWatcher = new EventWatcher(t, e.track, ['mute', 'unmute'], 59 () => waitForTimeout(t)); 60 unmutePromise = muteWatcher.wait_for('unmute'); 61 }); 62 await exchangeOfferAnswer(pc1, pc2); 63 // Need to wait for the initial unmute event before renegotiating, otherwise 64 // there will be no transition from unmuted->muted. 65 await unmutePromise; 66 67 const mutePromise = muteWatcher.wait_for('mute'); 68 localTransceiver.direction = 'inactive'; 69 await exchangeOfferAnswer(pc1, pc2); 70 71 await mutePromise; 72 }, 'Changing transceiver direction to \'inactive\' mutes the remote track'); 73 74 promise_test(async t => { 75 const pc1 = createPeerConnectionWithCleanup(t); 76 const pc1Sender = pc1.addTrack(... await createTrackAndStreamWithCleanup(t)); 77 const localTransceiver = findTransceiverForSender(pc1, pc1Sender); 78 const pc2 = createPeerConnectionWithCleanup(t); 79 exchangeIceCandidates(pc1, pc2); 80 81 let muteWatcher; 82 let unmutePromise; 83 pc2.ontrack = t.step_func(e => { 84 muteWatcher = new EventWatcher(t, e.track, ['mute', 'unmute'], 85 () => waitForTimeout(t)); 86 unmutePromise = muteWatcher.wait_for('unmute'); 87 }); 88 await exchangeOfferAnswer(pc1, pc2); 89 await unmutePromise; 90 91 const mutePromise = muteWatcher.wait_for('mute'); 92 localTransceiver.direction = 'inactive'; 93 await exchangeOfferAnswer(pc1, pc2); 94 await mutePromise; 95 96 unmutePromise = muteWatcher.wait_for('unmute'); 97 localTransceiver.direction = 'sendrecv'; 98 await exchangeOfferAnswer(pc1, pc2); 99 100 await unmutePromise; 101 }, 'Changing transceiver direction to \'sendrecv\' unmutes the remote track'); 102 103 promise_test(async t => { 104 const pc1 = createPeerConnectionWithCleanup(t); 105 const pc1Sender = pc1.addTrack(... await createTrackAndStreamWithCleanup(t)); 106 const localTransceiver = findTransceiverForSender(pc1, pc1Sender); 107 const pc2 = createPeerConnectionWithCleanup(t); 108 exchangeIceCandidates(pc1, pc2); 109 110 let muteWatcher; 111 let unmutePromise; 112 pc2.ontrack = t.step_func(e => { 113 muteWatcher = new EventWatcher(t, e.track, ['mute', 'unmute'], 114 () => waitForTimeout(t)); 115 unmutePromise = muteWatcher.wait_for('unmute'); 116 }); 117 await exchangeOfferAnswer(pc1, pc2); 118 // Need to wait for the initial unmute event before closing, otherwise 119 // there will be no transition from unmuted->muted. 120 await unmutePromise; 121 122 // This will send an RTCP BYE which causes the remote side to mute. 123 const mutePromise = muteWatcher.wait_for('mute'); 124 localTransceiver.stop(); 125 await mutePromise; 126 }, 'transceiver.stop() on one side (without renegotiation) causes mute events on the other'); 127 128 promise_test(async t => { 129 const pc1 = createPeerConnectionWithCleanup(t); 130 const pc1Sender = pc1.addTrack(...await createTrackAndStreamWithCleanup(t)); 131 const localTransceiver = findTransceiverForSender(pc1, pc1Sender); 132 const pc2 = createPeerConnectionWithCleanup(t); 133 exchangeIceCandidates(pc1, pc2); 134 135 let muteWatcher; 136 let unmutePromise; 137 pc2.ontrack = t.step_func(e => { 138 muteWatcher = new EventWatcher(t, e.track, ['mute', 'unmute'], 139 () => waitForTimeout(t)); 140 unmutePromise = muteWatcher.wait_for('unmute'); 141 }); 142 await exchangeOfferAnswer(pc1, pc2); 143 // Need to wait for the initial unmute event before closing, otherwise 144 // there will be no transition from unmuted->muted. 145 await unmutePromise; 146 147 const mutePromise = muteWatcher.wait_for('mute'); 148 pc1.close(); 149 await mutePromise; 150 }, 'pc.close() on one side causes mute events on the other'); 151 </script>