summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_audioSynchronizationSourcesUnidirectional.html
blob: 6d66614e91b9b55af44c39c232febf4cc913db3b (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
54
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1439001",
    title: "Test audio unidirectional getSynchronizationSources"
  });

  var waitForSyncSources = async (test) => {
    let receiver = test.pcRemote.getReceivers()[0];
    ok(receiver, "Remote has a receiver");
    // Wait for remote sync source
    while (!receiver.getSynchronizationSources().length) {
      await wait(250);
    }
    is(receiver.getSynchronizationSources().length, 1,
       "Remote receiver has a synchronization source");
    // Make sure local has no sync source
    is(test.pcLocal.getReceivers()[0].getSynchronizationSources().length, 0,
       "Local receiver has no synchronization source");
  };
  /*
   * Test to make sure that in unidirectional calls, the receiving end has
   * synchronization sources with audio levels, and the sending end has none.
   */
  var testGetSynchronizationSourcesUnidirectional = async (test) => {
    await waitForSyncSources(test);
    let receiver = test.pcRemote.getReceivers()[0];
    let syncSources = receiver.getSynchronizationSources();
    ok(syncSources.length,
       "Receiver has Synchronization sources " + JSON.stringify(syncSources));
    is(syncSources.length, 1, "Receiver has only a single sync source");
    let syncSource = syncSources[0];
    ok(syncSource.audioLevel !== undefined, "SynchronizationSource has audioLevel");
  };

  var test;
  runNetworkTest(function(options) {
    test = new PeerConnectionTest(options);
    test.chain.insertAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW",
      [testGetSynchronizationSourcesUnidirectional]);
    test.setMediaConstraints([{audio: true}], []);
    test.pcLocal.audioElementsOnly = true;
    return test.run();
  });
</script>
</pre>
</body>
</html>