Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support streams of only video/audio tracks #61

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapters/WHEPAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
return this.localPeer;
}

async connect(opts?: AdapterConnectOptions) {

Check warning on line 60 in src/adapters/WHEPAdapter.ts

View workflow job for this annotation

GitHub Actions / lint

'opts' is defined but never used
try {
await this.initSdpExchange();
} catch (error) {
Expand Down Expand Up @@ -94,7 +94,7 @@
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
Loading