msid-generate.html (6367B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCPeerconnection MSID generation</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="../RTCPeerConnection-helper.js"></script> 7 <script src="../third_party/sdp/sdp.js"></script> 8 <script> 9 10 function msidLines(desc) { 11 const sections = SDPUtils.splitSections(desc.sdp); 12 return SDPUtils.matchPrefix(sections[1], 'a=msid:'); 13 } 14 15 promise_test(async t => { 16 const pc = new RTCPeerConnection(); 17 t.add_cleanup(() => pc.close()); 18 const dc = pc.createDataChannel('foo'); 19 const desc = await pc.createOffer(); 20 assert_equals(msidLines(desc).length, 0); 21 }, 'No media track produces no MSID'); 22 23 promise_test(async t => { 24 const pc = new RTCPeerConnection(); 25 t.add_cleanup(() => pc.close()); 26 const stream1 = await getNoiseStream({audio: true}); 27 pc.addTrack(stream1.getTracks()[0]); 28 const desc = await pc.createOffer(); 29 const msid_lines = msidLines(desc); 30 assert_equals(msid_lines.length, 1); 31 assert_regexp_match(msid_lines[0], /^a=msid:-/); 32 }, 'AddTrack without a stream produces MSID with no stream ID'); 33 34 // token-char from RFC 4566 35 // This is printable characters except whitespace, and ["(),/:;<=>?@[\]] 36 const token_char = '\\x21\\x23-\\x27\\x2A-\\x2B\\x2D-\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7E'; 37 38 // msid-value from RFC 8830 39 const msid_attr = RegExp(`^a=msid:[${token_char}]{1,64}( [${token_char}]{1,64})?$`); 40 41 promise_test(async t => { 42 const pc = new RTCPeerConnection(); 43 t.add_cleanup(() => pc.close()); 44 const stream1 = await getNoiseStream({audio: true}); 45 pc.addTrack(stream1.getTracks()[0], stream1); 46 const desc = await pc.createOffer(); 47 const msid_lines = msidLines(desc); 48 assert_equals(msid_lines.length, 1); 49 assert_regexp_match(msid_lines[0], msid_attr); 50 }, 'AddTrack with a stream produces MSID with a stream ID'); 51 52 promise_test(async t => { 53 const pc = new RTCPeerConnection(); 54 t.add_cleanup(() => pc.close()); 55 const stream1 = await getNoiseStream({audio: true}); 56 const stream2 = new MediaStream(stream1.getTracks()); 57 pc.addTrack(stream1.getTracks()[0], stream1, stream2); 58 const desc = await pc.createOffer(); 59 const msid_lines = msidLines(desc); 60 assert_equals(msid_lines.length, 2); 61 assert_regexp_match(msid_lines[0], msid_attr); 62 assert_regexp_match(msid_lines[1], msid_attr); 63 }, 'AddTrack with two streams produces two MSID lines'); 64 65 promise_test(async t => { 66 const pc = new RTCPeerConnection(); 67 t.add_cleanup(() => pc.close()); 68 const stream1 = await getNoiseStream({audio: true}); 69 pc.addTrack(stream1.getTracks()[0], stream1, stream1); 70 const desc = await pc.createOffer(); 71 const msid_lines = msidLines(desc); 72 assert_equals(msid_lines.length, 1); 73 assert_regexp_match(msid_lines[0], msid_attr); 74 }, 'AddTrack with the stream twice produces single MSID with a stream ID'); 75 76 promise_test(async t => { 77 const pc = new RTCPeerConnection(); 78 t.add_cleanup(() => pc.close()); 79 const stream1 = await getNoiseStream({audio: true}); 80 pc.addTransceiver(stream1.getTracks()[0]); 81 const desc = await pc.createOffer(); 82 const msid_lines = msidLines(desc); 83 assert_equals(msid_lines.length, 1); 84 assert_regexp_match(msid_lines[0], /^a=msid:-/); 85 }, 'AddTransceiver without a stream produces MSID with no stream ID'); 86 87 promise_test(async t => { 88 const pc = new RTCPeerConnection(); 89 t.add_cleanup(() => pc.close()); 90 const stream1 = await getNoiseStream({audio: true}); 91 pc.addTransceiver(stream1.getTracks()[0], {streams: [stream1]}); 92 const desc = await pc.createOffer(); 93 const msid_lines = msidLines(desc); 94 assert_equals(msid_lines.length, 1); 95 assert_regexp_match(msid_lines[0], msid_attr); 96 }, 'AddTransceiver with a stream produces MSID with a stream ID'); 97 98 promise_test(async t => { 99 const pc = new RTCPeerConnection(); 100 t.add_cleanup(() => pc.close()); 101 const stream1 = await getNoiseStream({audio: true}); 102 const stream2 = new MediaStream(stream1.getTracks()); 103 pc.addTransceiver(stream1.getTracks()[0], {streams: [stream1, stream2]}); 104 const desc = await pc.createOffer(); 105 const msid_lines = msidLines(desc); 106 assert_equals(msid_lines.length, 2); 107 assert_regexp_match(msid_lines[0], msid_attr); 108 assert_regexp_match(msid_lines[1], msid_attr); 109 }, 'AddTransceiver with two streams produces two MSID lines'); 110 111 promise_test(async t => { 112 const pc = new RTCPeerConnection(); 113 t.add_cleanup(() => pc.close()); 114 const stream1 = await getNoiseStream({audio: true}); 115 pc.addTransceiver(stream1.getTracks()[0], {streams: [stream1, stream1]}); 116 const desc = await pc.createOffer(); 117 const msid_lines = msidLines(desc); 118 assert_equals(msid_lines.length, 1); 119 assert_regexp_match(msid_lines[0], msid_attr); 120 }, 'AddTransceiver with the stream twice produces single MSID with a stream ID'); 121 122 promise_test(async t => { 123 const pc = new RTCPeerConnection(); 124 t.add_cleanup(() => pc.close()); 125 const stream1 = await getNoiseStream({audio: true}); 126 const {sender} = pc.addTransceiver(stream1.getTracks()[0]); 127 sender.setStreams(stream1); 128 const desc = await pc.createOffer(); 129 const msid_lines = msidLines(desc); 130 assert_equals(msid_lines.length, 1); 131 assert_regexp_match(msid_lines[0], msid_attr); 132 }, 'SetStreams with a stream produces MSID with a stream ID'); 133 134 promise_test(async t => { 135 const pc = new RTCPeerConnection(); 136 t.add_cleanup(() => pc.close()); 137 const stream1 = await getNoiseStream({audio: true}); 138 const stream2 = new MediaStream(stream1.getTracks()); 139 const {sender} = pc.addTransceiver(stream1.getTracks()[0]); 140 sender.setStreams(stream1, stream2); 141 const desc = await pc.createOffer(); 142 const msid_lines = msidLines(desc); 143 assert_equals(msid_lines.length, 2); 144 assert_regexp_match(msid_lines[0], msid_attr); 145 assert_regexp_match(msid_lines[1], msid_attr); 146 }, 'SetStreams with two streams produces two MSID lines'); 147 148 promise_test(async t => { 149 const pc = new RTCPeerConnection(); 150 t.add_cleanup(() => pc.close()); 151 const stream1 = await getNoiseStream({audio: true}); 152 const {sender} = pc.addTransceiver(stream1.getTracks()[0]); 153 sender.setStreams(stream1, stream1); 154 const desc = await pc.createOffer(); 155 const msid_lines = msidLines(desc); 156 assert_equals(msid_lines.length, 1); 157 assert_regexp_match(msid_lines[0], msid_attr); 158 }, 'SetStreams with the stream twice produces single MSID with a stream ID'); 159 160 </script>