Skip to content

Commit

Permalink
use EnhancedEventEmitter rather than EventEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed May 17, 2024
1 parent 8c4bc93 commit 95b8225
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions node/workerChannel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter } from 'events';
import { EnhancedEventEmitter } from '../../src/enhancedEvents';

const buildType = process.env.MEDIASOUP_BUILDTYPE ?? 'Release';

Expand All @@ -7,7 +8,12 @@ const { WorkerChannel: NativeWorkerChannel } = require(
`../build/${buildType}/worker-channel.node`
);

export class WorkerChannel extends EventEmitter {
export type WorkerChannelEvents = {
data: [Uint8Array];
error: [number];
};

export class WorkerChannel extends EnhancedEventEmitter<WorkerChannelEvents> {
private emitter: EventEmitter;
private workerChannel: typeof NativeWorkerChannel;

Expand All @@ -22,11 +28,11 @@ export class WorkerChannel extends EventEmitter {
);

this.emitter.on('data', data => {
this.emit('data', data);
this.safeEmit('data', data);
});

this.emitter.on('error', code => {
this.emit('error', code);
this.safeEmit('error', code);
});
}

Expand Down

0 comments on commit 95b8225

Please sign in to comment.