handover-datachannel.html (2413B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCPeerConnection Handovers</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 promise_test(async t => { 11 const offerPc = new RTCPeerConnection(); 12 const answerPcFirst = new RTCPeerConnection(); 13 const answerPcSecond = new RTCPeerConnection(); 14 t.add_cleanup(() => { 15 offerPc.close(); 16 answerPcFirst.close(); 17 answerPcSecond.close(); 18 }); 19 const offerDatachannel1 = offerPc.createDataChannel('initial'); 20 exchangeIceCandidates(offerPc, answerPcFirst); 21 22 // Negotiate connection with PC 1 23 const offer1 = await offerPc.createOffer(); 24 await offerPc.setLocalDescription(offer1); 25 await answerPcFirst.setRemoteDescription(offer1); 26 const answer1 = await answerPcFirst.createAnswer(); 27 await offerPc.setRemoteDescription(answer1); 28 await answerPcFirst.setLocalDescription(answer1); 29 const datachannelAtAnswerPcFirst = await new Promise( 30 r => answerPcFirst.ondatachannel = ({channel}) => r(channel)); 31 const iceTransport = offerPc.sctp.transport; 32 // Check that messages get through. 33 datachannelAtAnswerPcFirst.send('hello'); 34 const message1 = await awaitMessage(offerDatachannel1); 35 assert_equals(message1, 'hello'); 36 37 // Renegotiate with PC 2 38 // Note - ICE candidates will also be sent to answerPc1, but that shouldn't matter. 39 exchangeIceCandidates(offerPc, answerPcSecond); 40 const offer2 = await offerPc.createOffer(); 41 await offerPc.setLocalDescription(offer2); 42 await answerPcSecond.setRemoteDescription(offer2); 43 const answer2 = await answerPcSecond.createAnswer(); 44 await offerPc.setRemoteDescription(answer2); 45 await answerPcSecond.setLocalDescription(answer2); 46 47 // Kill the first PC. This should not affect anything, but leaving it may cause untoward events. 48 answerPcFirst.close(); 49 50 const answerDataChannel2 = answerPcSecond.createDataChannel('second back'); 51 52 const datachannelAtOfferPcSecond = await new Promise(r => offerPc.ondatachannel = ({channel}) => r(channel)); 53 54 await new Promise(r => datachannelAtOfferPcSecond.onopen = r); 55 56 datachannelAtOfferPcSecond.send('hello again'); 57 const message2 = await awaitMessage(answerDataChannel2); 58 assert_equals(message2, 'hello again'); 59 }, 'Handover with datachannel reinitiated from new callee completes'); 60 61 </script>