mirror of
https://github.com/jambonz/chrome-extension-dialer.git
synced 2026-01-25 02:08:05 +00:00
Merge pull request #28 from jambonz/feat/user_restriction
feat user restriction
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
|||||||
FetchError,
|
FetchError,
|
||||||
FetchTransport,
|
FetchTransport,
|
||||||
Queue,
|
Queue,
|
||||||
|
RegisteredUser,
|
||||||
StatusCodes,
|
StatusCodes,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { MSG_SOMETHING_WRONG } from "./constants";
|
import { MSG_SOMETHING_WRONG } from "./constants";
|
||||||
@@ -144,3 +145,10 @@ export const getQueues = () => {
|
|||||||
`${advancedSettings.apiServer}/Accounts/${advancedSettings.accountSid}/Queues`
|
`${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;
|
name: string;
|
||||||
length: number;
|
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 { OutGoingCall } from "./outgoing-call";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import IconButtonMenu, { IconButtonMenuItems } from "src/components/menu";
|
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 JambonzSwitch from "src/components/switch";
|
||||||
import { DEFAULT_TOAST_DURATION } from "src/common/constants";
|
import { DEFAULT_TOAST_DURATION } from "src/common/constants";
|
||||||
|
import { RegisteredUser } from "src/api/types";
|
||||||
|
|
||||||
type PhoneProbs = {
|
type PhoneProbs = {
|
||||||
sipDomain: string;
|
sipDomain: string;
|
||||||
@@ -100,6 +106,13 @@ export const Phone = ({
|
|||||||
const sipDisplayNameRef = useRef("");
|
const sipDisplayNameRef = useRef("");
|
||||||
const [isForceChangeUaStatus, setIsForceChangeUaStatus] = useState(false);
|
const [isForceChangeUaStatus, setIsForceChangeUaStatus] = useState(false);
|
||||||
const isInputNumberFocusRef = useRef(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();
|
const toast = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -120,6 +133,9 @@ export const Phone = ({
|
|||||||
setIsConfigured(false);
|
setIsConfigured(false);
|
||||||
clientGoOffline();
|
clientGoOffline();
|
||||||
}
|
}
|
||||||
|
getSelfRegisteredUser(sipUsernameRef.current).then(({ json }) => {
|
||||||
|
setRegisteredUser(json);
|
||||||
|
});
|
||||||
}, [sipDomain, sipUsername, sipPassword, sipServerAddress, sipDisplayName]);
|
}, [sipDomain, sipUsername, sipPassword, sipServerAddress, sipDisplayName]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -162,6 +178,14 @@ export const Phone = ({
|
|||||||
}
|
}
|
||||||
}, [status]);
|
}, [status]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInterval(() => {
|
||||||
|
getSelfRegisteredUser(sipUsernameRef.current).then(({ json }) => {
|
||||||
|
setRegisteredUser(json);
|
||||||
|
});
|
||||||
|
}, 20000);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// chrome.runtime.onMessage.addListener(function (request) {
|
// chrome.runtime.onMessage.addListener(function (request) {
|
||||||
// const msg = request as Message<any>;
|
// const msg = request as Message<any>;
|
||||||
@@ -478,6 +502,7 @@ export const Phone = ({
|
|||||||
>
|
>
|
||||||
{isAdvanceMode && isSipClientIdle(callStatus) && (
|
{isAdvanceMode && isSipClientIdle(callStatus) && (
|
||||||
<HStack spacing={2} align="start" w="full">
|
<HStack spacing={2} align="start" w="full">
|
||||||
|
{registeredUser.allow_direct_user_calling && (
|
||||||
<IconButtonMenu
|
<IconButtonMenu
|
||||||
icon={<Users />}
|
icon={<Users />}
|
||||||
tooltip="Call an online user"
|
tooltip="Call an online user"
|
||||||
@@ -508,6 +533,9 @@ export const Phone = ({
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{registeredUser.allow_direct_queue_calling && (
|
||||||
<IconButtonMenu
|
<IconButtonMenu
|
||||||
icon={<List />}
|
icon={<List />}
|
||||||
tooltip="Take a call from queue"
|
tooltip="Take a call from queue"
|
||||||
@@ -535,7 +563,9 @@ export const Phone = ({
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{registeredUser.allow_direct_app_calling && (
|
||||||
<IconButtonMenu
|
<IconButtonMenu
|
||||||
icon={<GitMerge />}
|
icon={<GitMerge />}
|
||||||
tooltip="Call an application"
|
tooltip="Call an application"
|
||||||
@@ -563,6 +593,7 @@ export const Phone = ({
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</HStack>
|
</HStack>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user