mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-15 22:41:32 +03:00
Manage some more call states
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
f96e25d833
commit
c1fcadba3b
2 changed files with 33 additions and 4 deletions
|
@ -25,6 +25,13 @@ export enum CallEventGrouperEvent {
|
||||||
StateChanged = "state_changed",
|
StateChanged = "state_changed",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SUPPORTED_STATES = [
|
||||||
|
CallState.Connected,
|
||||||
|
CallState.Connecting,
|
||||||
|
CallState.Ended,
|
||||||
|
CallState.Ringing,
|
||||||
|
];
|
||||||
|
|
||||||
export default class CallEventGrouper extends EventEmitter {
|
export default class CallEventGrouper extends EventEmitter {
|
||||||
invite: MatrixEvent;
|
invite: MatrixEvent;
|
||||||
call: MatrixCall;
|
call: MatrixCall;
|
||||||
|
@ -66,12 +73,15 @@ export default class CallEventGrouper extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private setCallState = () => {
|
private setCallState = () => {
|
||||||
this.state = this.call.state
|
if (SUPPORTED_STATES.includes(this.call.state)) {
|
||||||
|
this.state = this.call.state;
|
||||||
this.emit(CallEventGrouperEvent.StateChanged, this.state);
|
this.emit(CallEventGrouperEvent.StateChanged, this.state);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public add(event: MatrixEvent) {
|
public add(event: MatrixEvent) {
|
||||||
if (event.getType() === EventType.CallInvite) this.invite = event;
|
if (event.getType() === EventType.CallInvite) this.invite = event;
|
||||||
|
if (event.getType() === EventType.CallHangup) this.state = CallState.Ended;
|
||||||
|
|
||||||
if (this.call) return;
|
if (this.call) return;
|
||||||
const callId = event.getContent().call_id;
|
const callId = event.getContent().call_id;
|
||||||
|
|
|
@ -32,6 +32,12 @@ interface IState {
|
||||||
callState: CallState;
|
callState: CallState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TEXTUAL_STATES = new Map([
|
||||||
|
[CallState.Connected, _t("Connected")],
|
||||||
|
[CallState.Connecting, _t("Connecting")],
|
||||||
|
[CallState.Ended, _t("This call has ended")],
|
||||||
|
]);
|
||||||
|
|
||||||
export default class CallEvent extends React.Component<IProps, IState> {
|
export default class CallEvent extends React.Component<IProps, IState> {
|
||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -49,7 +55,7 @@ export default class CallEvent extends React.Component<IProps, IState> {
|
||||||
this.props.callEventGrouper.removeListener(CallEventGrouperEvent.StateChanged, this.onStateChanged);
|
this.props.callEventGrouper.removeListener(CallEventGrouperEvent.StateChanged, this.onStateChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onStateChanged = (newState: CallEventGrouperState) => {
|
private onStateChanged = (newState: CallState) => {
|
||||||
this.setState({callState: newState});
|
this.setState({callState: newState});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +63,9 @@ export default class CallEvent extends React.Component<IProps, IState> {
|
||||||
const event = this.props.mxEvent;
|
const event = this.props.mxEvent;
|
||||||
const sender = event.sender ? event.sender.name : event.getSender();
|
const sender = event.sender ? event.sender.name : event.getSender();
|
||||||
|
|
||||||
|
const state = this.state.callState;
|
||||||
let content;
|
let content;
|
||||||
if (this.state.callState === CallState.Ringing) {
|
if (state === CallState.Ringing) {
|
||||||
content = (
|
content = (
|
||||||
<div className="mx_CallEvent_content">
|
<div className="mx_CallEvent_content">
|
||||||
<FormButton
|
<FormButton
|
||||||
|
@ -76,6 +83,18 @@ export default class CallEvent extends React.Component<IProps, IState> {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
} else if (Array.from(TEXTUAL_STATES.keys()).includes(state)) {
|
||||||
|
content = (
|
||||||
|
<div className="mx_CallEvent_content">
|
||||||
|
{ TEXTUAL_STATES.get(state) }
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
content = (
|
||||||
|
<div className="mx_CallEvent_content">
|
||||||
|
{ _t("The call is in an unknown state!") }
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue