Merge pull request #5438 from matrix-org/dbkr/move_calls_to_callhandler
Move call listener out of MatrixChat
This commit is contained in:
commit
2144932bbc
3 changed files with 26 additions and 13 deletions
|
@ -79,6 +79,7 @@ import { ElementWidgetActions } from "./stores/widgets/ElementWidgetActions";
|
||||||
import { MatrixCall, CallErrorCode, CallState, CallEvent, CallParty, CallType } from "matrix-js-sdk/src/webrtc/call";
|
import { MatrixCall, CallErrorCode, CallState, CallEvent, CallParty, CallType } from "matrix-js-sdk/src/webrtc/call";
|
||||||
import Analytics from './Analytics';
|
import Analytics from './Analytics';
|
||||||
import CountlyAnalytics from "./CountlyAnalytics";
|
import CountlyAnalytics from "./CountlyAnalytics";
|
||||||
|
import {UIFeature} from "./settings/UIFeature";
|
||||||
|
|
||||||
enum AudioID {
|
enum AudioID {
|
||||||
Ring = 'ringAudio',
|
Ring = 'ringAudio',
|
||||||
|
@ -124,7 +125,7 @@ export default class CallHandler {
|
||||||
return window.mxCallHandler;
|
return window.mxCallHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
start() {
|
||||||
dis.register(this.onAction);
|
dis.register(this.onAction);
|
||||||
// add empty handlers for media actions, otherwise the media keys
|
// add empty handlers for media actions, otherwise the media keys
|
||||||
// end up causing the audio elements with our ring/ringback etc
|
// end up causing the audio elements with our ring/ringback etc
|
||||||
|
@ -137,6 +138,27 @@ export default class CallHandler {
|
||||||
navigator.mediaSession.setActionHandler('previoustrack', function() {});
|
navigator.mediaSession.setActionHandler('previoustrack', function() {});
|
||||||
navigator.mediaSession.setActionHandler('nexttrack', function() {});
|
navigator.mediaSession.setActionHandler('nexttrack', function() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SettingsStore.getValue(UIFeature.Voip)) {
|
||||||
|
MatrixClientPeg.get().on('Call.incoming', this.onCallIncoming);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
if (cli) {
|
||||||
|
cli.removeListener('Call.incoming', this.onCallIncoming);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private onCallIncoming = (call) => {
|
||||||
|
// we dispatch this synchronously to make sure that the event
|
||||||
|
// handlers on the call are set up immediately (so that if
|
||||||
|
// we get an immediate hangup, we don't get a stuck call)
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'incoming_call',
|
||||||
|
call: call,
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCallForRoom(roomId: string): MatrixCall {
|
getCallForRoom(roomId: string): MatrixCall {
|
||||||
|
|
|
@ -48,6 +48,7 @@ import {Jitsi} from "./widgets/Jitsi";
|
||||||
import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "./BasePlatform";
|
import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "./BasePlatform";
|
||||||
import ThreepidInviteStore from "./stores/ThreepidInviteStore";
|
import ThreepidInviteStore from "./stores/ThreepidInviteStore";
|
||||||
import CountlyAnalytics from "./CountlyAnalytics";
|
import CountlyAnalytics from "./CountlyAnalytics";
|
||||||
|
import CallHandler from './CallHandler';
|
||||||
|
|
||||||
const HOMESERVER_URL_KEY = "mx_hs_url";
|
const HOMESERVER_URL_KEY = "mx_hs_url";
|
||||||
const ID_SERVER_URL_KEY = "mx_is_url";
|
const ID_SERVER_URL_KEY = "mx_is_url";
|
||||||
|
@ -665,6 +666,7 @@ async function startMatrixClient(startSyncing = true): Promise<void> {
|
||||||
DMRoomMap.makeShared().start();
|
DMRoomMap.makeShared().start();
|
||||||
IntegrationManagers.sharedInstance().startWatching();
|
IntegrationManagers.sharedInstance().startWatching();
|
||||||
ActiveWidgetStore.start();
|
ActiveWidgetStore.start();
|
||||||
|
CallHandler.sharedInstance().start();
|
||||||
|
|
||||||
// Start Mjolnir even though we haven't checked the feature flag yet. Starting
|
// Start Mjolnir even though we haven't checked the feature flag yet. Starting
|
||||||
// the thing just wastes CPU cycles, but should result in no actual functionality
|
// the thing just wastes CPU cycles, but should result in no actual functionality
|
||||||
|
@ -760,6 +762,7 @@ async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void
|
||||||
*/
|
*/
|
||||||
export function stopMatrixClient(unsetClient = true): void {
|
export function stopMatrixClient(unsetClient = true): void {
|
||||||
Notifier.stop();
|
Notifier.stop();
|
||||||
|
CallHandler.sharedInstance().stop();
|
||||||
UserActivity.sharedInstance().stop();
|
UserActivity.sharedInstance().stop();
|
||||||
TypingStore.sharedInstance().reset();
|
TypingStore.sharedInstance().reset();
|
||||||
Presence.stop();
|
Presence.stop();
|
||||||
|
|
|
@ -1353,18 +1353,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (SettingsStore.getValue(UIFeature.Voip)) {
|
|
||||||
cli.on('Call.incoming', function(call) {
|
|
||||||
// we dispatch this synchronously to make sure that the event
|
|
||||||
// handlers on the call are set up immediately (so that if
|
|
||||||
// we get an immediate hangup, we don't get a stuck call)
|
|
||||||
dis.dispatch({
|
|
||||||
action: 'incoming_call',
|
|
||||||
call: call,
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
cli.on('Session.logged_out', function(errObj) {
|
cli.on('Session.logged_out', function(errObj) {
|
||||||
if (Lifecycle.isLoggingOut()) return;
|
if (Lifecycle.isLoggingOut()) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue