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