Skip to content

Commit

Permalink
physical phone. added methods to support actions
Browse files Browse the repository at this point in the history
  • Loading branch information
edospadoni committed Feb 9, 2024
1 parent c86d3b2 commit 4907b8c
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 22 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Start recording": "Start recording",
"Switch call": "Switch call",
"Call to transfer": "Call to transfer",
"Hangup and transfer": "Hangup and transfer"
"Hangup and transfer": "Transfer"
},
"DropdownContent": {
"Microphones": "MICROPHONES",
Expand Down
18 changes: 14 additions & 4 deletions src/components/CallView/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { Tooltip } from 'react-tooltip/dist/react-tooltip.min.cjs'
import { park } from '../../lib/phone/call'
import { eventDispatch, useEventListener } from '../../utils'
import { useTranslation } from 'react-i18next'
import { isWebRTC } from '../../lib/user/default_device'
import { sendPhysicalDTMF } from '../../services/astproxy'

const Actions: FC = () => {
// Get multiple values from currentCall store
Expand All @@ -56,7 +58,12 @@ const Actions: FC = () => {

// Cancels the current transfer through dtmfs
function calcelTransfer() {
sendDTMF('*')
if (isWebRTC()) {
sendDTMF('*')
} else {
sendPhysicalDTMF('*')
}

const { audioPlayerPlaying } = store.getState().player
// Check if the local audio is already playing and start playing
if (!audioPlayerPlaying) {
Expand All @@ -66,7 +73,12 @@ const Actions: FC = () => {
})
}
setTimeout(() => {
sendDTMF('1')
if (isWebRTC()) {
sendDTMF('1')
} else {
sendPhysicalDTMF('1')
}

dispatch.player.stopAudioPlayer()
// The workarround to disable transfer because of the wrong conv.connection value from ws
if (transferring) {
Expand All @@ -91,8 +103,6 @@ const Actions: FC = () => {
eventDispatch('phone-island-call-parked', {})
}



const { t } = useTranslation()

// Phone island header section
Expand Down
8 changes: 7 additions & 1 deletion src/components/KeypadView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { backToCallView } from '../../lib/island/island'
import { playDtmfAudio } from '../../lib/phone/call'
import { Tooltip } from 'react-tooltip/dist/react-tooltip.min.cjs'
import { useTranslation } from 'react-i18next'
import { isWebRTC } from '../../lib/user/default_device'
import { sendPhysicalDTMF } from '../../services/astproxy'

const DTMF_KEYS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#']

Expand All @@ -26,7 +28,11 @@ const KeypadView: FC<KeypadViewTypes> = () => {
dispatch.currentCall.updateKeypadValue(`${keypadValueRef.current}${key}`)
keypadValueRef.current = `${keypadValueRef.current}${key}`
playDtmfAudio(key)
sendDTMF(key)
if (isWebRTC()) {
sendDTMF(key)
} else {
sendPhysicalDTMF(key)
}
}

useEffect(() => {
Expand Down
46 changes: 36 additions & 10 deletions src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

import React, { type ReactNode, FC, useEffect, useRef } from 'react'
import { useDispatch } from 'react-redux'
import { Dispatch } from '../store'
import { useDispatch, useSelector } from 'react-redux'
import { Dispatch, RootState } from '../store'
import { io } from 'socket.io-client'
import { getDisplayName } from '../lib/phone/conversation'
import {
Expand All @@ -25,6 +25,7 @@ import type {
MainPresenceTypes,
} from '../types'
import { getTimestampInSeconds } from '../utils/genericFunctions/timestamp'
import { userTotallyFree } from '../lib/user/extensions'

interface SocketProps {
children: ReactNode
Expand All @@ -47,6 +48,26 @@ export const Socket: FC<SocketProps> = ({
const connectionCheckInterval = useRef<any>()
const socket = useRef<any>()

// get user information
const userInformation = useSelector((state: RootState) => state.currentUser)

const checkDefaultDeviceConversationActive = (conv: any) => {
dispatch.currentCall.updateCurrentCall({
conversationId: conv.id,
accepted: true,
incoming: conv.direction === 'in' ? false : undefined,
})

// Stop the local audio element ringing
store.dispatch.player.stopAudioPlayer()
}

const checkDefaultDeviceConversationClosed = (conv: any) => {
// store.dispatch.player.stopAudioPlayer()
store.dispatch.currentCall.reset()
// store.dispatch.listen.reset()
}

useEffect(() => {
/**
* Manages event and data for the currentUser
Expand All @@ -57,6 +78,7 @@ export const Socket: FC<SocketProps> = ({
const handleCurrentUserEvents = (res: ExtensionTypes, conv: ConversationTypes) => {
// Handle transferring data
const { transferring, transferSwitching, transferCalls } = store.getState().currentCall

// Check conversation isn't empty
if (Object.keys(conv).length > 0) {
// With conversation
Expand Down Expand Up @@ -87,6 +109,7 @@ export const Socket: FC<SocketProps> = ({
displayName: getDisplayName(conv),
number: `${conv.counterpartNum}`,
startTime: `${conv.startTime / 1000}`,
ownerExtension: conv.owner,
username:
`${
extensions &&
Expand All @@ -101,6 +124,10 @@ export const Socket: FC<SocketProps> = ({
number: `${conv.counterpartNum}`,
startTime: `${getTimestampInSeconds()}`,
})

if (userInformation?.default_device?.type !== 'webrtc') {
checkDefaultDeviceConversationActive(conv)
}
}
// Handle not connected calls
else if (conv && !conv.connected) {
Expand Down Expand Up @@ -157,6 +184,7 @@ export const Socket: FC<SocketProps> = ({
displayName: getDisplayName(conv),
number: counterpartNum,
startTime: `${startTime / 1000}`,
conversationId: conv.id,
})
// Set the view of the island to call
dispatch.island.setIslandView('call')
Expand All @@ -168,14 +196,12 @@ export const Socket: FC<SocketProps> = ({
}
} else {
// Without conversation for physical phone management
// if (status) {
// if (res.status == 'online' && userTotallyFree()) {
// // Stop ringing sounds
// dispatch.player.stopAudioPlayer()
// // Reset current call info
// dispatch.currentCall.reset()
// }
// }
if (res.status == 'online' && userTotallyFree()) {
// Stop ringing sounds
dispatch.player.stopAudioPlayer()
// Reset current call info
dispatch.currentCall.reset()
}
}
}

Expand Down
34 changes: 29 additions & 5 deletions src/lib/phone/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import { isWebRTC } from '../user/default_device'
import {
blindTransfer as blindTransferRequest,
attendedTransfer as attendedTransferRequest,
hangupPhysical,
answerPhysical,
mutePhysical,
unmutePhysical,
pausePhysical,
callPhysical,
} from '../../services/astproxy'
import dtmfAudios from '../../static/dtmf'
import { hangupConversation, parkConversation } from '../../services/astproxy'
Expand All @@ -27,7 +33,11 @@ import { hangupConversation, parkConversation } from '../../services/astproxy'
*/
export function callNumber(number: string, sipHost: string) {
const sipURI = `sip:${number}@${sipHost}`
callSipURI(sipURI)
if (isWebRTC()) {
callSipURI(sipURI)
} else {
callPhysical(number)
}
}

/**
Expand Down Expand Up @@ -68,6 +78,8 @@ export function callSipURI(sipURI: string) {
export function answerIncomingCall() {
if (isWebRTC()) {
answerWebRTC()
} else {
answerPhysical()
}
}

Expand Down Expand Up @@ -95,11 +107,15 @@ export function hangupAllExtensions() {
export function hangupCurrentCall() {
const { outgoing, accepted } = store.getState().currentCall
if (outgoing || accepted) {
hangup()
if (isWebRTC()) {
hangup()
} else {
hangupPhysical()
}
store.dispatch.player.stopAudioPlayer()
store.dispatch.currentCall.reset()
store.dispatch.listen.reset()
}
store.dispatch.player.stopAudioPlayer()
store.dispatch.currentCall.reset()
store.dispatch.listen.reset()
}

/**
Expand All @@ -114,6 +130,8 @@ export function muteCurrentCall() {
muted: true,
})
}
} else {
mutePhysical()
}
}

Expand All @@ -129,6 +147,8 @@ export function unmuteCurrentCall() {
muted: false,
})
}
} else {
unmutePhysical()
}
}

Expand All @@ -146,6 +166,8 @@ export function pauseCurrentCall() {
// Pause remote audio
store.dispatch.player.pauseRemoteAudio()
}
} else {
pausePhysical(true)
}
}

Expand All @@ -163,6 +185,8 @@ export function unpauseCurrentCall() {
// Play remote audio
store.dispatch.player.playRemoteAudio()
}
} else {
pausePhysical(false)
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/models/currentCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultState = {
transferringStartTime: '',
transferSwitching: false,
transferCalls: new Array(),
ownerExtension: '',
}

export const currentCall = createModel<RootModel>()({
Expand Down Expand Up @@ -159,4 +160,5 @@ export interface CurrentCallTypes {
transferringStartTime?: string
transferSwitching?: boolean
transferCalls?: TransferCallsTypes[]
ownerExtension?: string
}
Loading

0 comments on commit 4907b8c

Please sign in to comment.