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

Wrap addTrack in try/catch block #728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/lib/WazoSessionDescriptionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
SessionDescriptionHandler.dispatchRemoveTrackEvent(localStream, oldTrack);
}

localStream.addTrack(newTrack);
try {
localStream.addTrack(newTrack);
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (e) {
} catch (e: any) {

It appears we need to specify that type for tests to pass

this.logger.error(`SessionDescriptionHandler.setLocalMediaStream - failed to add track: ${e.message}`);
}
// @ts-ignore
SessionDescriptionHandler.dispatchAddTrackEvent(localStream, newTrack);
}).catch((error: Error) => {
Expand All @@ -469,12 +473,13 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
} else {
pc.addStream(localStream);
}

localStream.addTrack(newTrack);
} catch (error) {
this.logger.error(`SessionDescriptionHandler.setLocalMediaStream - failed to add sender ${kind} track`);
throw error;
}

localStream.addTrack(newTrack);
// @ts-ignore
SessionDescriptionHandler.dispatchAddTrackEvent(localStream, newTrack);
}));
Expand Down
28 changes: 15 additions & 13 deletions src/web-rtc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1788,18 +1788,22 @@ export default class WebRTCClient extends Emitter {
return;
}

remoteStream.getTracks().forEach(track => {
if (allTracks || track.kind === 'video') {
remoteStream.removeTrack(track);
}
});

if (pc.getReceivers) {
pc.getReceivers().forEach((receiver: any) => {
if (allTracks || receiver.track.kind === 'video') {
remoteStream.addTrack(receiver.track);
try {
remoteStream.getTracks().forEach(track => {
if (allTracks || track.kind === 'video') {
remoteStream.removeTrack(track);
}
});

if (pc.getReceivers) {
pc.getReceivers().forEach((receiver: any) => {
if (allTracks || receiver.track.kind === 'video') {
remoteStream.addTrack(receiver.track);
}
});
}
} catch (e) {
logger.error('Unable to update remote stream', e);
}
}

Expand Down Expand Up @@ -2417,9 +2421,7 @@ export default class WebRTCClient extends Emitter {
remoteStream = typeof global !== 'undefined' && global.window && global.window.MediaStream ? new global.window.MediaStream() : new window.MediaStream();

pc.getReceivers().forEach((receiver: any) => {
const {
track,
} = receiver;
const { track } = receiver;

if (track && remoteStream) {
remoteStream.addTrack(track);
Expand Down