Refactor setState()
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
78229a2fd0
commit
b202f997e3
1 changed files with 7 additions and 6 deletions
|
@ -55,6 +55,10 @@ export default class CallEventGrouper extends EventEmitter {
|
||||||
return [...this.events].find((event) => event.getType() === EventType.CallHangup);
|
return [...this.events].find((event) => event.getType() === EventType.CallHangup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get reject(): MatrixEvent {
|
||||||
|
return [...this.events].find((event) => event.getType() === EventType.CallReject);
|
||||||
|
}
|
||||||
|
|
||||||
public get isVoice(): boolean {
|
public get isVoice(): boolean {
|
||||||
const invite = this.invite;
|
const invite = this.invite;
|
||||||
if (!invite) return;
|
if (!invite) return;
|
||||||
|
@ -101,13 +105,10 @@ export default class CallEventGrouper extends EventEmitter {
|
||||||
if (SUPPORTED_STATES.includes(this.call?.state)) {
|
if (SUPPORTED_STATES.includes(this.call?.state)) {
|
||||||
this.state = this.call.state;
|
this.state = this.call.state;
|
||||||
} else {
|
} else {
|
||||||
const lastEvent = [...this.events][this.events.size - 1];
|
|
||||||
const lastEventType = lastEvent.getType();
|
|
||||||
|
|
||||||
if (this.callWasMissed) this.state = CustomCallState.Missed;
|
if (this.callWasMissed) this.state = CustomCallState.Missed;
|
||||||
else if (lastEventType === EventType.CallHangup) this.state = CallState.Ended;
|
else if (this.reject) this.state = CallState.Ended;
|
||||||
else if (lastEventType === EventType.CallReject) this.state = CallState.Ended;
|
else if (this.hangup) this.state = CallState.Ended;
|
||||||
else if (lastEventType === EventType.CallInvite && this.call) this.state = CallState.Connecting;
|
else if (this.invite && this.call) this.state = CallState.Connecting;
|
||||||
}
|
}
|
||||||
this.emit(CallEventGrouperEvent.StateChanged, this.state);
|
this.emit(CallEventGrouperEvent.StateChanged, this.state);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue