forked from cta-wave/dpctf-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.html
executable file
·110 lines (99 loc) · 3.25 KB
/
events.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<video style="height: 400px;"></video>
<div id="debug"></div>
<div id="log"></div>
<div id="info-overlay"></div>
<script src="lib/mozilla/object-keys-polyfill.js"></script>
<script src="lib/stefanpenner/es6-promise.min.js"></script>
<script src="lib/utils/test_helper.js"></script>
<script src="lib/player.js"></script>
<script src="lib/manifest_parser.js"></script>
<script src="lib/mpd-parser.js"></script>
<script src="lib/info-overlay.js"></script>
<script src="lib/wave-service.js"></script>
<script>
// Global variables
var waveService = null;
var currentListener = null;
var currentToken = null;
var receivedTestPath = null;
var receivedObservations = null;
// Specify workflow
initializeWaveService().then(notifyInitialization).then(handleError);
function listen(token) {
if (currentListener) {
waveService.removeSessionEventListener(currentListener);
}
currentListener = function (event) {
console.log("");
console.log("Event received:");
console.log("Type:", event.type);
console.log("Data:", JSON.stringify(event.data, null, 2));
if (event.type === WaveService.TEST_READY_EVENT) {
receivedTestPath = event.data.path;
receivedObservations = event.data.observations;
}
};
waveService.addSessionEventListener(token, currentListener);
currentToken = token;
console.log(
"Successfully registered event listener for session '" + token + "'"
);
}
function sendObservationReadyEvent() {
sendEvent(WaveService.OBSERVATION_READY_EVENT, {
test_path: receivedTestPath,
});
}
function sendObservationResults() {
var results = [];
for (var observation of receivedObservations) {
results.push({
id: observation.id,
name: observation.name,
status: "PASS",
message: null,
});
}
sendEvent(WaveService.OBSERVATION_COMPLETED_EVENT, results);
}
function sendEvent(type, data) {
waveService
.sendSessionEvent(currentToken, type, data)
.then(function (error) {
if (error) {
console.log("Failed to send event:", error);
return;
}
console.log("Event successfully sent");
});
}
function handleError(error) {
if (!error) return;
throw new Error(error);
}
function initializeWaveService(error) {
if (error) return error;
return new Promise(function (resolve) {
waveService = new WaveService();
waveService
.initialize("resources/wave-config")
.then(function (error) {
if (error) resolve("Failed to initialize wave service: " + error);
resolve();
});
});
}
function notifyInitialization(error) {
if (error) return error;
console.log("Wave Service successfully initialized.");
}
</script>
</body>
</html>