calling: update setTurnServerOverride to support overriding all ice server fields
This commit is contained in:
parent
a1f0afdae8
commit
a57d5582f0
2 changed files with 61 additions and 35 deletions
|
@ -82,6 +82,7 @@ import * as durations from '../util/durations';
|
||||||
import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
|
import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
|
||||||
import { fetchMembershipProof, getMembershipList } from '../groups';
|
import { fetchMembershipProof, getMembershipList } from '../groups';
|
||||||
import type { ProcessedEnvelope } from '../textsecure/Types.d';
|
import type { ProcessedEnvelope } from '../textsecure/Types.d';
|
||||||
|
import type { GetIceServersResultType } from '../textsecure/WebAPI';
|
||||||
import { missingCaseError } from '../util/missingCaseError';
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
import { normalizeGroupCallTimestamp } from '../util/ringrtc/normalizeGroupCallTimestamp';
|
import { normalizeGroupCallTimestamp } from '../util/ringrtc/normalizeGroupCallTimestamp';
|
||||||
import {
|
import {
|
||||||
|
@ -317,7 +318,7 @@ export class CallingClass {
|
||||||
|
|
||||||
public _sfuUrl?: string;
|
public _sfuUrl?: string;
|
||||||
|
|
||||||
public _iceServerOverride?: string;
|
public _iceServerOverride?: GetIceServersResultType | string;
|
||||||
|
|
||||||
private lastMediaDeviceSettings?: MediaDeviceSettings;
|
private lastMediaDeviceSettings?: MediaDeviceSettings;
|
||||||
|
|
||||||
|
@ -2658,12 +2659,39 @@ export class CallingClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleStartCall(call: Call): Promise<boolean> {
|
private async handleStartCall(call: Call): Promise<boolean> {
|
||||||
|
type IceServer = {
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
hostname?: string;
|
||||||
|
urls: Array<string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function iceServerConfigToList(
|
||||||
|
iceServerConfig: GetIceServersResultType
|
||||||
|
): Array<IceServer> {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
hostname: iceServerConfig.hostname ?? '',
|
||||||
|
username: iceServerConfig.username,
|
||||||
|
password: iceServerConfig.password,
|
||||||
|
urls: (iceServerConfig.urlsWithIps ?? []).slice(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hostname: '',
|
||||||
|
username: iceServerConfig.username,
|
||||||
|
password: iceServerConfig.password,
|
||||||
|
urls: (iceServerConfig.urls ?? []).slice(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
if (!window.textsecure.messaging) {
|
if (!window.textsecure.messaging) {
|
||||||
log.error('handleStartCall: offline!');
|
log.error('handleStartCall: offline!');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const iceServer = await window.textsecure.messaging.server.getIceServers();
|
const iceServerConfig =
|
||||||
|
await window.textsecure.messaging.server.getIceServers();
|
||||||
|
|
||||||
const shouldRelayCalls = window.Events.getAlwaysRelayCalls();
|
const shouldRelayCalls = window.Events.getAlwaysRelayCalls();
|
||||||
|
|
||||||
|
@ -2676,33 +2704,23 @@ export class CallingClass {
|
||||||
// If the peer is not in the user's system contacts, force IP hiding.
|
// If the peer is not in the user's system contacts, force IP hiding.
|
||||||
const isContactUntrusted = !isInSystemContacts(conversation.attributes);
|
const isContactUntrusted = !isInSystemContacts(conversation.attributes);
|
||||||
|
|
||||||
|
// proritize ice servers with IPs to avoid DNS
|
||||||
// only include hostname with urlsWithIps
|
// only include hostname with urlsWithIps
|
||||||
const iceServers = this._iceServerOverride
|
let iceServers = iceServerConfigToList(iceServerConfig);
|
||||||
? [
|
|
||||||
{
|
if (this._iceServerOverride) {
|
||||||
hostname: ICE_SERVER_IS_IP_LIKE.test(this._iceServerOverride)
|
if (typeof this._iceServerOverride === 'string') {
|
||||||
? iceServer.hostname
|
if (ICE_SERVER_IS_IP_LIKE.test(this._iceServerOverride)) {
|
||||||
: '',
|
iceServers[0].urls = [this._iceServerOverride];
|
||||||
username: iceServer.username,
|
iceServers = [iceServers[0]];
|
||||||
password: iceServer.password,
|
} else {
|
||||||
urls: [this._iceServerOverride.toString()],
|
iceServers[1].urls = [this._iceServerOverride];
|
||||||
},
|
iceServers = [iceServers[1]];
|
||||||
]
|
}
|
||||||
: // proritize ice servers with IPs to avoid DNS
|
} else {
|
||||||
[
|
iceServers = iceServerConfigToList(this._iceServerOverride);
|
||||||
{
|
}
|
||||||
hostname: iceServer.hostname ?? '',
|
}
|
||||||
username: iceServer.username,
|
|
||||||
password: iceServer.password,
|
|
||||||
urls: (iceServer.urlsWithIps ?? []).slice(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
hostname: '',
|
|
||||||
username: iceServer.username,
|
|
||||||
password: iceServer.password,
|
|
||||||
urls: (iceServer.urls ?? []).slice(),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const callSettings = {
|
const callSettings = {
|
||||||
iceServers,
|
iceServers,
|
||||||
|
|
|
@ -13,7 +13,10 @@ import './phase3-post-signal';
|
||||||
import './phase4-test';
|
import './phase4-test';
|
||||||
import '../../backbone/reliable_trigger';
|
import '../../backbone/reliable_trigger';
|
||||||
|
|
||||||
import type { CdsLookupOptionsType } from '../../textsecure/WebAPI';
|
import type {
|
||||||
|
CdsLookupOptionsType,
|
||||||
|
GetIceServersResultType,
|
||||||
|
} from '../../textsecure/WebAPI';
|
||||||
import type { FeatureFlagType } from '../../window.d';
|
import type { FeatureFlagType } from '../../window.d';
|
||||||
import type { StorageAccessType } from '../../types/Storage.d';
|
import type { StorageAccessType } from '../../types/Storage.d';
|
||||||
import { start as startConversationController } from '../../ConversationController';
|
import { start as startConversationController } from '../../ConversationController';
|
||||||
|
@ -71,13 +74,18 @@ if (!isProduction(window.SignalContext.getVersion())) {
|
||||||
setSfuUrl: (url: string) => {
|
setSfuUrl: (url: string) => {
|
||||||
window.Signal.Services.calling._sfuUrl = url;
|
window.Signal.Services.calling._sfuUrl = url;
|
||||||
},
|
},
|
||||||
setIceServerOverride: (url: string) => {
|
setIceServerOverride: (
|
||||||
if (!/(turn|turns|stun):.*]/.test(url)) {
|
override: GetIceServersResultType | string | undefined
|
||||||
log.warn(
|
) => {
|
||||||
'Override url should be prefixed with `turn:`, `turns:`, or `stun:` else override may not work'
|
if (typeof override === 'string') {
|
||||||
);
|
if (!/(turn|turns|stun):.*/.test(override)) {
|
||||||
|
log.warn(
|
||||||
|
'Override url should be prefixed with `turn:`, `turns:`, or `stun:` else override may not work'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.Signal.Services.calling._iceServerOverride = url;
|
|
||||||
|
window.Signal.Services.calling._iceServerOverride = override;
|
||||||
},
|
},
|
||||||
sqlCall: (name: string, ...args: ReadonlyArray<unknown>) =>
|
sqlCall: (name: string, ...args: ReadonlyArray<unknown>) =>
|
||||||
ipcInvoke(name, args),
|
ipcInvoke(name, args),
|
||||||
|
|
Loading…
Reference in a new issue