-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathframecount.js
More file actions
121 lines (110 loc) · 4.02 KB
/
framecount.js
File metadata and controls
121 lines (110 loc) · 4.02 KB
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
/* Interop testing using apprtc.appspot.com using selenium
* Copyright (c) 2016, Philipp Hancke
*/
const test = require('tape');
const fs = require('fs');
const webdriver = require('selenium-webdriver');
const buildDriver = require('./webdriver').buildDriver;
const TIMEOUT = 30000;
// in apprtc this step is moot since it creates the PC
// even if there is no other client.
function waitNPeerConnectionsExist(driver) {
return driver.wait(() => driver.executeScript(
() => appController && appController.call_ && appController.call_.pcClient_ && appController.call_.pcClient_.pc_
), TIMEOUT);
}
function waitAllPeerConnectionsConnected(driver) {
return driver.wait(() => driver.executeScript(() => {
var state = appController.call_.pcClient_.pc_.iceConnectionState;
return state === 'connected' || state === 'completed';
}), TIMEOUT);
}
// moot since apprtc always used three videos
function waitNVideosExist(driver) {
return driver.wait(() => driver.executeScript(() => document.querySelectorAll('video').length === 3, n), TIMEOUT);
}
// apprtc uses remote-video
function waitAllVideosHaveEnoughData(driver) {
return driver.wait(() => driver.executeScript(() => {
var video = document.querySelector('#remote-video');
return video.readyState >= video.HAVE_ENOUGH_DATA;
}), TIMEOUT);
}
function countFrames(driver, interval_, numberOfSamples_) {
return driver.executeAsyncScript(function(interval, numberOfSamples) {
const callback = arguments[arguments.length - 1];
const samples = [];
const remoteVideo = document.querySelector('#remote-video');
const intervalId = setInterval(() => {
samples.push([Date.now(), remoteVideo.webkitDecodedFrameCount || remoteVideo.mozPaintedFrames]);
if (samples.length === numberOfSamples) {
clearInterval(intervalId);
callback(samples);
}
}, interval);
}, interval_, numberOfSamples_);
}
// Edge Webdriver resolves quit slightly too early, wait a bit.
function maybeWaitForEdge(browserA, browserB) {
if (browserA === 'MicrosoftEdge' || browserB === 'MicrosoftEdge') {
return new Promise(resolve => {
setTimeout(resolve, 2000);
});
}
return Promise.resolve();
}
function frameCount(t, browserA, browserB, queryString) {
var driverA = buildDriver(browserA, {h264: true});
var driverB;
var baseURL = 'https://appr.tc/';
return driverA.get(baseURL + (queryString || ''))
.then(() => {
t.pass('page loaded');
return driverA.findElement(webdriver.By.id('join-button')).click();
})
.then(() => // wait for URL to change to /r/some-id
driverA.wait(() => driverA.getCurrentUrl()
.then(url => url.indexOf(baseURL + 'r/') === 0), 10000, 'Did not join room for 10s'))
.then(() => {
t.pass('joined room');
return driverA.getCurrentUrl();
})
.then(url => {
//
driverB = buildDriver(browserB, {h264: true});
return driverB.get(url);
})
.then(() => driverB.findElement(webdriver.By.id('confirm-join-button')).click())
.then(() => {
t.pass('second browser joined');
// Show the info box.
//return driverA.executeScript('appController.infoBox_.showInfoDiv();');
})
.then(() => waitNPeerConnectionsExist(driverA))
.then(() => waitNPeerConnectionsExist(driverB))
.then(() => waitAllPeerConnectionsConnected(driverA))
.then(() => waitAllPeerConnectionsConnected(driverB))
.then(() => {
t.pass('videos exist');
return waitAllVideosHaveEnoughData(driverA);
})
.then(() => {
t.pass('videos exist');
return waitAllVideosHaveEnoughData(driverB);
})
.then(() => {
t.pass('videos are in HAVE_ENOUGH_DATA state');
})
.then(() => countFrames(driverA, 500, 10)
.then(samples => {
console.log('counted frames', samples);
}))
.then(() => Promise.all([driverA.quit(), driverB.quit()]))
.then(() => maybeWaitForEdge(browserA, browserB))
.then(() => {
t.end();
});
}
test('Chrome-Chrome', t => {
frameCount(t, 'chrome', 'chrome')
});