[MM-45001] Add support for generating short-lived TURN credentials (#6404)
* Generate TURN credentials if needed * Reduce calls to getState
This commit is contained in:
parent
11136e7cf6
commit
ed6daffa0c
4 changed files with 18 additions and 3 deletions
|
|
@ -59,6 +59,13 @@ const ClientCalls = (superclass: any) => class extends superclass {
|
|||
{method: 'post'},
|
||||
);
|
||||
};
|
||||
|
||||
genTURNCredentials = async () => {
|
||||
return this.doFetch(
|
||||
`${this.getCallsRoute()}/turn-credentials`,
|
||||
{method: 'get'},
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default ClientCalls;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,13 @@ export function joinCall(channelId: string, intl: typeof intlShape): ActionFunc
|
|||
dispatch(setSpeakerphoneOn(false));
|
||||
|
||||
try {
|
||||
ws = await newClient(channelId, getICEServersConfigs(getState()), () => {
|
||||
const state = getState();
|
||||
const iceConfigs = [...getICEServersConfigs(state)];
|
||||
if (getConfig(state).NeedsTURNCredentials) {
|
||||
iceConfigs.push(...await Client4.genTURNCredentials());
|
||||
}
|
||||
|
||||
ws = await newClient(channelId, iceConfigs, () => {
|
||||
dispatch(setSpeakerphoneOn(false));
|
||||
dispatch({type: CallsTypes.RECEIVED_MYSELF_LEFT_CALL});
|
||||
}, setScreenShareURL);
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ export type ServerConfig = {
|
|||
AllowEnableCalls: boolean;
|
||||
DefaultEnabled: boolean;
|
||||
MaxCallParticipants: number;
|
||||
NeedsTURNCredentials: boolean;
|
||||
sku_short_name: string;
|
||||
last_retrieved_at: number;
|
||||
}
|
||||
|
|
@ -76,8 +77,9 @@ export const DefaultServerConfig = {
|
|||
AllowEnableCalls: false,
|
||||
DefaultEnabled: false,
|
||||
MaxCallParticipants: 0,
|
||||
NeedsTURNCredentials: false,
|
||||
sku_short_name: '',
|
||||
last_retrieved_at: 0,
|
||||
} as ServerConfig;
|
||||
|
||||
export type ICEServersConfigs = ConfigurationParamWithUrls[] | ConfigurationParamWithUrl[];
|
||||
export type ICEServersConfigs = Array<ConfigurationParamWithUrls | ConfigurationParamWithUrl>;
|
||||
|
|
|
|||
2
types/modules/react-native-webrtc.d.ts
vendored
2
types/modules/react-native-webrtc.d.ts
vendored
|
|
@ -168,7 +168,7 @@ declare module 'react-native-webrtc' {
|
|||
}
|
||||
|
||||
export interface RTCPeerConnectionConfiguration {
|
||||
iceServers: ConfigurationParamWithUrls[] | ConfigurationParamWithUrl[];
|
||||
iceServers: Array<ConfigurationParamWithUrls | ConfigurationParamWithUrl>;
|
||||
iceTransportPolicy?: 'all' | 'relay' | 'nohost' | 'none' | undefined;
|
||||
bundlePolicy?: 'balanced' | 'max-compat' | 'max-bundle' | undefined;
|
||||
rtcpMuxPolicy?: 'negotiate' | 'require' | undefined;
|
||||
|
|
|
|||
Loading…
Reference in a new issue