blob: d35c1c952b880069eafe25aa971d8aa7c9293e05 (
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
|
var messageHandler = function(port, e) {
var text_decoder = new TextDecoder;
port.postMessage({
content: text_decoder.decode(e.data),
byteLength: e.data.byteLength
});
// Send back the array buffer via Client.postMessage.
port.postMessage(e.data, [e.data.buffer]);
port.postMessage({
content: text_decoder.decode(e.data),
byteLength: e.data.byteLength
});
};
self.addEventListener('message', e => {
if (e.ports[0]) {
// Wait for messages sent via MessagePort.
e.ports[0].onmessage = messageHandler.bind(null, e.ports[0]);
return;
}
messageHandler(e.source, e);
});
|