forked from github/cinny
prepare for juggling iframes and handling hang up appropriately
This commit is contained in:
@@ -77,7 +77,7 @@ export function CallProvider({ children }: CallProviderProps) {
|
|||||||
logger.debug('CallContext: Resetting media state to defaults.');
|
logger.debug('CallContext: Resetting media state to defaults.');
|
||||||
setIsAudioEnabledState(DEFAULT_AUDIO_ENABLED);
|
setIsAudioEnabledState(DEFAULT_AUDIO_ENABLED);
|
||||||
setIsVideoEnabledState(DEFAULT_VIDEO_ENABLED);
|
setIsVideoEnabledState(DEFAULT_VIDEO_ENABLED);
|
||||||
setIsChatOpenState(DEFAULT_CHAT_OPENED);
|
//setIsChatOpenState(DEFAULT_CHAT_OPENED);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setActiveCallRoomId = useCallback(
|
const setActiveCallRoomId = useCallback(
|
||||||
@@ -104,13 +104,14 @@ export function CallProvider({ children }: CallProviderProps) {
|
|||||||
|
|
||||||
const hangUp = useCallback(() => {
|
const hangUp = useCallback(() => {
|
||||||
logger.debug(`CallContext: Hang up called.`);
|
logger.debug(`CallContext: Hang up called.`);
|
||||||
// activeClientWidgetApi?.transport.send(`action:${WIDGET_HANGUP_ACTION}`, {});
|
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
||||||
setActiveCallRoomIdState(null);
|
setIsCallActive(false);
|
||||||
logger.debug(`CallContext: Clearing active clientWidgetApi due to hangup.`);
|
//setActiveCallRoomId(null);
|
||||||
setActiveClientWidgetApiState(null);
|
//setActiveCallRoomIdState(null);
|
||||||
setClientWidgetApiRoomId(null);
|
//logger.debug(`CallContext: Clearing active clientWidgetApi due to hangup.`);
|
||||||
resetMediaState();
|
//setActiveClientWidgetApiState(null);
|
||||||
}, [resetMediaState]);
|
//setClientWidgetApiRoomId(null);
|
||||||
|
}, [activeClientWidgetApi?.transport]);
|
||||||
|
|
||||||
const setActiveClientWidgetApi = useCallback(
|
const setActiveClientWidgetApi = useCallback(
|
||||||
(clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => {
|
(clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => {
|
||||||
@@ -145,7 +146,12 @@ export function CallProvider({ children }: CallProviderProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeClientWidgetApi || !activeCallRoomId || clientWidgetApiRoomId !== activeCallRoomId) {
|
if (
|
||||||
|
!activeClientWidgetApi ||
|
||||||
|
!activeCallRoomId ||
|
||||||
|
clientWidgetApiRoomId !== activeCallRoomId ||
|
||||||
|
isCallActive
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +166,7 @@ export function CallProvider({ children }: CallProviderProps) {
|
|||||||
ev
|
ev
|
||||||
);
|
);
|
||||||
setIsCallActive(false);
|
setIsCallActive(false);
|
||||||
// hangUp();
|
//hangUp();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMediaStateUpdate = (ev: CustomEvent<MediaStatePayload>) => {
|
const handleMediaStateUpdate = (ev: CustomEvent<MediaStatePayload>) => {
|
||||||
@@ -203,8 +209,8 @@ export function CallProvider({ children }: CallProviderProps) {
|
|||||||
`CallContext: Cleaning up listeners for clientWidgetApi in room ${activeCallRoomId}`
|
`CallContext: Cleaning up listeners for clientWidgetApi in room ${activeCallRoomId}`
|
||||||
);
|
);
|
||||||
if (clientWidgetApi) {
|
if (clientWidgetApi) {
|
||||||
clientWidgetApi.off(`action:${WIDGET_HANGUP_ACTION}`, handleHangup);
|
//clientWidgetApi.off(`action:${WIDGET_HANGUP_ACTION}`, handleHangup);
|
||||||
clientWidgetApi.off(`action:${WIDGET_MEDIA_STATE_UPDATE_ACTION}`, handleMediaStateUpdate);
|
//clientWidgetApi.off(`action:${WIDGET_MEDIA_STATE_UPDATE_ACTION}`, handleMediaStateUpdate);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
|
|||||||
Reference in New Issue
Block a user