blob: bb2dc81e553f3b271d3bb20efc12c9ff2da102a1 (
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
|
let port;
let received = false;
function reportFailure(details) {
port.postMessage('FAIL: ' + details);
}
onmessage = event => {
port = event.source;
const ws = new WebSocket('wss://{{host}}:{{ports[wss][0]}}/echo');
ws.onopen = () => {
ws.send('Hello');
};
ws.onmessage = msg => {
if (msg.data !== 'Hello') {
reportFailure('Unexpected reply: ' + msg.data);
return;
}
received = true;
ws.close();
};
ws.onclose = (event) => {
if (!received) {
reportFailure('Closed before receiving reply: ' + event.code);
return;
}
port.postMessage('PASS');
};
ws.onerror = () => {
reportFailure('Got an error event');
};
};
|