mirror of
https://github.com/jambonz/chrome-extension-dialer.git
synced 2025-12-19 04:47:45 +00:00
feat user restriction
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
FetchError,
|
||||
FetchTransport,
|
||||
Queue,
|
||||
RegisteredUser,
|
||||
StatusCodes,
|
||||
} from "./types";
|
||||
import { MSG_SOMETHING_WRONG } from "./constants";
|
||||
@@ -144,3 +145,10 @@ export const getQueues = () => {
|
||||
`${advancedSettings.apiServer}/Accounts/${advancedSettings.accountSid}/Queues`
|
||||
);
|
||||
};
|
||||
|
||||
export const getSelfRegisteredUser = (username: string) => {
|
||||
const advancedSettings = getAdvancedSettings();
|
||||
return getFetch<RegisteredUser>(
|
||||
`${advancedSettings.apiServer}/Accounts/${advancedSettings.accountSid}/RegisteredSipUsers/${username}`
|
||||
);
|
||||
};
|
||||
|
||||
@@ -34,3 +34,14 @@ export interface Queue {
|
||||
name: string;
|
||||
length: number;
|
||||
}
|
||||
|
||||
export interface RegisteredUser {
|
||||
name: string;
|
||||
contact: string;
|
||||
expiryTime: number;
|
||||
protocol: string;
|
||||
allow_direct_app_calling: boolean;
|
||||
allow_direct_queue_calling: boolean;
|
||||
allow_direct_user_calling: boolean;
|
||||
registered_status: string;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,15 @@ import {
|
||||
import { OutGoingCall } from "./outgoing-call";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import IconButtonMenu, { IconButtonMenuItems } from "src/components/menu";
|
||||
import { getApplications, getQueues, getRegisteredUser } from "src/api";
|
||||
import {
|
||||
getApplications,
|
||||
getQueues,
|
||||
getRegisteredUser,
|
||||
getSelfRegisteredUser,
|
||||
} from "src/api";
|
||||
import JambonzSwitch from "src/components/switch";
|
||||
import { DEFAULT_TOAST_DURATION } from "src/common/constants";
|
||||
import { RegisteredUser } from "src/api/types";
|
||||
|
||||
type PhoneProbs = {
|
||||
sipDomain: string;
|
||||
@@ -100,6 +106,13 @@ export const Phone = ({
|
||||
const sipDisplayNameRef = useRef("");
|
||||
const [isForceChangeUaStatus, setIsForceChangeUaStatus] = useState(false);
|
||||
const isInputNumberFocusRef = useRef(false);
|
||||
const [registeredUser, setRegisteredUser] = useState<Partial<RegisteredUser>>(
|
||||
{
|
||||
allow_direct_app_calling: false,
|
||||
allow_direct_queue_calling: false,
|
||||
allow_direct_user_calling: false,
|
||||
}
|
||||
);
|
||||
const toast = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -162,6 +175,17 @@ export const Phone = ({
|
||||
}
|
||||
}, [status]);
|
||||
|
||||
useEffect(() => {
|
||||
getSelfRegisteredUser(sipUsernameRef.current).then(({ json }) => {
|
||||
setRegisteredUser(json);
|
||||
});
|
||||
setInterval(() => {
|
||||
getSelfRegisteredUser(sipUsernameRef.current).then(({ json }) => {
|
||||
setRegisteredUser(json);
|
||||
});
|
||||
}, 20000);
|
||||
}, []);
|
||||
|
||||
// useEffect(() => {
|
||||
// chrome.runtime.onMessage.addListener(function (request) {
|
||||
// const msg = request as Message<any>;
|
||||
@@ -478,6 +502,7 @@ export const Phone = ({
|
||||
>
|
||||
{isAdvanceMode && isSipClientIdle(callStatus) && (
|
||||
<HStack spacing={2} align="start" w="full">
|
||||
{registeredUser.allow_direct_user_calling && (
|
||||
<IconButtonMenu
|
||||
icon={<Users />}
|
||||
tooltip="Call an online user"
|
||||
@@ -508,6 +533,9 @@ export const Phone = ({
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{registeredUser.allow_direct_queue_calling && (
|
||||
<IconButtonMenu
|
||||
icon={<List />}
|
||||
tooltip="Take a call from queue"
|
||||
@@ -535,7 +563,9 @@ export const Phone = ({
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{registeredUser.allow_direct_app_calling && (
|
||||
<IconButtonMenu
|
||||
icon={<GitMerge />}
|
||||
tooltip="Call an application"
|
||||
@@ -563,6 +593,7 @@ export const Phone = ({
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</HStack>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user