summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_replaceNullTrackThenRenegotiateAudio.html
blob: 2253b8767296c04a00904cf712dbe4d6253f3fa5 (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1763832",
    title: "Renegotiation (audio): Start with no track and recvonly, then replace and set direction to sendrecv, then renegotiate"
  });

  runNetworkTest(async () => {
    await pushPrefs(
      ['media.audio_loopback_dev', ''],
      ['media.navigator.streams.fake', true]);
    const offerer = new RTCPeerConnection();
    const answerer = new RTCPeerConnection();
    const transceiverSend = offerer.addTransceiver('audio', {direction: 'recvonly'});

    const add = (pc, can, failed) => can && pc.addIceCandidate(can).catch(failed);
    offerer.onicecandidate = e => add(answerer, e.candidate, generateErrorCallback());
    answerer.onicecandidate = e => add(offerer, e.candidate, generateErrorCallback());

    await offerer.setLocalDescription();
    await answerer.setRemoteDescription(offerer.localDescription);
    await answerer.setLocalDescription();
    await offerer.setRemoteDescription(answerer.localDescription);

    // add audio with replaceTrack, set send bit, and renegotiate
    const stream = await navigator.mediaDevices.getUserMedia({audio: true});
    const [track] = stream.getAudioTracks();
    transceiverSend.sender.replaceTrack(track);
    transceiverSend.direction = "sendrecv";
    const remoteStreamAvailable = new Promise(r => {
      answerer.ontrack = ({track}) => r(new MediaStream([track]));
    });

    await offerer.setLocalDescription();
    await answerer.setRemoteDescription(offerer.localDescription);
    await answerer.setLocalDescription();
    await offerer.setRemoteDescription(answerer.localDescription);

    const remoteStream = await remoteStreamAvailable;
    const h = new AudioStreamHelper();
    await h.checkAudioFlowing(remoteStream);
  });

</script>
</pre>
</body>
</html>