blob: 87a4500d754ab02465e109899e7f1ffdc0bdca53 (
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, {transfer: [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);
});
|