Improved missed calls

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-06-01 13:40:25 +02:00
parent 9b904cdee8
commit f1e780e642
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
1 changed files with 9 additions and 4 deletions

View File

@ -82,6 +82,13 @@ export default class CallEventGrouper extends EventEmitter {
return this.state;
}
/**
* Returns true if there are only events from the other side - we missed the call
*/
private wasThisCallMissed(): boolean {
return !this.events.some((event) => event.sender?.userId === MatrixClientPeg.get().getUserId());
}
private setCallListeners() {
if (!this.call) return;
this.call.addListener(CallEvent.State, this.setCallState);
@ -94,12 +101,10 @@ export default class CallEventGrouper extends EventEmitter {
const lastEvent = this.events[this.events.length - 1];
const lastEventType = lastEvent.getType();
if (lastEventType === EventType.CallHangup) this.state = CallState.Ended;
if (this.wasThisCallMissed()) this.state = CustomCallState.Missed;
else if (lastEventType === EventType.CallHangup) this.state = CallState.Ended;
else if (lastEventType === EventType.CallReject) this.state = CallState.Ended;
else if (lastEventType === EventType.CallInvite && this.call) this.state = CallState.Connecting;
else if (this.invite?.sender?.userId !== MatrixClientPeg.get().getUserId()) {
this.state = CustomCallState.Missed;
}
}
this.emit(CallEventGrouperEvent.StateChanged, this.state);
}