Skip to content

Commit

Permalink
Merge pull request #1851 from SimonBrandner/fix/glare/18538
Browse files Browse the repository at this point in the history
Fix glare related regressions
  • Loading branch information
dbkr committed Aug 16, 2021
2 parents 977720c + d65b482 commit ccf296e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
13 changes: 2 additions & 11 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export class MatrixCall extends EventEmitter {
this.emit(CallEvent.FeedsChanged, this.feeds);
}

// TODO: Find out what is going on here
// why do we enable audio (and only audio) tracks here? -- matthew
setTracksEnabled(stream.getAudioTracks(), true);

Expand Down Expand Up @@ -708,8 +709,6 @@ export class MatrixCall extends EventEmitter {
this.getUserMediaFailed(e);
return;
}
} else if (this.localUsermediaStream) {
this.gotUserMediaForAnswer(this.localUsermediaStream);
} else if (this.waitForLocalAVStream) {
this.setState(CallState.WaitLocalMedia);
}
Expand All @@ -721,14 +720,10 @@ export class MatrixCall extends EventEmitter {
* @param {MatrixCall} newCall The new call.
*/
replacedBy(newCall: MatrixCall) {
logger.debug(this.callId + " being replaced by " + newCall.callId);
if (this.state === CallState.WaitLocalMedia) {
logger.debug("Telling new call to wait for local media");
newCall.waitForLocalAVStream = true;
} else if (this.state === CallState.CreateOffer) {
logger.debug("Handing local stream to new call");
newCall.gotUserMediaForAnswer(this.localUsermediaStream);
} else if (this.state === CallState.InviteSent) {
} else if ([CallState.CreateOffer, CallState.InviteSent].includes(this.state)) {
logger.debug("Handing local stream to new call");
newCall.gotUserMediaForAnswer(this.localUsermediaStream);
}
Expand Down Expand Up @@ -1029,7 +1024,6 @@ export class MatrixCall extends EventEmitter {
this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia);
this.setState(CallState.CreateOffer);

logger.info("Got local AV stream with id " + this.localUsermediaStream.id);
logger.debug("gotUserMediaForInvite -> " + this.type);
// Now we wait for the negotiationneeded event
};
Expand Down Expand Up @@ -1087,9 +1081,6 @@ export class MatrixCall extends EventEmitter {
}

this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia);

logger.info("Got local AV stream with id " + this.localUsermediaStream.id);

this.setState(CallState.CreateAnswer);

let myAnswer;
Expand Down
18 changes: 10 additions & 8 deletions src/webrtc/callEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class CallEventHandler {
continue;
}
try {
this.handleCallEvent(e);
await this.handleCallEvent(e);
} catch (e) {
logger.error("Caught exception handling call event", e);
}
Expand All @@ -100,7 +100,7 @@ export class CallEventHandler {

if (event.isBeingDecrypted() || event.isDecryptionFailure()) {
// add an event listener for once the event is decrypted.
event.once("Event.decrypted", () => {
event.once("Event.decrypted", async () => {
if (!this.eventIsACall(event)) return;

if (this.callEventBuffer.includes(event)) {
Expand All @@ -110,7 +110,7 @@ export class CallEventHandler {
// This one wasn't buffered so just run the event handler for it
// straight away
try {
this.handleCallEvent(event);
await this.handleCallEvent(event);
} catch (e) {
logger.error("Caught exception handling call event", e);
}
Expand All @@ -128,7 +128,7 @@ export class CallEventHandler {
return type.startsWith("m.call.") || type.startsWith("org.matrix.call.");
}

private handleCallEvent(event: MatrixEvent) {
private async handleCallEvent(event: MatrixEvent) {
const content = event.getContent();
const type = event.getType() as EventType;
const weSentTheEvent = event.getSender() === this.client.credentials.userId;
Expand Down Expand Up @@ -169,7 +169,7 @@ export class CallEventHandler {
}

call.callId = content.call_id;
call.initWithInvite(event);
await call.initWithInvite(event);
this.calls.set(call.callId, call);

// if we stashed candidate events for that call ID, play them back now
Expand Down Expand Up @@ -201,9 +201,11 @@ export class CallEventHandler {
// we've got an invite, pick the incoming call because we know
// we haven't sent our invite yet otherwise, pick whichever
// call has the lowest call ID (by string comparison)
if (existingCall.state === CallState.WaitLocalMedia ||
existingCall.state === CallState.CreateOffer ||
existingCall.callId > call.callId) {
if (
existingCall.state === CallState.WaitLocalMedia ||
existingCall.state === CallState.CreateOffer ||
existingCall.callId > call.callId
) {
logger.log(
"Glare detected: answering incoming call " + call.callId +
" and canceling outgoing call " + existingCall.callId,
Expand Down

0 comments on commit ccf296e

Please sign in to comment.