summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/sharedarraybuffer-processor.js
blob: 2ccacccd4bb0a4d289ddccd9cafa4e29a0484730 (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
/**
 * @class SharedArrayBufferProcessor
 * @extends AudioWorkletProcessor
 *
 * This processor class demonstrates passing SharedArrayBuffers to and from
 * workers.
 */
class SharedArrayBufferProcessor extends AudioWorkletProcessor {
  constructor() {
    super();
    this.port.onmessage = this.handleMessage.bind(this);
    this.port.onmessageerror = this.handleMessageError.bind(this);
    let sab = new SharedArrayBuffer(8);
    this.port.postMessage({state: 'created', sab});
  }

  handleMessage(event) {
    this.port.postMessage({
      state: 'received message',
      isSab: event.data instanceof SharedArrayBuffer
    });
  }

  handleMessageError(event) {
    this.port.postMessage({
      state: 'received messageerror'
    });
  }

  process() {
    return true;
  }
}

registerProcessor('sharedarraybuffer-processor', SharedArrayBufferProcessor);