Use MatrixClientPeg::safeGet for strict typing (#10989)
This commit is contained in:
+25
-23
@@ -192,7 +192,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
if (this.shouldObeyAssertedfIdentity()) {
|
||||
const nativeUser = this.assertedIdentityNativeUsers.get(call.callId);
|
||||
if (nativeUser) {
|
||||
const room = findDMForUser(MatrixClientPeg.get(), nativeUser);
|
||||
const room = findDMForUser(MatrixClientPeg.safeGet(), nativeUser);
|
||||
if (room) return room.roomId;
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
if (SettingsStore.getValue(UIFeature.Voip)) {
|
||||
MatrixClientPeg.get().on(CallEventHandlerEvent.Incoming, this.onCallIncoming);
|
||||
MatrixClientPeg.safeGet().on(CallEventHandlerEvent.Incoming, this.onCallIncoming);
|
||||
}
|
||||
|
||||
this.checkProtocols(CHECK_PROTOCOLS_ATTEMPTS);
|
||||
@@ -271,7 +271,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
public isForcedSilent(): boolean {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
return localNotificationsAreSilenced(cli);
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
private async checkProtocols(maxTries: number): Promise<void> {
|
||||
try {
|
||||
const protocols = await MatrixClientPeg.get().getThirdpartyProtocols();
|
||||
const protocols = await MatrixClientPeg.safeGet().getThirdpartyProtocols();
|
||||
|
||||
if (protocols[PROTOCOL_PSTN] !== undefined) {
|
||||
this.supportsPstnProtocol = Boolean(protocols[PROTOCOL_PSTN]);
|
||||
@@ -358,7 +358,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
public async pstnLookup(phoneNumber: string): Promise<ThirdpartyLookupResponse[]> {
|
||||
try {
|
||||
return await MatrixClientPeg.get().getThirdpartyUser(
|
||||
return await MatrixClientPeg.safeGet().getThirdpartyUser(
|
||||
this.pstnSupportPrefixed ? PROTOCOL_PSTN_PREFIXED : PROTOCOL_PSTN,
|
||||
{
|
||||
"m.id.phone": phoneNumber,
|
||||
@@ -372,7 +372,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
public async sipVirtualLookup(nativeMxid: string): Promise<ThirdpartyLookupResponse[]> {
|
||||
try {
|
||||
return await MatrixClientPeg.get().getThirdpartyUser(PROTOCOL_SIP_VIRTUAL, {
|
||||
return await MatrixClientPeg.safeGet().getThirdpartyUser(PROTOCOL_SIP_VIRTUAL, {
|
||||
native_mxid: nativeMxid,
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -383,7 +383,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
public async sipNativeLookup(virtualMxid: string): Promise<ThirdpartyLookupResponse[]> {
|
||||
try {
|
||||
return await MatrixClientPeg.get().getThirdpartyUser(PROTOCOL_SIP_NATIVE, {
|
||||
return await MatrixClientPeg.safeGet().getThirdpartyUser(PROTOCOL_SIP_NATIVE, {
|
||||
virtual_mxid: virtualMxid,
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -394,7 +394,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
private onCallIncoming = (call: MatrixCall): void => {
|
||||
// if the runtime env doesn't do VoIP, stop here.
|
||||
if (!MatrixClientPeg.get().supportsVoip()) {
|
||||
if (!MatrixClientPeg.get()?.supportsVoip()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
// get ready to send encrypted events in the room, so if the user does answer
|
||||
// the call, we'll be ready to send. NB. This is the protocol-level room ID not
|
||||
// the mapped one: that's where we'll send the events.
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const room = cli.getRoom(call.roomId);
|
||||
if (room) cli.prepareToEncrypt(room);
|
||||
};
|
||||
@@ -463,7 +463,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
public getAllActiveCallsForPip(roomId: string): MatrixCall[] {
|
||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
||||
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||
if (room && WidgetLayoutStore.instance.hasMaximisedWidget(room)) {
|
||||
// This checks if there is space for the call view in the aux panel
|
||||
// If there is no space any call should be displayed in PiP
|
||||
@@ -570,7 +570,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
if (
|
||||
MatrixClientPeg.get().getTurnServers().length === 0 &&
|
||||
MatrixClientPeg.safeGet().getTurnServers().length === 0 &&
|
||||
SettingsStore.getValue("fallbackICEServerAllowed") === null
|
||||
) {
|
||||
this.showICEFallbackPrompt();
|
||||
@@ -638,7 +638,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
// this if we want the actual, native room to exist (which we do). This is why it's
|
||||
// important to only obey asserted identity in trusted environments, since anyone you're
|
||||
// on a call with can cause you to send a room invite to someone.
|
||||
await ensureDMExists(MatrixClientPeg.get(), newNativeAssertedIdentity);
|
||||
await ensureDMExists(MatrixClientPeg.safeGet(), newNativeAssertedIdentity);
|
||||
|
||||
const newMappedRoomId = this.roomIdForCall(call);
|
||||
logger.log(`Old room ID: ${mappedRoomId}, new room ID: ${newMappedRoomId}`);
|
||||
@@ -678,7 +678,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
switch (newState) {
|
||||
case CallState.Ringing: {
|
||||
const incomingCallPushRule = new PushProcessor(MatrixClientPeg.get()).getPushRuleById(
|
||||
const incomingCallPushRule = new PushProcessor(MatrixClientPeg.safeGet()).getPushRuleById(
|
||||
RuleId.IncomingCall,
|
||||
);
|
||||
const pushRuleEnabled = incomingCallPushRule?.enabled;
|
||||
@@ -825,7 +825,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
private showICEFallbackPrompt(): void {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
Modal.createDialog(
|
||||
QuestionDialog,
|
||||
{
|
||||
@@ -907,6 +907,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
private async placeMatrixCall(roomId: string, type: CallType, transferee?: MatrixCall): Promise<void> {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const mappedRoomId = (await VoipUserMapper.sharedInstance().getOrCreateVirtualRoomForRoom(roomId)) || roomId;
|
||||
logger.debug("Mapped real room " + roomId + " to room ID " + mappedRoomId);
|
||||
|
||||
@@ -916,15 +917,15 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
// in this queue, and since we're about to place a new call, they can only be events from
|
||||
// previous calls that are probably stale by now, so just cancel them.
|
||||
if (mappedRoomId !== roomId) {
|
||||
const mappedRoom = MatrixClientPeg.get().getRoom(mappedRoomId);
|
||||
const mappedRoom = cli.getRoom(mappedRoomId);
|
||||
if (mappedRoom?.getPendingEvents().length) {
|
||||
Resend.cancelUnsentEvents(mappedRoom);
|
||||
}
|
||||
}
|
||||
|
||||
const timeUntilTurnCresExpire = MatrixClientPeg.get().getTurnServersExpiry() - Date.now();
|
||||
const timeUntilTurnCresExpire = cli.getTurnServersExpiry() - Date.now();
|
||||
logger.log("Current turn creds expire in " + timeUntilTurnCresExpire + " ms");
|
||||
const call = MatrixClientPeg.get().createCall(mappedRoomId)!;
|
||||
const call = cli.createCall(mappedRoomId)!;
|
||||
|
||||
try {
|
||||
this.addCallForRoom(roomId, call);
|
||||
@@ -953,6 +954,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
public async placeCall(roomId: string, type: CallType, transferee?: MatrixCall): Promise<void> {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
// Pause current broadcast, if any
|
||||
SdkContextClass.instance.voiceBroadcastPlaybacksStore.getCurrent()?.pause();
|
||||
|
||||
@@ -969,7 +971,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
// if the runtime env doesn't do VoIP, whine.
|
||||
if (!MatrixClientPeg.get().supportsVoip()) {
|
||||
if (!cli.supportsVoip()) {
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Calls are unsupported"),
|
||||
description: _t("You cannot place calls in this browser."),
|
||||
@@ -977,7 +979,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (MatrixClientPeg.get().getSyncState() === SyncState.Error) {
|
||||
if (cli.getSyncState() === SyncState.Error) {
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Connectivity to the server has been lost"),
|
||||
description: _t("You cannot place calls without a connection to the server."),
|
||||
@@ -994,7 +996,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
||||
const room = cli.getRoom(roomId);
|
||||
if (!room) {
|
||||
logger.error(`Room ${roomId} does not exist.`);
|
||||
return;
|
||||
@@ -1095,7 +1097,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
nativeUserId = userId;
|
||||
}
|
||||
|
||||
const roomId = await ensureDMExists(MatrixClientPeg.get(), nativeUserId);
|
||||
const roomId = await ensureDMExists(MatrixClientPeg.safeGet(), nativeUserId);
|
||||
if (!roomId) {
|
||||
throw new Error("Failed to ensure DM exists for dialing number");
|
||||
}
|
||||
@@ -1135,7 +1137,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
|
||||
public async startTransferToMatrixID(call: MatrixCall, destination: string, consultFirst: boolean): Promise<void> {
|
||||
if (consultFirst) {
|
||||
const dmRoomId = await ensureDMExists(MatrixClientPeg.get(), destination);
|
||||
const dmRoomId = await ensureDMExists(MatrixClientPeg.safeGet(), destination);
|
||||
if (!dmRoomId) {
|
||||
logger.log("Failed to transfer call, could not ensure dm exists");
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
@@ -1194,7 +1196,7 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
private async placeJitsiCall(roomId: string, type: CallType): Promise<void> {
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
logger.info(`Place conference call in ${roomId}`);
|
||||
|
||||
dis.dispatch({ action: "appsDrawer", show: true });
|
||||
|
||||
Reference in New Issue
Block a user