summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc-extensions/transfer-datachannel-service-worker.js
blob: c1919d0b9a7b1c1ef991cfd6018a8268e271eb1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let channel;
let port;
onmessage = (e) => {
    if (e.data.port) {
        port = e.data.port;
        port.onmessage = (event) => channel.send(event.data.message);
    }
    if (e.data.channel) {
        channel = e.data.channel;
        channel.onopen = () => port.postMessage("opened");
        channel.onerror = () => port.postMessage("errored");
        channel.onclose = () => port.postMessage("closed");
        channel.onmessage = (event) => port.postMessage(event.data);
    }
};