Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Use hangupOrReject() instead of the dispatcher
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
  • Loading branch information
SimonBrandner committed Aug 28, 2021
1 parent 2ae0160 commit cd4ca57
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
38 changes: 14 additions & 24 deletions src/CallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import SettingsStore from './settings/SettingsStore';
import { Jitsi } from "./widgets/Jitsi";
import { WidgetType } from "./widgets/WidgetType";
import { SettingLevel } from "./settings/SettingLevel";
import { ActionPayload } from "./dispatcher/payloads";
import { base32 } from "rfc4648";

import QuestionDialog from "./components/views/dialogs/QuestionDialog";
Expand Down Expand Up @@ -146,7 +145,6 @@ export default class CallHandler extends EventEmitter {
// call with a different party to this one.
private transferees = new Map<string, MatrixCall>(); // callId (target) -> call (transferee)
private audioPromises = new Map<AudioID, Promise<void>>();
private dispatcherRef: string = null;
private supportsPstnProtocol = null;
private pstnSupportPrefixed = null; // True if the server only support the prefixed pstn protocol
private supportsSipNativeVirtual = null; // im.vector.protocol.sip_virtual and im.vector.protocol.sip_native
Expand Down Expand Up @@ -191,7 +189,6 @@ export default class CallHandler extends EventEmitter {
}

start() {
this.dispatcherRef = dis.register(this.onAction);
// add empty handlers for media actions, otherwise the media keys
// end up causing the audio elements with our ring/ringback etc
// audio clips in to play.
Expand All @@ -216,10 +213,6 @@ export default class CallHandler extends EventEmitter {
if (cli) {
cli.removeListener('Call.incoming', this.onCallIncoming);
}
if (this.dispatcherRef !== null) {
dis.unregister(this.dispatcherRef);
this.dispatcherRef = null;
}
}

public silenceCall(callId: string) {
Expand Down Expand Up @@ -848,25 +841,22 @@ export default class CallHandler extends EventEmitter {
}
}

private onAction = (payload: ActionPayload) => {
switch (payload.action) {
case 'hangup':
case 'reject':
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);
public hangupOrReject(roomId: string, reject?: boolean): void {
const call = this.calls.get(roomId);

if (!this.calls.get(payload.room_id)) {
return; // no call to hangup
}
if (payload.action === 'reject') {
this.calls.get(payload.room_id).reject();
} else {
this.calls.get(payload.room_id).hangup(CallErrorCode.UserHangup, false);
}
// don't remove the call yet: let the hangup event handler do it (otherwise it will throw
// the hangup event away)
break;
// no call to hangup
if (!call) return;

this.stopRingingIfPossible(call.callId);

if (reject) {
call.reject();
} else {
call.hangup(CallErrorCode.UserHangup, false);
}
};
// don't remove the call yet: let the hangup event handler do it (otherwise it will throw
// the hangup event away)
}

public answerCall(roomId: string): void {
const call = this.calls.get(roomId);
Expand Down
5 changes: 1 addition & 4 deletions src/components/views/voip/CallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ export default class CallView extends React.Component<IProps, IState> {
};

private onHangupClick = (): void => {
dis.dispatch({
action: 'hangup',
room_id: CallHandler.instance.roomIdForCall(this.props.call),
});
CallHandler.instance.hangupOrReject(CallHandler.instance.roomIdForCall(this.props.call));
};

private onToggleSidebar = (): void => {
Expand Down
6 changes: 1 addition & 5 deletions src/toasts/IncomingCallToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { CallType, MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
import classNames from 'classnames';
import { replaceableComponent } from '../utils/replaceableComponent';
import CallHandler, { CallHandlerEvent } from '../CallHandler';
import dis from '../dispatcher/dispatcher';
import { MatrixClientPeg } from '../MatrixClientPeg';
import { _t } from '../languageHandler';
import RoomAvatar from '../components/views/avatars/RoomAvatar';
Expand Down Expand Up @@ -68,10 +67,7 @@ export default class IncomingCallToast extends React.Component<IProps, IState> {

private onRejectClick= (e: React.MouseEvent): void => {
e.stopPropagation();
dis.dispatch({
action: 'reject',
room_id: CallHandler.instance.roomIdForCall(this.props.call),
});
CallHandler.instance.hangupOrReject(CallHandler.instance.roomIdForCall(this.props.call), true);
};

private onSilenceClick = (e: React.MouseEvent): void => {
Expand Down

0 comments on commit cd4ca57

Please sign in to comment.