mirror of
https://github.com/jambonz/chrome-extension-dialer.git
synced 2025-12-19 04:47:45 +00:00
Merge pull request #37 from jambonz/feat/fix_null_settings
fixed null setting if remove active account
This commit is contained in:
@@ -91,12 +91,18 @@ export const setActiveSettings = (id: number) => {
|
|||||||
export const deleteSettings = (id: number) => {
|
export const deleteSettings = (id: number) => {
|
||||||
const str = localStorage.getItem(SETTINGS_KEY);
|
const str = localStorage.getItem(SETTINGS_KEY);
|
||||||
if (str) {
|
if (str) {
|
||||||
const parsed = JSON.parse(str);
|
const parsed = JSON.parse(str) as saveSettingFormat[];
|
||||||
|
|
||||||
// for edit:
|
const setting = parsed.find((s) => s.id === id);
|
||||||
const newData = parsed.filter((el: saveSettingFormat) => el.id !== id);
|
|
||||||
|
|
||||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(newData));
|
const newSettings = parsed.filter((el) => el.id !== id);
|
||||||
|
|
||||||
|
// deleting active account, reassign active to next account
|
||||||
|
if (setting?.active && newSettings.length) {
|
||||||
|
newSettings[0].active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(SETTINGS_KEY, JSON.stringify(newSettings));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,14 +132,16 @@ export const getActiveSettings = (): IAppSettings => {
|
|||||||
JSON.parse(str);
|
JSON.parse(str);
|
||||||
|
|
||||||
const activeSettings = parsed.find((el) => el.active);
|
const activeSettings = parsed.find((el) => el.active);
|
||||||
const decoded = {
|
if (activeSettings) {
|
||||||
active: activeSettings?.active,
|
const decoded = {
|
||||||
decoded: JSON.parse(
|
active: activeSettings?.active,
|
||||||
Buffer.from(activeSettings?.encoded!, "base64").toString("utf-8")
|
decoded: JSON.parse(
|
||||||
),
|
Buffer.from(activeSettings.encoded, "base64").toString("utf-8")
|
||||||
id: activeSettings?.id,
|
),
|
||||||
};
|
id: activeSettings.id,
|
||||||
return decoded as IAppSettings;
|
};
|
||||||
|
return decoded as IAppSettings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {} as IAppSettings;
|
return {} as IAppSettings;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ export const Phone = forwardRef(
|
|||||||
) => {
|
) => {
|
||||||
const [inputNumber, setInputNumber] = useState("");
|
const [inputNumber, setInputNumber] = useState("");
|
||||||
const [appName, setAppName] = useState("");
|
const [appName, setAppName] = useState("");
|
||||||
const [isConfigured, setIsConfigured] = useState(false);
|
|
||||||
const [callStatus, setCallStatus] = useState(SipConstants.SESSION_ENDED);
|
const [callStatus, setCallStatus] = useState(SipConstants.SESSION_ENDED);
|
||||||
const [sessionDirection, setSessionDirection] =
|
const [sessionDirection, setSessionDirection] =
|
||||||
useState<SipCallDirection>("");
|
useState<SipCallDirection>("");
|
||||||
@@ -145,6 +144,7 @@ export const Phone = forwardRef(
|
|||||||
const sessionDirectionRef = useRef(sessionDirection);
|
const sessionDirectionRef = useRef(sessionDirection);
|
||||||
const sipUA = useRef<SipUA | null>(null);
|
const sipUA = useRef<SipUA | null>(null);
|
||||||
const timerRef = useRef<NodeJS.Timer | null>(null);
|
const timerRef = useRef<NodeJS.Timer | null>(null);
|
||||||
|
const FetchUsertimerRef = useRef<NodeJS.Timer | null>(null);
|
||||||
const isRestartRef = useRef(false);
|
const isRestartRef = useRef(false);
|
||||||
const sipDomainRef = useRef("");
|
const sipDomainRef = useRef("");
|
||||||
const sipUsernameRef = useRef("");
|
const sipUsernameRef = useRef("");
|
||||||
@@ -299,7 +299,7 @@ export const Phone = forwardRef(
|
|||||||
setStatus,
|
setStatus,
|
||||||
startCallDurationCounter,
|
startCallDurationCounter,
|
||||||
toast,
|
toast,
|
||||||
setIsOnline
|
setIsOnline,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -319,19 +319,9 @@ export const Phone = forwardRef(
|
|||||||
} else {
|
} else {
|
||||||
createSipClient();
|
createSipClient();
|
||||||
}
|
}
|
||||||
setIsConfigured(true);
|
|
||||||
} else {
|
} else {
|
||||||
setIsConfigured(false);
|
|
||||||
clientGoOffline();
|
clientGoOffline();
|
||||||
}
|
}
|
||||||
fetchRegisterUser();
|
|
||||||
getConferences()
|
|
||||||
?.then(() => {
|
|
||||||
setShowConference(true);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setShowConference(false);
|
|
||||||
});
|
|
||||||
}, [
|
}, [
|
||||||
sipDomain,
|
sipDomain,
|
||||||
sipUsername,
|
sipUsername,
|
||||||
@@ -405,14 +395,31 @@ export const Phone = forwardRef(
|
|||||||
}
|
}
|
||||||
}, [status, setIsOnline, setIsSwitchingUserStatus]);
|
}, [status, setIsOnline, setIsSwitchingUserStatus]);
|
||||||
|
|
||||||
|
const clearFetchUserTimer = () => {
|
||||||
|
if (FetchUsertimerRef.current) {
|
||||||
|
clearInterval(FetchUsertimerRef.current);
|
||||||
|
FetchUsertimerRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setInterval(() => {
|
if (isAdvanceMode) {
|
||||||
fetchRegisterUser();
|
// check conference aibility
|
||||||
}, 10000);
|
getConferences()
|
||||||
return () => {
|
.then(() => {
|
||||||
clearInterval(timer);
|
setShowConference(true);
|
||||||
};
|
})
|
||||||
}, []);
|
.catch(() => {
|
||||||
|
setShowConference(false);
|
||||||
|
});
|
||||||
|
FetchUsertimerRef.current = setInterval(() => {
|
||||||
|
fetchRegisterUser();
|
||||||
|
}, 10_000);
|
||||||
|
} else {
|
||||||
|
clearFetchUserTimer();
|
||||||
|
setShowConference(false);
|
||||||
|
}
|
||||||
|
}, [isAdvanceMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (showAccounts) {
|
if (showAccounts) {
|
||||||
@@ -553,9 +560,7 @@ export const Phone = forwardRef(
|
|||||||
const handleSetActive = (id: number) => {
|
const handleSetActive = (id: number) => {
|
||||||
setActiveSettings(id);
|
setActiveSettings(id);
|
||||||
setShowAccounts(false);
|
setShowAccounts(false);
|
||||||
// fetchRegisterUser();
|
|
||||||
reload();
|
reload();
|
||||||
// window.location.reload();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickOutside = (event: Event) => {
|
const handleClickOutside = (event: Event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user