summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/port-processor.js
blob: 8def5a61d7e4f130d6e2d41407c016e769ea9132 (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
/**
 * @class PortProcessor
 * @extends AudioWorkletProcessor
 *
 * This processor class demonstrates the message port functionality.
 */
class PortProcessor extends AudioWorkletProcessor {
  constructor() {
    super();
    this.port.onmessage = this.handleMessage.bind(this);
    this.port.postMessage({
      state: 'created',
      timeStamp: currentTime,
      currentFrame: currentFrame
    });
    this.processCallCount = 0;
  }

  handleMessage(event) {
    this.port.postMessage({
      message: event.data,
      timeStamp: currentTime,
      currentFrame: currentFrame,
      processCallCount: this.processCallCount
    });
  }

  process() {
    ++this.processCallCount;
    return true;
  }
}

registerProcessor('port-processor', PortProcessor);