Skip to content

Commit

Permalink
fix: support streams of only video/audio tracks (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wkkkkk committed Sep 19, 2023
1 parent c15f5c0 commit 4b80d3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/adapters/WHEPAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class WHEPAdapter implements Adapter {
if (opusCodecId !== null) {
offer.sdp = offer.sdp.replace(
'opus/48000/2\r\n',
'opus/48000/2\r\na=rtcp-fb:" + opusCodecId[1] + " nack\r\n'
'opus/48000/2\r\na=rtcp-fb:' + opusCodecId[1] + ' nack\r\n'
);
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class WebRTCPlayer extends EventEmitter {

private onTrack(event: RTCTrackEvent) {
for (const stream of event.streams) {
if (stream.id === 'feedbackvideomslabel' || this.videoElement.srcObject) {
if (stream.id === 'feedbackvideomslabel') {
continue;
}

Expand All @@ -207,7 +207,16 @@ export class WebRTCPlayer extends EventEmitter {
' video ' +
stream.getVideoTracks().length
);
this.videoElement.srcObject = stream;

// Create a new MediaStream if we don't have one
if (!this.videoElement.srcObject) {
this.videoElement.srcObject = new MediaStream();
}

// We might have one stream of both audio and video, or separate streams for audio and video
for (const track of stream.getTracks()) {
(this.videoElement.srcObject as MediaStream).addTrack(track);
}
}
}

Expand Down

0 comments on commit 4b80d3c

Please sign in to comment.