Don't treat empty object as a valid sfu config
This was causing an extra reconnect cycle when the call was first joined because it thought the previous SFU config was valid. This was probably causing some client to fail to connect at all.
This commit is contained in:
@@ -36,6 +36,12 @@ export enum ECAddonConnectionState {
|
|||||||
|
|
||||||
export type ECConnectionState = ConnectionState | ECAddonConnectionState;
|
export type ECConnectionState = ConnectionState | ECAddonConnectionState;
|
||||||
|
|
||||||
|
// This is mostly necessary because an empty useRef is an empty object
|
||||||
|
// which is truthy, so we can't just use Boolean(currentSFUConfig.current)
|
||||||
|
function sfuConfigValid(sfuConfig?: SFUConfig): boolean {
|
||||||
|
return Boolean(sfuConfig?.url) && Boolean(sfuConfig?.jwt);
|
||||||
|
}
|
||||||
|
|
||||||
export function useECConnectionState(
|
export function useECConnectionState(
|
||||||
livekitRoom?: Room,
|
livekitRoom?: Room,
|
||||||
sfuConfig?: SFUConfig
|
sfuConfig?: SFUConfig
|
||||||
@@ -68,18 +74,22 @@ export function useECConnectionState(
|
|||||||
|
|
||||||
const currentSFUConfig = useRef(Object.assign({}, sfuConfig));
|
const currentSFUConfig = useRef(Object.assign({}, sfuConfig));
|
||||||
|
|
||||||
|
// Id we are transitioning from a valid config to another valid one, we need
|
||||||
|
// to explicitly switch focus
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
sfuConfig &&
|
sfuConfigValid(sfuConfig) &&
|
||||||
currentSFUConfig.current &&
|
sfuConfigValid(currentSFUConfig.current) &&
|
||||||
!sfuConfigEquals(currentSFUConfig.current, sfuConfig)
|
!sfuConfigEquals(currentSFUConfig.current, sfuConfig)
|
||||||
) {
|
) {
|
||||||
logger.info("JWT changed!");
|
logger.info(
|
||||||
|
`SFU config changed! URL was ${currentSFUConfig.current?.url} now ${sfuConfig?.url}`
|
||||||
|
);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
setSwitchingFocus(true);
|
setSwitchingFocus(true);
|
||||||
await livekitRoom?.disconnect();
|
await livekitRoom?.disconnect();
|
||||||
await livekitRoom?.connect(sfuConfig.url, sfuConfig.jwt);
|
await livekitRoom?.connect(sfuConfig!.url, sfuConfig!.jwt);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user