Skip to content

Commit

Permalink
Revert hack to only clone streams on safari
Browse files Browse the repository at this point in the history
Reverts #2450

Looks like this wasn't really the problem (although may have made it
happens faster) and the actual problem was multiple audio contexts
and/or leaking peer connections as fixed in #2484
  • Loading branch information
dbkr committed Jul 1, 2022
1 parent f9672cf commit ac8a9eb
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,6 @@ function getCallUserId(call: MatrixCall): string | null {
return call.getOpponentMember()?.userId || call.invitee || null;
}

/**
* Returns a call feed for passing to a new call in the group call. The media
* This could be either return the passed feed as-is or a clone, depending on the
* platform.
* @returns CallFeed
*/
function feedForNewCallFromFeed(feed: CallFeed): CallFeed {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

// Safari can't send a MediaStream to multiple sources, so we clone it,
// however cloning mediastreams on Chrome appears to cause the audio renderer
// to become unstable and hang: https://github.com/vector-im/element-call/issues/267
// It's a bit arbitrary what we do for other browsers: I've made Safari the special
// case on a somewhat arbitrary basis.
// To retest later to see if this hack is still necessary:
// * In Safari, you should be able to have a group call with 2 other people and both
// of them see your video stream (either desktop or mobile Safari)
// * In Chrome, you should be able to enter a call and then go to youtube and play
// a video (both desktop & Android Chrome, although in Android you may have to
// open YouTube in incognito mode to avoid being redirected to the app.)
if (isSafari) {
return feed.clone();
}

return feed;
}

export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventHandlerMap> {
// Config
public activeSpeakerInterval = 1000;
Expand Down Expand Up @@ -598,7 +571,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH

// TODO: handle errors
await Promise.all(this.calls.map(call => call.pushLocalFeed(
feedForNewCallFromFeed(this.localScreenshareFeed),
this.localScreenshareFeed.clone(),
)));

await this.sendMemberStateEvent();
Expand Down Expand Up @@ -673,7 +646,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
this.addCall(newCall);
}

newCall.answerWithCallFeeds(this.getLocalFeeds().map((feed) => feedForNewCallFromFeed(feed)));
newCall.answerWithCallFeeds(this.getLocalFeeds().map((feed) => feed.clone()));
};

/**
Expand Down Expand Up @@ -861,7 +834,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH

try {
await newCall.placeCallWithCallFeeds(
this.getLocalFeeds().map(feed => feedForNewCallFromFeed(feed)),
this.getLocalFeeds().map(feed => feed.clone()),
requestScreenshareFeed,
);
} catch (e) {
Expand Down

0 comments on commit ac8a9eb

Please sign in to comment.