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