fix review comments

This commit is contained in:
Quan HL
2023-10-30 14:14:55 +07:00
parent 7bcb56229b
commit 01e6342872
18 changed files with 76 additions and 7 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+14
View File
@@ -5,6 +5,7 @@ export default class SipAudioElements {
#busy: HTMLAudioElement; #busy: HTMLAudioElement;
#remote: HTMLAudioElement; #remote: HTMLAudioElement;
#hungup: HTMLAudioElement; #hungup: HTMLAudioElement;
#localHungup: HTMLAudioElement;
constructor() { constructor() {
this.#ringing = new Audio(chrome.runtime.getURL("audios/ringing.mp3")); this.#ringing = new Audio(chrome.runtime.getURL("audios/ringing.mp3"));
@@ -21,9 +22,22 @@ export default class SipAudioElements {
chrome.runtime.getURL("audios/remote-party-hungup-tone.mp3") chrome.runtime.getURL("audios/remote-party-hungup-tone.mp3")
); );
this.#hungup.volume = 0.3; this.#hungup.volume = 0.3;
this.#localHungup = new Audio(
chrome.runtime.getURL("audios/local-party-hungup-tone.mp3")
);
this.#localHungup.volume = 0.3;
this.#remote = new Audio(); this.#remote = new Audio();
} }
playLocalHungup(volume: number | undefined) {
this.pauseRingback();
this.pauseRinging();
if (volume) {
this.#localHungup.volume = volume;
}
this.#localHungup.play();
}
playRinging(volume: number | undefined): void { playRinging(volume: number | undefined): void {
if (volume) { if (volume) {
this.#ringing.volume = volume; this.#ringing.volume = volume;
+2
View File
@@ -105,6 +105,8 @@ export default class SipSession extends events.EventEmitter {
let description; let description;
if (originator === "remote") { if (originator === "remote") {
this.#audio.playRemotePartyHungup(undefined); this.#audio.playRemotePartyHungup(undefined);
} else {
this.#audio.playLocalHungup(undefined);
} }
if (message && originator === "remote" && message.hasHeader("Reason")) { if (message && originator === "remote" && message.hasHeader("Reason")) {
const reason = Grammar.parse(message.getHeader("Reason"), "Reason"); const reason = Grammar.parse(message.getHeader("Reason"), "Reason");
+28
View File
@@ -0,0 +1,28 @@
export default class DialPadAudioElements {
private keySounds: { [key: string]: HTMLAudioElement | undefined } = {};
constructor() {
const arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#"];
for (const i of arr) {
this.keySounds[i] = new Audio(
chrome.runtime.getURL(`audios/dtmf-${encodeURIComponent(i)}.mp3`)
);
const audio = this.keySounds[i];
console.log({ i, audio }, "xquanluu");
if (audio) {
audio.volume = 0.5;
}
}
}
playKeyTone(key: string): void {
const audio = this.keySounds[key];
if (audio) {
if (!audio.paused) {
audio.pause();
audio.currentTime = 0;
}
audio.play();
}
}
}
+27 -1
View File
@@ -1,9 +1,13 @@
import { Box, Button, HStack, VStack } from "@chakra-ui/react"; import { Box, Button, HStack, VStack } from "@chakra-ui/react";
import DialPadAudioElements from "./DialPadSoundElement";
import { useEffect } from "react";
type DialPadProbs = { type DialPadProbs = {
handleDigitPress: (digit: string) => void; handleDigitPress: (digit: string) => void;
}; };
const keySounds = new DialPadAudioElements();
export const DialPad = ({ handleDigitPress }: DialPadProbs) => { export const DialPad = ({ handleDigitPress }: DialPadProbs) => {
const buttons = [ const buttons = [
["1", "2", "3"], ["1", "2", "3"],
@@ -12,6 +16,25 @@ export const DialPad = ({ handleDigitPress }: DialPadProbs) => {
["*", "0", "#"], ["*", "0", "#"],
]; ];
const handleKeyDown = (e: KeyboardEvent) => {
if (
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#"].includes(
e.key
)
) {
keySounds?.playKeyTone(e.key);
handleDigitPress(e.key);
}
};
useEffect(() => {
document.addEventListener("keydown", handleKeyDown);
return () => {
console.log("xquanluu1231");
document.removeEventListener("keydown", handleKeyDown);
};
}, []);
return ( return (
<Box p={2} w="full"> <Box p={2} w="full">
<VStack w="full" bg="grey.500" spacing={0.5}> <VStack w="full" bg="grey.500" spacing={0.5}>
@@ -20,7 +43,10 @@ export const DialPad = ({ handleDigitPress }: DialPadProbs) => {
{row.map((num) => ( {row.map((num) => (
<Button <Button
key={num} key={num}
onClick={() => handleDigitPress(num)} onClick={() => {
keySounds?.playKeyTone(num);
handleDigitPress(num);
}}
size="lg" size="lg"
p={0} p={0}
width="124px" width="124px"
+5 -6
View File
@@ -315,9 +315,8 @@ export const Phone = ({
} }
const handleDialPadClick = (value: string) => { const handleDialPadClick = (value: string) => {
if (isSipClientIdle(callStatus)) { setInputNumber((prev) => prev + value);
setInputNumber((prev) => prev + value); if (isSipClientAnswered(callStatus)) {
} else if (isSipClientAnswered(callStatus)) {
sipUA.current?.dtmf(value, undefined); sipUA.current?.dtmf(value, undefined);
} }
}; };
@@ -414,9 +413,9 @@ export const Phone = ({
<Center flexDirection="column"> <Center flexDirection="column">
{isConfigured ? ( {isConfigured ? (
<> <>
<HStack spacing={2} boxShadow="md" w="full" p={2} borderRadius={5}> <HStack spacing={2} boxShadow="md" w="full" borderRadius={5} p={2}>
<Image src={isOnline() ? GreenAvatar : Avatar} /> <Image src={isOnline() ? GreenAvatar : Avatar} boxSize="50px" />
<VStack spacing={2} alignItems="start" w="full"> <VStack alignItems="start" w="full" spacing={0}>
<HStack spacing={2} w="full"> <HStack spacing={2} w="full">
<Text fontWeight="bold" fontSize="13px"> <Text fontWeight="bold" fontSize="13px">
{sipDisplayName || sipUsername} {sipDisplayName || sipUsername}