diff --git a/ts/services/calling.ts b/ts/services/calling.ts index 7bc3f82d376..782c121fd1e 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -88,7 +88,10 @@ import * as durations from '../util/durations'; import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary'; import { fetchMembershipProof, getMembershipList } from '../groups'; import type { ProcessedEnvelope } from '../textsecure/Types.d'; -import type { GetIceServersResultType } from '../textsecure/WebAPI'; +import type { + GetIceServersResultType, + IceServerGroupType, +} from '../textsecure/WebAPI'; import { missingCaseError } from '../util/missingCaseError'; import { normalizeGroupCallTimestamp } from '../util/ringrtc/normalizeGroupCallTimestamp'; import { @@ -3144,20 +3147,32 @@ export class CallingClass { function iceServerConfigToList( iceServerConfig: GetIceServersResultType ): Array { - 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(), - }, - ]; + function mapConfig( + iceServerGroup: GetIceServersResultType | IceServerGroupType + ): Array { + if (!iceServerGroup.username || !iceServerGroup.password) { + return []; + } + + return [ + { + hostname: iceServerGroup.hostname ?? '', + username: iceServerGroup.username, + password: iceServerGroup.password, + urls: (iceServerGroup.urlsWithIps ?? []).slice(), + }, + { + hostname: '', + username: iceServerGroup.username, + password: iceServerGroup.password, + urls: (iceServerGroup.urls ?? []).slice(), + }, + ]; + } + + return [iceServerConfig] + .concat(iceServerConfig.iceServers ?? []) + .flatMap(mapConfig); } if (!window.textsecure.messaging) { diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 8ac6c933798..dbc277a7dfc 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -857,6 +857,15 @@ export type GetAccountForUsernameResultType = z.infer< >; export type GetIceServersResultType = Readonly<{ + username?: string; + password?: string; + urls?: ReadonlyArray; + urlsWithIps?: ReadonlyArray; + hostname?: string; + iceServers?: ReadonlyArray; +}>; + +export type IceServerGroupType = Readonly<{ username: string; password: string; urls?: ReadonlyArray;