Skip to content

Commit

Permalink
feat: events object on local-track class (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccarthytyler authored and GitHub Enterprise committed Aug 25, 2021
1 parent d0510f8 commit 53b4068
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/local-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { Track } from './track';
* A wrapper around MediaStreamTrack.
*/
export class LocalTrack extends Track {
static Events = {
TrackUpdate: 'track-update',
};

/**
* Exchange the underlying track with a new track. Emit the `track-update` event to alert
* listeners to an update on a new track.
Expand All @@ -12,7 +16,7 @@ export class LocalTrack extends Track {
* @fires LocalTrack#track-update
*/
replaceUnderlyingTrack(track: MediaStreamTrack): void {
this.emit('track-update', this.getUnderlyingTrack().id, track);
this.emit(LocalTrack.Events.TrackUpdate, this.getUnderlyingTrack().id, track);
this.getUnderlyingTrack().stop();
this.setUnderlyingTrack(track);
}
Expand Down
2 changes: 1 addition & 1 deletion src/peer-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PeerConnection {
* @listens LocalTrack#track-update
*/
addTrack(track: LocalTrack, ...streams: MediaStream[]): RTCRtpSender {
track.on('track-update', this.handleTrackUpdate);
track.on(LocalTrack.Events.TrackUpdate, this.handleTrackUpdate);
return this.pc.addTrack(track.getUnderlyingTrack(), ...streams);
}

Expand Down

0 comments on commit 53b4068

Please sign in to comment.