RTCRtpTransceiver-direction.html (3232B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCRtpTransceiver.prototype.direction</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="RTCPeerConnection-helper.js"></script> 7 <script> 8 'use strict'; 9 10 // Test is based on the following editor draft: 11 // https://rawgit.com/w3c/webrtc-pc/8495678808d126d8bc764bf944996f32981fa6fd/webrtc.html 12 13 // The following helper functions are called from RTCPeerConnection-helper.js: 14 // generateAnswer 15 16 /* 17 5.4. RTCRtpTransceiver Interface 18 interface RTCRtpTransceiver { 19 attribute RTCRtpTransceiverDirection direction; 20 readonly attribute RTCRtpTransceiverDirection? currentDirection; 21 ... 22 }; 23 */ 24 25 /* 26 5.4. direction 27 7. Set transceiver's [[Direction]] slot to newDirection. 28 */ 29 test(t => { 30 const pc = new RTCPeerConnection(); 31 const transceiver = pc.addTransceiver('audio'); 32 assert_equals(transceiver.direction, 'sendrecv'); 33 assert_equals(transceiver.currentDirection, null); 34 35 transceiver.direction = 'recvonly'; 36 assert_equals(transceiver.direction, 'recvonly'); 37 assert_equals(transceiver.currentDirection, null, 38 'Expect transceiver.currentDirection to not change'); 39 40 }, 'setting direction should change transceiver.direction'); 41 42 /* 43 5.4. direction 44 3. If newDirection is equal to transceiver's [[Direction]] slot, abort 45 these steps. 46 */ 47 test(t => { 48 const pc = new RTCPeerConnection(); 49 const transceiver = pc.addTransceiver('audio', { direction: 'sendonly' }); 50 assert_equals(transceiver.direction, 'sendonly'); 51 transceiver.direction = 'sendonly'; 52 assert_equals(transceiver.direction, 'sendonly'); 53 54 }, 'setting direction with same direction should have no effect'); 55 56 promise_test(t => { 57 const pc = new RTCPeerConnection(); 58 t.add_cleanup(() => pc.close()); 59 const transceiver = pc.addTransceiver('audio', { direction: 'recvonly' }); 60 assert_equals(transceiver.direction, 'recvonly'); 61 assert_equals(transceiver.currentDirection, null); 62 63 return pc.createOffer() 64 .then(offer => 65 pc.setLocalDescription(offer) 66 .then(() => generateAnswer(offer))) 67 .then(answer => pc.setRemoteDescription(answer)) 68 .then(() => { 69 assert_equals(transceiver.currentDirection, 'inactive'); 70 transceiver.direction = 'sendrecv'; 71 assert_equals(transceiver.direction, 'sendrecv'); 72 assert_equals(transceiver.currentDirection, 'inactive'); 73 }); 74 }, 'setting direction should change transceiver.direction independent of transceiver.currentDirection'); 75 76 /* 77 TODO 78 An update of directionality does not take effect immediately. Instead, future calls 79 to createOffer and createAnswer mark the corresponding media description as 80 sendrecv, sendonly, recvonly or inactive as defined in [JSEP] (section 5.2.2. 81 and section 5.3.2.). 82 83 Tested in RTCPeerConnection-onnegotiationneeded.html 84 5.4. direction 85 6. Update the negotiation-needed flag for connection. 86 87 Coverage Report 88 Tested 6 89 Not Tested 1 90 Untestable 0 91 Total 7 92 */ 93 94 </script>