mirror of
https://github.com/jambonz/chrome-extension-dialer.git
synced 2025-12-19 04:47:45 +00:00
Merge pull request #33 from jambonz/fix/wrongly_upadte_conference
fix wrongly update conference settings when initiating a conference join
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { ConferenceModes } from "src/api/types";
|
||||||
|
|
||||||
export interface LoginCredential {
|
export interface LoginCredential {
|
||||||
name?: string;
|
name?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
@@ -57,6 +59,12 @@ export interface AppSettings {
|
|||||||
sipDisplayName: string;
|
sipDisplayName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConferenceSettings {
|
||||||
|
mode: ConferenceModes;
|
||||||
|
tags: string;
|
||||||
|
speakOnlyTo: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AdvancedAppSettings {
|
export interface AdvancedAppSettings {
|
||||||
accountSid: string;
|
accountSid: string;
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
|
|||||||
@@ -2,9 +2,26 @@ import {
|
|||||||
AdvancedAppSettings,
|
AdvancedAppSettings,
|
||||||
AppSettings,
|
AppSettings,
|
||||||
CallHistory,
|
CallHistory,
|
||||||
|
ConferenceSettings,
|
||||||
} from "src/common/types";
|
} from "src/common/types";
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
|
|
||||||
|
// Conference settings
|
||||||
|
const CONFERENCE_SETTINGS = "ConferenceSettingsKey";
|
||||||
|
|
||||||
|
export const saveConferenceSettings = (settings: ConferenceSettings) => {
|
||||||
|
sessionStorage.setItem(CONFERENCE_SETTINGS, JSON.stringify(settings));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getConferenceSettings = (): ConferenceSettings => {
|
||||||
|
return JSON.parse(
|
||||||
|
sessionStorage.getItem(CONFERENCE_SETTINGS) || "{}"
|
||||||
|
) as ConferenceSettings;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteConferenceSettings = () => {
|
||||||
|
sessionStorage.removeItem(CONFERENCE_SETTINGS);
|
||||||
|
};
|
||||||
// Settings
|
// Settings
|
||||||
const SETTINGS_KEY = "SettingsKey";
|
const SETTINGS_KEY = "SettingsKey";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
|
||||||
FormControl,
|
FormControl,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
HStack,
|
HStack,
|
||||||
@@ -9,13 +8,20 @@ import {
|
|||||||
Radio,
|
Radio,
|
||||||
RadioGroup,
|
RadioGroup,
|
||||||
Text,
|
Text,
|
||||||
|
useToast,
|
||||||
VStack,
|
VStack,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { FormEvent, useEffect, useState } from "react";
|
import { FormEvent, useEffect, useState } from "react";
|
||||||
import { updateConferenceParticipantAction } from "src/api";
|
import { updateConferenceParticipantAction } from "src/api";
|
||||||
import { ConferenceModes } from "src/api/types";
|
import { ConferenceModes } from "src/api/types";
|
||||||
|
import { DEFAULT_TOAST_DURATION } from "src/common/constants";
|
||||||
import OutlineBox from "src/components/outline-box";
|
import OutlineBox from "src/components/outline-box";
|
||||||
import { SipConstants } from "src/lib";
|
import { SipConstants } from "src/lib";
|
||||||
|
import {
|
||||||
|
deleteConferenceSettings,
|
||||||
|
getConferenceSettings,
|
||||||
|
saveConferenceSettings,
|
||||||
|
} from "src/storage";
|
||||||
|
|
||||||
type JoinConferenceProbs = {
|
type JoinConferenceProbs = {
|
||||||
conferenceId?: string;
|
conferenceId?: string;
|
||||||
@@ -33,6 +39,7 @@ export const JoinConference = ({
|
|||||||
handleCancel,
|
handleCancel,
|
||||||
call,
|
call,
|
||||||
}: JoinConferenceProbs) => {
|
}: JoinConferenceProbs) => {
|
||||||
|
const toast = useToast();
|
||||||
const [conferenceName, setConferenceName] = useState(conferenceId || "");
|
const [conferenceName, setConferenceName] = useState(conferenceId || "");
|
||||||
const [appTitle, setAppTitle] = useState(
|
const [appTitle, setAppTitle] = useState(
|
||||||
!!conferenceId ? "Joining Conference" : "Start Conference"
|
!!conferenceId ? "Joining Conference" : "Start Conference"
|
||||||
@@ -40,11 +47,17 @@ export const JoinConference = ({
|
|||||||
const [submitTitle, setSubmitTitle] = useState(
|
const [submitTitle, setSubmitTitle] = useState(
|
||||||
!!conferenceId ? "Joining Conference" : "Start Conference"
|
!!conferenceId ? "Joining Conference" : "Start Conference"
|
||||||
);
|
);
|
||||||
|
|
||||||
const [cancelTitle, setCancelTitle] = useState("Cancel");
|
const [cancelTitle, setCancelTitle] = useState("Cancel");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [speakOnlyTo, setSpeakOnlyTo] = useState("");
|
const confSettings = getConferenceSettings();
|
||||||
const [tags, setTags] = useState("");
|
const [speakOnlyTo, setSpeakOnlyTo] = useState(
|
||||||
const [mode, setMode] = useState<ConferenceModes>("full_participant");
|
confSettings.speakOnlyTo || ""
|
||||||
|
);
|
||||||
|
const [tags, setTags] = useState(confSettings.tags || "");
|
||||||
|
const [mode, setMode] = useState<ConferenceModes>(
|
||||||
|
confSettings.mode || "full_participant"
|
||||||
|
);
|
||||||
const [participantState, setParticipantState] = useState("Join as");
|
const [participantState, setParticipantState] = useState("Join as");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -60,21 +73,11 @@ export const JoinConference = ({
|
|||||||
case SipConstants.SESSION_ENDED:
|
case SipConstants.SESSION_ENDED:
|
||||||
case SipConstants.SESSION_FAILED:
|
case SipConstants.SESSION_FAILED:
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
deleteConferenceSettings();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}, [callStatus]);
|
}, [callStatus]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
switch (mode) {
|
|
||||||
case "full_participant":
|
|
||||||
break;
|
|
||||||
case "muted":
|
|
||||||
break;
|
|
||||||
case "coach":
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}, [mode]);
|
|
||||||
|
|
||||||
const handleSubmit = (e: FormEvent) => {
|
const handleSubmit = (e: FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (callStatus !== SipConstants.SESSION_ANSWERED) {
|
if (callStatus !== SipConstants.SESSION_ANSWERED) {
|
||||||
@@ -88,21 +91,49 @@ export const JoinConference = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const configureConferenceSession = async () => {
|
const configureConferenceSession = async () => {
|
||||||
|
const confSettings = getConferenceSettings();
|
||||||
if (callSid) {
|
if (callSid) {
|
||||||
await updateConferenceParticipantAction(callSid, {
|
if (confSettings.mode) {
|
||||||
action: mode === "muted" ? "mute" : "unmute",
|
updateConferenceParticipantAction(callSid, {
|
||||||
tag: "",
|
action: confSettings.mode === "muted" ? "mute" : "unmute",
|
||||||
});
|
tag: "",
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
updateConferenceParticipantAction(callSid, {
|
||||||
|
action: mode === "coach" ? "coach" : "uncoach",
|
||||||
|
tag: confSettings.speakOnlyTo,
|
||||||
|
}).catch((error) => {
|
||||||
|
toast({
|
||||||
|
title: error.msg,
|
||||||
|
status: "error",
|
||||||
|
duration: DEFAULT_TOAST_DURATION,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
toast({
|
||||||
|
title: error.msg,
|
||||||
|
status: "error",
|
||||||
|
duration: DEFAULT_TOAST_DURATION,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await updateConferenceParticipantAction(callSid, {
|
if (confSettings.tags) {
|
||||||
action: tags ? "tag" : "untag",
|
updateConferenceParticipantAction(callSid, {
|
||||||
tag: tags,
|
action: tags ? "tag" : "untag",
|
||||||
});
|
tag: tags,
|
||||||
|
}).catch((error) => {
|
||||||
await updateConferenceParticipantAction(callSid, {
|
toast({
|
||||||
action: mode === "coach" ? "coach" : "uncoach",
|
title: error.msg,
|
||||||
tag: speakOnlyTo,
|
status: "error",
|
||||||
});
|
duration: DEFAULT_TOAST_DURATION,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -131,7 +162,14 @@ export const JoinConference = ({
|
|||||||
|
|
||||||
<OutlineBox title={participantState}>
|
<OutlineBox title={participantState}>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
onChange={(e) => setMode(e as ConferenceModes)}
|
onChange={(e) => {
|
||||||
|
setMode(e as ConferenceModes);
|
||||||
|
saveConferenceSettings({
|
||||||
|
mode: e as ConferenceModes,
|
||||||
|
speakOnlyTo,
|
||||||
|
tags,
|
||||||
|
});
|
||||||
|
}}
|
||||||
value={mode}
|
value={mode}
|
||||||
colorScheme="jambonz"
|
colorScheme="jambonz"
|
||||||
>
|
>
|
||||||
@@ -150,7 +188,14 @@ export const JoinConference = ({
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="tag"
|
placeholder="tag"
|
||||||
value={speakOnlyTo}
|
value={speakOnlyTo}
|
||||||
onChange={(e) => setSpeakOnlyTo(e.target.value)}
|
onChange={(e) => {
|
||||||
|
setSpeakOnlyTo(e.target.value);
|
||||||
|
saveConferenceSettings({
|
||||||
|
mode,
|
||||||
|
speakOnlyTo: e.target.value,
|
||||||
|
tags,
|
||||||
|
});
|
||||||
|
}}
|
||||||
disabled={mode !== "coach"}
|
disabled={mode !== "coach"}
|
||||||
required={mode === "coach"}
|
required={mode === "coach"}
|
||||||
/>
|
/>
|
||||||
@@ -162,7 +207,14 @@ export const JoinConference = ({
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="tag"
|
placeholder="tag"
|
||||||
value={tags}
|
value={tags}
|
||||||
onChange={(e) => setTags(e.target.value)}
|
onChange={(e) => {
|
||||||
|
setTags(e.target.value);
|
||||||
|
saveConferenceSettings({
|
||||||
|
mode,
|
||||||
|
speakOnlyTo,
|
||||||
|
tags: e.target.value,
|
||||||
|
});
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</OutlineBox>
|
</OutlineBox>
|
||||||
@@ -181,7 +233,10 @@ export const JoinConference = ({
|
|||||||
type="button"
|
type="button"
|
||||||
w="full"
|
w="full"
|
||||||
textColor="black"
|
textColor="black"
|
||||||
onClick={handleCancel}
|
onClick={() => {
|
||||||
|
deleteConferenceSettings();
|
||||||
|
handleCancel();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{cancelTitle}
|
{cancelTitle}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ export const Phone = ({
|
|||||||
);
|
);
|
||||||
const [selectedConference, setSelectedConference] = useState("");
|
const [selectedConference, setSelectedConference] = useState("");
|
||||||
const [callSid, setCallSid] = useState("");
|
const [callSid, setCallSid] = useState("");
|
||||||
|
const [showConference, setShowConference] = useState(false);
|
||||||
|
|
||||||
const inputNumberRef = useRef(inputNumber);
|
const inputNumberRef = useRef(inputNumber);
|
||||||
const sessionDirectionRef = useRef(sessionDirection);
|
const sessionDirectionRef = useRef(sessionDirection);
|
||||||
@@ -154,6 +155,13 @@ export const Phone = ({
|
|||||||
clientGoOffline();
|
clientGoOffline();
|
||||||
}
|
}
|
||||||
fetchRegisterUser();
|
fetchRegisterUser();
|
||||||
|
getConferences()
|
||||||
|
.then(() => {
|
||||||
|
setShowConference(true);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setShowConference(false);
|
||||||
|
});
|
||||||
}, [sipDomain, sipUsername, sipPassword, sipServerAddress, sipDisplayName]);
|
}, [sipDomain, sipUsername, sipPassword, sipServerAddress, sipDisplayName]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -643,7 +651,7 @@ export const Phone = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{registeredUser.allow_direct_app_calling && (
|
{registeredUser.allow_direct_app_calling && showConference && (
|
||||||
<IconButtonMenu
|
<IconButtonMenu
|
||||||
icon={<FontAwesomeIcon icon={faPeopleGroup} />}
|
icon={<FontAwesomeIcon icon={faPeopleGroup} />}
|
||||||
tooltip="Join a conference"
|
tooltip="Join a conference"
|
||||||
|
|||||||
Reference in New Issue
Block a user