Skip to content

Commit

Permalink
fix: wrong mute/unMute physical action (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 authored Nov 19, 2024
1 parent f957378 commit 6c83caa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
8 changes: 6 additions & 2 deletions src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export const Socket: FC<SocketProps> = ({
extensions[conv.counterpartNum].username
}` || '',
})
// Update the current call informations for physical devices
dispatch.currentCall.checkAcceptedUpdate({
acceptedSocket: true,
})
// Add call to transfer calls
dispatch.currentCall.addTransferCalls({
type: 'transferred',
Expand Down Expand Up @@ -411,8 +415,8 @@ export const Socket: FC<SocketProps> = ({
dispatchParkingUpdate()
})

// `callNethLink` is the socket event when user make a call or a action from NethLink and has a physical device
socket.current.on('callNethLink', (link, urlType) => {
// `actionNethLink` is the socket event when user make a call or a action from NethLink and has a physical device
socket.current.on('actionNethLink', (link, urlType) => {
// Dispatch phone island physical call event with the link and the urlType
dispatchUrlCall(link, urlType)
})
Expand Down
5 changes: 2 additions & 3 deletions src/lib/phone/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
hangupPhysical,
answerPhysical,
mutePhysical,
unmutePhysical,
pausePhysical,
callPhysical,
toggleRecord,
Expand Down Expand Up @@ -118,7 +117,7 @@ export function muteCurrentCall() {
})
}
} else {
mutePhysical()
mutePhysical(true)
}
eventDispatch('phone-island-call-muted', {})
}
Expand All @@ -136,7 +135,7 @@ export function unmuteCurrentCall() {
})
}
} else {
unmutePhysical()
mutePhysical(false)
}
eventDispatch('phone-island-call-unmuted', {})
}
Expand Down
8 changes: 7 additions & 1 deletion src/models/island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export const island = createModel<RootModel>()({
}),
})

type IslandViewType = 'call' | 'keypad' | 'player' | 'transfer' | 'recorder' | 'physicalPhoneRecorder'
type IslandViewType =
| 'call'
| 'keypad'
| 'player'
| 'transfer'
| 'recorder'
| 'physicalPhoneRecorder'

interface IslandTypes {
view?: IslandViewType | null
Expand Down
39 changes: 5 additions & 34 deletions src/services/astproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export async function parkConversation(body: {

export async function answerPhysical() {
// get data
const { ownerExtension } = store.getState().currentCall
const { default_device } = store.getState().currentUser

// compose body
let body: any = {
endpointId: ownerExtension,
endpointId: default_device?.id,
endpointType: 'extension',
}

Expand Down Expand Up @@ -183,36 +183,7 @@ export async function hangupPhysicalRecordingCall() {
}
}

export async function mutePhysical() {
// get data
const { ownerExtension, conversationId } = store.getState().currentCall

// compose body
let body: any = {
convid: conversationId,
endpointId: ownerExtension,
}

try {
const { baseURL, headers } = store.getState().fetchDefaults
const response = await fetch(`${baseURL}/astproxy/mute`, {
method: 'POST',
headers: { ...headers },
body: JSON.stringify(body),
})
if (!response.ok) {
throw new Error(response.statusText)
}
store.dispatch.currentCall.updateCurrentCall({
muted: true,
})
return true
} catch (error: any) {
throw new Error(error)
}
}

export async function unmutePhysical() {
export async function mutePhysical(toggleMute: boolean) {
// get data
const { ownerExtension, conversationId } = store.getState().currentCall

Expand All @@ -224,7 +195,7 @@ export async function unmutePhysical() {

try {
const { baseURL, headers } = store.getState().fetchDefaults
const response = await fetch(`${baseURL}/astproxy/unmute`, {
const response = await fetch(`${baseURL}/astproxy/toggle_mute`, {
method: 'POST',
headers: { ...headers },
body: JSON.stringify(body),
Expand All @@ -233,7 +204,7 @@ export async function unmutePhysical() {
throw new Error(response.statusText)
}
store.dispatch.currentCall.updateCurrentCall({
muted: false,
muted: toggleMute,
})
return true
} catch (error: any) {
Expand Down

0 comments on commit 6c83caa

Please sign in to comment.