calling: add support for multiple ice server groups in GetIceServers

This commit is contained in:
adel-signal 2024-10-10 17:24:45 -07:00 committed by GitHub
parent 2818a3c8fc
commit f3aae86796
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 15 deletions

View file

@ -88,7 +88,10 @@ 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 type {
GetIceServersResultType,
IceServerGroupType,
} 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 {
@ -3145,22 +3148,34 @@ export class CallingClass {
function iceServerConfigToList( function iceServerConfigToList(
iceServerConfig: GetIceServersResultType iceServerConfig: GetIceServersResultType
): Array<IceServer> { ): Array<IceServer> {
function mapConfig(
iceServerGroup: GetIceServersResultType | IceServerGroupType
): Array<IceServer> {
if (!iceServerGroup.username || !iceServerGroup.password) {
return [];
}
return [ return [
{ {
hostname: iceServerConfig.hostname ?? '', hostname: iceServerGroup.hostname ?? '',
username: iceServerConfig.username, username: iceServerGroup.username,
password: iceServerConfig.password, password: iceServerGroup.password,
urls: (iceServerConfig.urlsWithIps ?? []).slice(), urls: (iceServerGroup.urlsWithIps ?? []).slice(),
}, },
{ {
hostname: '', hostname: '',
username: iceServerConfig.username, username: iceServerGroup.username,
password: iceServerConfig.password, password: iceServerGroup.password,
urls: (iceServerConfig.urls ?? []).slice(), urls: (iceServerGroup.urls ?? []).slice(),
}, },
]; ];
} }
return [iceServerConfig]
.concat(iceServerConfig.iceServers ?? [])
.flatMap(mapConfig);
}
if (!window.textsecure.messaging) { if (!window.textsecure.messaging) {
log.error('handleStartCall: offline!'); log.error('handleStartCall: offline!');
return false; return false;

View file

@ -861,6 +861,15 @@ export type GetAccountForUsernameResultType = z.infer<
>; >;
export type GetIceServersResultType = Readonly<{ export type GetIceServersResultType = Readonly<{
username?: string;
password?: string;
urls?: ReadonlyArray<string>;
urlsWithIps?: ReadonlyArray<string>;
hostname?: string;
iceServers?: ReadonlyArray<IceServerGroupType>;
}>;
export type IceServerGroupType = Readonly<{
username: string; username: string;
password: string; password: string;
urls?: ReadonlyArray<string>; urls?: ReadonlyArray<string>;