Save all events

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

View File

@ -33,10 +33,14 @@ const SUPPORTED_STATES = [
]; ];
export default class CallEventGrouper extends EventEmitter { export default class CallEventGrouper extends EventEmitter {
invite: MatrixEvent; events: Array<MatrixEvent> = [];
call: MatrixCall; call: MatrixCall;
state: CallState; state: CallState;
private get invite(): MatrixEvent {
return this.events.find((event) => event.getType() === EventType.CallInvite);
}
public answerCall = () => { public answerCall = () => {
this.call?.answer(); this.call?.answer();
} }
@ -80,10 +84,11 @@ export default class CallEventGrouper extends EventEmitter {
} }
public add(event: MatrixEvent) { public add(event: MatrixEvent) {
if (event.getType() === EventType.CallInvite) this.invite = event; this.events.push(event);
if (event.getType() === EventType.CallHangup) this.state = CallState.Ended; const type = event.getType();
if (this.call) return; if (type === EventType.CallHangup) this.state = CallState.Ended;
else if (type === EventType.CallReject) this.state = CallState.Ended;
const callId = event.getContent().call_id; const callId = event.getContent().call_id;
this.call = CallHandler.sharedInstance().getCallById(callId); this.call = CallHandler.sharedInstance().getCallById(callId);
if (!this.call) return; if (!this.call) return;