Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom ice servers in join config #2884

Merged
merged 27 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2a750ab
fix: update join config types
KaustubhKumar05 May 9, 2024
96ef8a5
fix: use proxy for init if provided
KaustubhKumar05 May 9, 2024
c5c8811
feat: forward passed ice servers
KaustubhKumar05 May 9, 2024
8304bda
fix: clean up
KaustubhKumar05 May 9, 2024
4159c6f
Merge branch 'dev' into WEB-2806
KaustubhKumar05 May 9, 2024
5467983
fix: revert changes to yarn.lock
KaustubhKumar05 May 9, 2024
4bfa560
fix: transform ice server config
KaustubhKumar05 May 9, 2024
2e551e2
Merge branch 'dev' into WEB-2806
KaustubhKumar05 May 13, 2024
d451dbc
fix: username casing
KaustubhKumar05 May 13, 2024
a24d48a
fix: username casing
KaustubhKumar05 May 13, 2024
9675181
fix: support proxy and ice servers in usepreviewjoin
KaustubhKumar05 May 14, 2024
57df547
fix: cleanup
KaustubhKumar05 May 15, 2024
394b161
fix: builds
KaustubhKumar05 May 15, 2024
90ffed1
fix: revert yarn lock changes
KaustubhKumar05 May 15, 2024
d2c745a
fix: revert yarn lock changes
KaustubhKumar05 May 15, 2024
f238c30
fix: builds
KaustubhKumar05 May 15, 2024
46712ec
fix: builds
KaustubhKumar05 May 15, 2024
16bac01
fix: revert extra endpoint changes
KaustubhKumar05 May 16, 2024
87c5b8e
fix: revert extra changes
KaustubhKumar05 May 16, 2024
ca28beb
fix: support https proxy
KaustubhKumar05 May 16, 2024
ee583cf
fix: revert proxy changes
KaustubhKumar05 May 17, 2024
bee8761
Merge branch 'dev' into WEB-2806
raviteja83 May 17, 2024
5628068
fix: review comments
KaustubhKumar05 May 17, 2024
c29d3a7
fix: conflict
KaustubhKumar05 May 17, 2024
23758da
fix: check for custom ice server config
KaustubhKumar05 May 17, 2024
271498b
fix: check for custom ice server config
KaustubhKumar05 May 17, 2024
054fe8c
fix: props
KaustubhKumar05 May 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/hms-video-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type {
HMSQuizLeaderboardResponse,
HMSQuizLeaderboardSummary,
HMSTranscriptionInfo,
HMSICEServer,
} from './internal';

export { EventBus } from './events/EventBus';
Expand Down
13 changes: 12 additions & 1 deletion packages/hms-video-store/src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import InitialSettings from './settings';
* @link https://docs.100ms.live/javascript/v2/features/preview
* @link https://docs.100ms.live/javascript/v2/features/join
*/

export type HMSICEServer = {
urls: string[];
userName?: string;
password?: string;
};

export interface HMSConfig {
/**
* the name of the peer, can be later accessed via peer.name and can also be changed mid call.
Expand Down Expand Up @@ -53,10 +60,14 @@ export interface HMSConfig {
*/
autoManageVideo?: boolean;
/**
* if this flag is enabled, wake lock will be acquired automatically(if supported) when joining the room, so the device
* if this flag is enabled, wake lock will be acquired automatically (if supported) when joining the room, so the device
* will be kept awake.
*/
autoManageWakeLock?: boolean;
/**
* use custom STUN/TURN servers for media connection (advanced)
*/
iceServers?: HMSICEServer[];
}

export interface HMSMidCallPreviewConfig {
Expand Down
1 change: 1 addition & 0 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export class HMSSdk implements HMSInterface {
this.localPeer!.peerId,
{ name: config.userName, metaData: config.metaData || '' },
config.autoVideoSubscribe,
config.iceServers,
)
.then((initConfig: InitConfig | void) => {
initSuccessful = true;
Expand Down
17 changes: 11 additions & 6 deletions packages/hms-video-store/src/signal/init/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { InitConfig } from './models';
import { ErrorFactory } from '../../error/ErrorFactory';
import { HMSAction } from '../../error/HMSAction';
import { HMSICEServer } from '../../interfaces';
import { transformIceServerConfig } from '../../utils/ice-server-config';
import HMSLogger from '../../utils/logger';

const TAG = '[InitService]';
Expand All @@ -26,26 +28,26 @@ export default class InitService {
userAgent,
initEndpoint = 'https://prod-init.100ms.live',
region = '',
iceServers,
}: {
token: string;
peerId: string;
userAgent: string;
initEndpoint?: string;
region?: string;
iceServers?: HMSICEServer[];
}): Promise<InitConfig> {
HMSLogger.d(TAG, `fetchInitConfig: initEndpoint=${initEndpoint} token=${token} peerId=${peerId} region=${region} `);
const url = getUrl(initEndpoint, peerId, userAgent, region);
try {
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
headers: { Authorization: `Bearer ${token}` },
});
try {
const config = await response.clone().json();
this.handleError(response, config);
HMSLogger.d(TAG, `config is ${JSON.stringify(config, null, 2)}`);
return transformInitConfig(config);
return transformInitConfig(config, iceServers);
} catch (err) {
const text = await response.text();
HMSLogger.e(TAG, 'json error', (err as Error).message, text);
Expand Down Expand Up @@ -78,9 +80,12 @@ export function getUrl(endpoint: string, peerId: string, userAgent: string, regi
}
}

export function transformInitConfig(config: any): InitConfig {
export function transformInitConfig(config: any, iceServers?: HMSICEServer[]): InitConfig {
return {
...config,
rtcConfiguration: { ...config.rtcConfiguration, iceServers: config.rtcConfiguration?.ice_servers },
rtcConfiguration: {
...config.rtcConfiguration,
iceServers: transformIceServerConfig(config.rtcConfiguration?.ice_servers, iceServers),
},
};
}
15 changes: 10 additions & 5 deletions packages/hms-video-store/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ErrorFactory } from '../error/ErrorFactory';
import { HMSAction } from '../error/HMSAction';
import { HMSException } from '../error/HMSException';
import { EventBus } from '../events/EventBus';
import { HMSRole } from '../interfaces';
import { HMSICEServer, HMSRole } from '../interfaces';
import { HMSLocalStream } from '../media/streams/HMSLocalStream';
import { HMSLocalTrack, HMSLocalVideoTrack, HMSTrack } from '../media/tracks';
import { TrackState } from '../notification-manager';
Expand Down Expand Up @@ -397,8 +397,9 @@ export default class HMSTransport {
peerId: string,
customData: { name: string; metaData: string },
autoSubscribeVideo = false,
iceServers?: HMSICEServer[],
): Promise<InitConfig | void> {
const initConfig = await this.connect(token, endpoint, peerId, customData, autoSubscribeVideo);
const initConfig = await this.connect(token, endpoint, peerId, customData, autoSubscribeVideo, iceServers);
this.state = TransportState.Preview;
this.observer.onStateChange(this.state);
return initConfig;
Expand Down Expand Up @@ -447,6 +448,7 @@ export default class HMSTransport {
peerId: string,
customData: { name: string; metaData: string },
autoSubscribeVideo = false,
iceServers?: HMSICEServer[],
): Promise<InitConfig | void> {
this.setTransportStateForConnect();
this.joinParameters = new JoinParameters(
Expand All @@ -456,9 +458,10 @@ export default class HMSTransport {
customData.metaData,
endpoint,
autoSubscribeVideo,
iceServers,
);
try {
const response = await this.internalConnect(token, endpoint, peerId);
const response = await this.internalConnect(token, endpoint, peerId, iceServers);
return response;
} catch (error) {
const shouldRetry =
Expand All @@ -474,7 +477,7 @@ export default class HMSTransport {

if (shouldRetry) {
const task = async () => {
await this.internalConnect(token, endpoint, peerId);
await this.internalConnect(token, endpoint, peerId, iceServers);
return Boolean(this.initConfig && this.initConfig.endpoint);
};

Expand Down Expand Up @@ -898,7 +901,7 @@ export default class HMSTransport {
}
}

private async internalConnect(token: string, initEndpoint: string, peerId: string) {
private async internalConnect(token: string, initEndpoint: string, peerId: string, iceServers?: HMSICEServer[]) {
HMSLogger.d(TAG, 'connect: started ⏰');
const connectRequestedAt = new Date();
try {
Expand All @@ -908,6 +911,7 @@ export default class HMSTransport {
peerId,
userAgent: this.store.getUserAgent(),
initEndpoint,
iceServers,
});
const room = this.store.getRoom();
if (room) {
Expand Down Expand Up @@ -1093,6 +1097,7 @@ export default class HMSTransport {
this.joinParameters!.authToken,
this.joinParameters!.endpoint,
this.joinParameters!.peerId,
this.joinParameters!.iceServers,
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HMSICEServer } from '../../interfaces';

export class JoinParameters {
constructor(
public authToken: string,
Expand All @@ -6,5 +8,6 @@ export class JoinParameters {
public data: string = '',
public endpoint: string = 'https://prod-init.100ms.live/init',
public autoSubscribeVideo: boolean = false,
public iceServers?: HMSICEServer[],
) {}
}
11 changes: 11 additions & 0 deletions packages/hms-video-store/src/utils/ice-server-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HMSICEServer } from '../interfaces';

export const transformIceServerConfig = (defaultConfig?: RTCIceServer[], iceServers?: HMSICEServer[]) => {
if (!iceServers || iceServers.length === 0) {
return defaultConfig;
}
const transformedIceServers = iceServers.map(server => {
return { urls: server.urls, credentialType: 'password', credential: server.password, username: server.userName };
});
return transformedIceServers;
};
9 changes: 9 additions & 0 deletions packages/react-sdk/src/hooks/usePreviewJoin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo } from 'react';
import {
HMSConfigInitialSettings,
HMSICEServer,
HMSPreviewConfig,
HMSRoomState,
selectIsConnectedToRoom,
Expand Down Expand Up @@ -51,6 +52,11 @@ export interface usePreviewInput {
* will be kept awake.
*/
autoManageWakeLock?: boolean;

/**
* use custom STUN/TURN servers for media connection (advanced)
*/
iceServers?: HMSICEServer[];
}

export interface usePreviewResult {
Expand Down Expand Up @@ -90,6 +96,7 @@ export const usePreviewJoin = ({
asRole,
autoManageVideo,
autoManageWakeLock,
iceServers,
}: usePreviewInput): usePreviewResult => {
const actions = useHMSActions();
const roomState = useHMSStore(selectRoomState);
Expand All @@ -108,6 +115,7 @@ export const usePreviewJoin = ({
captureNetworkQualityInPreview,
autoManageVideo,
autoManageWakeLock,
iceServers,
};
}, [
name,
Expand All @@ -119,6 +127,7 @@ export const usePreviewJoin = ({
asRole,
autoManageVideo,
autoManageWakeLock,
iceServers,
]);

const preview = useCallback(async () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17941,4 +17941,4 @@ [email protected]:
zustand@^3.6.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-3.7.2.tgz#7b44c4f4a5bfd7a8296a3957b13e1c346f42514d"
integrity sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==
integrity sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==
Loading