Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
BoxDialer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
BoxDialer
Commits
9b62f42b
Commit
9b62f42b
authored
Nov 10, 2023
by
Muhammadali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update-
parent
4a51d89e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1020 additions
and
993 deletions
+1020
-993
package.json
package.json
+1
-1
boxDIaler.js
src/lib/boxDIaler.js
+1011
-964
index.jsx
src/root/index.jsx
+8
-28
No files found.
package.json
View file @
9b62f42b
{
{
"name"
:
"boxdialer"
,
"name"
:
"boxdialer"
,
"version"
:
"4.8.
59
"
,
"version"
:
"4.8.
60
"
,
"description"
:
""
,
"description"
:
""
,
"main"
:
"src/boxDialer.js"
,
"main"
:
"src/boxDialer.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
src/lib/boxDIaler.js
View file @
9b62f42b
/** @format */
/** @format */
import
{
toast
}
from
'
react-hot-toast
'
;
import
{
toast
}
from
'
react-hot-toast
'
;
import
outcomingringTone
from
'
../sounds/ringtone.wav
'
;
import
outcomingringTone
from
'
../sounds/ringtone.wav
'
;
import
waitRingTone
from
'
../sounds/ringbacktone.wav
'
;
import
waitRingTone
from
'
../sounds/ringbacktone.wav
'
;
import
pickSound
from
'
../sounds/dtmf.wav
'
;
import
pickSound
from
'
../sounds/dtmf.wav
'
;
import
{
WebSocketInterface
,
UA
}
from
'
jssip
'
;
import
{
WebSocketInterface
,
UA
}
from
'
jssip
'
;
import
tugpng
from
'
../img/tug.png
'
;
import
tugpng
from
'
../img/tug.png
'
;
import
packageJson
from
'
../../package.json
'
;
import
packageJson
from
'
../../package.json
'
;
export
class
BoxDialer
{
export
class
BoxDialer
{
sTransferNumber
;
sTransferNumber
;
oRingTone
;
oRingTone
;
oRingbackTone
;
oRingbackTone
;
oSipStack
;
oSipStack
;
oSipSessionRegister
;
oSipSessionRegister
;
oSipSessionCall
;
oSipSessionCall
;
oSipSessionCallSecond
;
oSipSessionCallSecond
;
oSipSessionTransferCall
;
oSipSessionTransferCall
;
videoRemote
;
videoRemote
;
videoLocal
;
videoLocal
;
remoteAudio
;
remoteAudio
;
bFullScreen
=
false
;
bFullScreen
=
false
;
oNotifICall
;
oNotifICall
;
bDisableVideo
=
false
;
bDisableVideo
=
false
;
viewVideoLocal
;
viewVideoLocal
;
viewVideoRemote
;
viewVideoRemote
;
viewLocalScreencast
;
// <video> (webrtc) or <div> (webrtc4all)
viewLocalScreencast
;
// <video> (webrtc) or <div> (webrtc4all)
oConfigCall
;
oConfigCall
;
callDirection
;
callDirection
;
oReadyStateTimer
;
oReadyStateTimer
;
ringtone
;
ringtone
;
ringbacktone
;
ringbacktone
;
sipState
;
sipState
;
sipBxState
;
sipBxState
;
soundBool
;
soundBool
;
onSipStateChange
=
{};
onSipStateChange
=
{};
callEvetsBoxDialer
;
callEvetsBoxDialer
;
musicContext
;
musicContext
;
gainNode
;
gainNode
;
gainNode
;
gainNode
;
oscillator1
;
oscillator1
;
oscillator2
;
oscillator2
;
extnum
;
extnum
;
timer
=
{
timer
=
{
time
:
0
,
time
:
0
,
type
:
null
,
type
:
null
,
};
};
innerTimer
=
{
innerTimer
=
{
time
:
0
,
time
:
0
,
type
:
null
,
type
:
null
,
};
};
options
;
options
;
socket
;
socket
;
ua
;
ua
;
testTimer
;
testTimer
;
testInnerTimer
;
testInnerTimer
;
callSession
;
callSession
;
sipDomain
;
sipDomain
;
player
;
player
;
strmTrack
;
strmTrack
;
isRestarting
;
isRestarting
;
globalHistoryData
globalHistoryData
constructor
()
{
constructor
()
{
this
.
played
=
false
;
this
.
played
=
false
;
document
.
body
.
addEventListener
(
'
click
'
,
()
=>
{
document
.
body
.
addEventListener
(
'
click
'
,
()
=>
{
this
.
played
=
true
;
this
.
played
=
true
;
});
});
this
.
isRestarting
=
false
;
this
.
isRestarting
=
false
;
this
.
videoRemote
=
document
.
createElement
(
'
video
'
);
this
.
videoRemote
=
document
.
createElement
(
'
video
'
);
this
.
videoLocal
=
document
.
createElement
(
'
video
'
);
this
.
videoLocal
=
document
.
createElement
(
'
video
'
);
this
.
remoteAudio
=
document
.
createElement
(
'
audio
'
);
this
.
remoteAudio
=
document
.
createElement
(
'
audio
'
);
this
.
remoteAudio
.
autoplay
=
true
;
this
.
remoteAudio
.
autoplay
=
true
;
document
.
body
.
appendChild
(
this
.
videoRemote
);
document
.
body
.
appendChild
(
this
.
videoRemote
);
document
.
body
.
appendChild
(
this
.
videoLocal
);
document
.
body
.
appendChild
(
this
.
videoLocal
);
document
.
body
.
appendChild
(
this
.
remoteAudio
);
document
.
body
.
appendChild
(
this
.
remoteAudio
);
this
.
ringtone
=
new
Audio
(
outcomingringTone
);
this
.
ringtone
=
new
Audio
(
outcomingringTone
);
this
.
waitRingTone
=
new
Audio
(
waitRingTone
);
this
.
waitRingTone
=
new
Audio
(
waitRingTone
);
this
.
pickSound
=
new
Audio
(
pickSound
);
this
.
pickSound
=
new
Audio
(
pickSound
);
this
.
ringtone
.
loop
=
true
;
this
.
ringtone
.
loop
=
true
;
this
.
waitRingTone
.
loop
=
true
;
this
.
waitRingTone
.
loop
=
true
;
this
.
callEvetsBoxDialer
=
{
this
.
callEvetsBoxDialer
=
{
callHold
:
false
,
callHold
:
false
,
callMute
:
null
,
callMute
:
null
,
};
};
this
.
options
=
{
this
.
options
=
{
eventHandlers
:
this
.
uaEvents
(),
eventHandlers
:
this
.
uaEvents
(),
mediaConstraints
:
{
audio
:
true
,
video
:
false
},
mediaConstraints
:
{
audio
:
true
,
video
:
false
},
};
};
}
}
dialTone
(
freq1
,
freq2
)
{
setGlobalHistoryData
(
data
){
// merger = context.createChannelMerger(2);
console
.
log
(
'
setGlobalHistoryData:
'
,
data
)
// setTimeout(() => {
this
.
globalHistoryData
=
data
// console.log('-= sTOPING BY TIMEOUT');
}
// this.stop();
// }, 1000);
dialTone
(
freq1
,
freq2
)
{
// if (this.oscillator1 || this.oscillator2) return;
// merger = context.createChannelMerger(2);
// console.log('Begin dialTone:', this.oscillator1, this.oscillator2);
// setTimeout(() => {
// this.oscillator1 = this.musicContext.createOscillator();
// console.log('-= sTOPING BY TIMEOUT');
// // this.oscillator1.type = null;
// this.stop();
// this.oscillator1.frequency.value = freq1;
// }, 1000);
// this.gainNode = this.musicContext.createGain
// if (this.oscillator1 || this.oscillator2) return;
// ? this.musicContext.createGain()
// console.log('Begin dialTone:', this.oscillator1, this.oscillator2);
// : this.musicContext.createGainNode();
// this.oscillator1 = this.musicContext.createOscillator();
// this.oscillator1.connect(this.gainNode, 0, 0);
// // this.oscillator1.type = null;
// this.gainNode.connect(this.musicContext.destination);
// this.oscillator1.frequency.value = freq1;
// this.gainNode.gain.value = 0.1;
// this.gainNode = this.musicContext.createGain
// this.oscillator1.start
// ? this.musicContext.createGain()
// ? this.oscillator1.start(0)
// : this.musicContext.createGainNode();
// : this.oscillator1.noteOn(0);
// this.oscillator1.connect(this.gainNode, 0, 0);
// // this.gainNode.connect(merger,0,1);
// this.gainNode.connect(this.musicContext.destination);
// this.oscillator2 = this.musicContext.createOscillator();
// this.gainNode.gain.value = 0.1;
// // this.oscillator2.type = null;
// this.oscillator1.start
// this.oscillator2.frequency.value = freq2;
// ? this.oscillator1.start(0)
// this.gainNode = this.musicContext.createGain
// : this.oscillator1.noteOn(0);
// ? this.musicContext.createGain()
// // this.gainNode.connect(merger,0,1);
// : this.musicContext.createGainNode();
// this.oscillator2 = this.musicContext.createOscillator();
// this.oscillator2.connect(this.gainNode);
// // this.oscillator2.type = null;
// this.gainNode.connect(this.musicContext.destination);
// this.oscillator2.frequency.value = freq2;
// // this.gainNode.connect(merger,0,0);
// this.gainNode = this.musicContext.createGain
// this.gainNode.gain.value = 0.1;
// ? this.musicContext.createGain()
// this.oscillator2.start
// : this.musicContext.createGainNode();
// ? this.oscillator2.start(0)
// this.oscillator2.connect(this.gainNode);
// : this.oscillator2.noteOn(0);
// this.gainNode.connect(this.musicContext.destination);
}
// // this.gainNode.connect(merger,0,0);
start
()
{
// this.gainNode.gain.value = 0.1;
// if (typeof this.oscillator1 != 'undefined') this.oscillator1.disconnect();
// this.oscillator2.start
// if (typeof this.oscillator2 != 'undefined') this.oscillator2.disconnect();
// ? this.oscillator2.start(0)
// oscOn(
// : this.oscillator2.noteOn(0);
// parseFloat(document.getElementById('freq').value),
}
// parseFloat(document.getElementById('freq2').value),
// );
start
()
{
}
// if (typeof this.oscillator1 != 'undefined') this.oscillator1.disconnect();
// if (typeof this.oscillator2 != 'undefined') this.oscillator2.disconnect();
stop
()
{
// oscOn(
// console.log('STOP', this.oscillator1, this.oscillator2);
// parseFloat(document.getElementById('freq').value),
// console.log('FUNC', this.oscillator1?.disconnect, this.oscillator1?.stop);
// parseFloat(document.getElementById('freq2').value),
// this.oscillator1?.disconnect();
// );
// this.oscillator2?.disconnect();
}
// this.oscillator1?.stop();
// this.oscillator2?.stop();
stop
()
{
// this.oscillator1 = null;
// console.log('STOP', this.oscillator1, this.oscillator2);
// this.oscillator2 = null;
// console.log('FUNC', this.oscillator1?.disconnect, this.oscillator1?.stop);
}
// this.oscillator1?.disconnect();
uaEvents
()
{
// this.oscillator2?.disconnect();
return
{
// this.oscillator1?.stop();
progress
:
(
e
)
=>
{
// this.oscillator2?.stop();
console
.
log
(
'
%c progress
'
,
'
font-size: 22px; color: green;
'
,
e
);
// this.oscillator1 = null;
// this.hangupButtonClick();
// this.oscillator2 = null;
// this.closeBxCall();
}
// window.innerCallBegin(true);
uaEvents
()
{
this
.
onSipStateChange
.
innerCallerModal
({
return
{
bool
:
true
,
progress
:
(
e
)
=>
{
type
:
'
connectingOutgoing
'
,
console
.
log
(
'
%c progress
'
,
'
font-size: 22px; color: green;
'
,
e
);
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
// this.hangupButtonClick();
});
// this.closeBxCall();
this
.
setGuiPhoneState
({
funcName
:
'
modalState
'
,
// window.innerCallBegin(true);
stateCode
:
'
connectingOutgoing
'
,
this
.
onSipStateChange
.
innerCallerModal
({
funcParam
:
{
bool
:
true
,
bool
:
false
,
type
:
'
connectingOutgoing
'
,
callType
:
''
,
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
},
});
});
this
.
setGuiPhoneState
({
},
funcName
:
'
modalState
'
,
failed
:
(
e
)
=>
{
stateCode
:
'
connectingOutgoing
'
,
console
.
log
(
'
%c failed
'
,
'
font-size: 22px; color: green;
'
,
e
);
funcParam
:
{
if
(
e
?.
cause
)
{
bool
:
false
,
toast
.
error
(
e
?.
cause
);
callType
:
''
,
}
},
// console.log('call failed with cause: ' + e.data);
});
this
.
closeBxCall
();
},
this
.
onSipStateChange
.
innerCallerModal
({
failed
:
(
e
)
=>
{
bool
:
false
,
console
.
log
(
'
%c failed
'
,
'
font-size: 22px; color: green;
'
,
e
);
type
:
null
,
if
(
e
?.
cause
)
{
from
:
''
,
toast
.
error
(
e
?.
cause
);
});
}
this
.
stopInnerTimer
();
// console.log('call failed with cause: ' + e.data);
if
(
e
.
cause
==
'
User Denied Media Access
'
)
{
this
.
closeBxCall
();
console
.
log
(
'
User_Danied_Media_Access
'
);
this
.
onSipStateChange
.
innerCallerModal
({
toast
.
error
(
'
Your micrafon is OFF
'
,
{
bool
:
false
,
style
:
{
type
:
null
,
zIndex
:
'
99999999999999999
'
,
from
:
''
,
},
});
});
this
.
stopInnerTimer
();
if
(
e
.
cause
==
'
User Denied Media Access
'
)
{
window
.
navigator
.
mediaDevices
console
.
log
(
'
User_Danied_Media_Access
'
);
.
getUserMedia
({
audio
:
true
})
toast
.
error
(
'
Your micrafon is OFF
'
,
{
.
then
(
function
(
stream
)
{
style
:
{
console
.
log
(
zIndex
:
'
99999999999999999
'
,
'
User_Danied_Media_Access
'
,
},
'
You let me use your mic!
'
,
});
);
})
window
.
navigator
.
mediaDevices
.
catch
(
function
(
err
)
{
.
getUserMedia
({
audio
:
true
})
console
.
log
(
'
User_Danied_Media_Access
'
,
'
No mic for you!
'
);
.
then
(
function
(
stream
)
{
});
console
.
log
(
}
'
User_Danied_Media_Access
'
,
},
'
You let me use your mic!
'
,
ended
:
(
e
)
=>
{
);
console
.
log
(
'
%c ended
'
,
'
font-size: 22px; color: green;
'
);
})
this
.
closeBxCall
();
.
catch
(
function
(
err
)
{
this
.
onSipStateChange
.
innerCallerModal
({
console
.
log
(
'
User_Danied_Media_Access
'
,
'
No mic for you!
'
);
bool
:
false
,
});
type
:
null
,
}
from
:
''
,
},
});
ended
:
(
e
)
=>
{
this
.
stopInnerTimer
();
console
.
log
(
'
%c ended
'
,
'
font-size: 22px; color: green;
'
);
this
.
setGuiPhoneState
({
this
.
closeBxCall
();
funcName
:
'
modalState
'
,
this
.
onSipStateChange
.
innerCallerModal
({
funcParam
:
{
bool
:
false
,
bool
:
false
,
type
:
null
,
callType
:
''
,
from
:
''
,
},
});
});
this
.
stopInnerTimer
();
this
.
removeViExternalCard
();
this
.
setGuiPhoneState
({
},
funcName
:
'
modalState
'
,
confirmed
:
(
e
)
=>
{
funcParam
:
{
console
.
log
(
'
%c confirmed
'
,
'
font-size: 22px; color: green;
'
,
e
);
bool
:
false
,
// console.log(`%c BXLOG:`, datas, 'background-color: red;');
callType
:
''
,
this
.
onSipStateChange
.
innerCallerModal
({
},
bool
:
true
,
});
type
:
'
connected
'
,
this
.
removeViExternalCard
();
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
},
});
confirmed
:
(
e
)
=>
{
this
.
startInnerTimer
();
console
.
log
(
'
%c confirmed
'
,
'
font-size: 22px; color: green;
'
,
e
);
this
.
setGuiPhoneState
({
// console.log(`%c BXLOG:`, datas, 'background-color: red;');
funcName
:
'
modalState
'
,
this
.
onSipStateChange
.
innerCallerModal
({
stateCode
:
'
connected
'
,
bool
:
true
,
funcParam
:
{
type
:
'
connected
'
,
bool
:
true
,
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
callType
:
'
connected
'
,
});
callFromName
:
'
Test
'
,
this
.
startInnerTimer
();
},
this
.
setGuiPhoneState
({
});
funcName
:
'
modalState
'
,
},
stateCode
:
'
connected
'
,
};
funcParam
:
{
}
bool
:
true
,
callType
:
'
connected
'
,
isUaRunning
()
{
callFromName
:
'
Test
'
,
return
(
},
Boolean
(
typeof
window
.
BX
!==
'
undefined
'
)
&&
});
Boolean
(
window
.
localStorage
.
getItem
(
BX
.
bitrix_sessid
()
+
'
_mycall
'
))
&&
},
Boolean
(
window
.
localStorage
.
getItem
(
'
mycall
'
))
};
);
}
}
isUaRunning
()
{
removeViExternalCard
()
{
return
(
// if (
Boolean
(
typeof
window
.
BX
!==
'
undefined
'
)
&&
// typeof BX !== 'undefined' &&
Boolean
(
window
.
localStorage
.
getItem
(
BX
.
bitrix_sessid
()
+
'
_mycall
'
))
&&
// window.localStorage.getItem(BX.bitrix_sessid() + '_mycall') &&
Boolean
(
window
.
localStorage
.
getItem
(
'
mycall
'
))
// window.localStorage.getItem('mycall')
);
// ) {
}
// BX?.localStorage?.remove('viExternalCard');
// } else if (typeof BX !== 'undefined') {
removeViExternalCard
()
{
// BX?.localStorage?.remove('viExternalCard');
// if (
// }
// typeof BX !== 'undefined' &&
}
// window.localStorage.getItem(BX.bitrix_sessid() + '_mycall') &&
// window.localStorage.getItem('mycall')
startTimer
()
{
// ) {
this
.
testTimer
=
setInterval
(()
=>
{
// BX?.localStorage?.remove('viExternalCard');
this
.
timer
.
time
=
this
.
timer
.
time
+
1
;
// } else if (typeof BX !== 'undefined') {
this
.
onSipStateChange
.
setDndTimer
(
this
.
timer
.
time
);
// BX?.localStorage?.remove('viExternalCard');
},
1000
);
// }
}
}
stopTimer
()
{
startTimer
()
{
clearInterval
(
this
.
testTimer
);
this
.
testTimer
=
setInterval
(()
=>
{
this
.
timer
.
time
=
0
;
this
.
timer
.
time
=
this
.
timer
.
time
+
1
;
this
.
onSipStateChange
.
setDndTimer
(
this
.
timer
.
time
);
this
.
onSipStateChange
.
setDndTimer
(
this
.
timer
.
time
);
}
},
1000
);
}
startInnerTimer
()
{
this
.
testInnerTimer
=
setInterval
(()
=>
{
stopTimer
()
{
this
.
innerTimer
.
time
=
this
.
innerTimer
.
time
+
1
;
clearInterval
(
this
.
testTimer
);
this
.
onSipStateChange
.
innerTimer
(
this
.
innerTimer
.
time
);
this
.
timer
.
time
=
0
;
},
1000
);
this
.
onSipStateChange
.
setDndTimer
(
this
.
timer
.
time
);
}
}
stopInnerTimer
()
{
startInnerTimer
()
{
clearInterval
(
this
.
testInnerTimer
);
this
.
testInnerTimer
=
setInterval
(()
=>
{
this
.
innerTimer
.
time
=
0
;
this
.
innerTimer
.
time
=
this
.
innerTimer
.
time
+
1
;
this
.
onSipStateChange
.
innerTimer
(
this
.
innerTimer
.
time
);
this
.
onSipStateChange
.
innerTimer
(
this
.
innerTimer
.
time
);
}
},
1000
);
}
showNotification
(
cbk
)
{
let
callerId
=
this
.
callSession
.
_remote_identity
.
_uri
.
user
;
stopInnerTimer
()
{
const
greeting
=
new
Notification
(
`Звонок от
${
callerId
}
`
,
{
clearInterval
(
this
.
testInnerTimer
);
body
:
'
Answer Call
'
,
this
.
innerTimer
.
time
=
0
;
icon
:
tugpng
,
this
.
onSipStateChange
.
innerTimer
(
this
.
innerTimer
.
time
);
});
}
greeting
.
addEventListener
(
'
click
'
,
cbk
);
}
showNotification
(
cbk
)
{
let
callerId
=
this
.
callSession
.
_remote_identity
.
_uri
.
user
;
onSoundType
({
type
,
bool
})
{
const
greeting
=
new
Notification
(
`Звонок от
${
callerId
}
`
,
{
this
.
ringtone
.
remove
();
body
:
'
Answer Call
'
,
this
.
waitRingTone
.
remove
();
icon
:
tugpng
,
this
.
pickSound
.
remove
();
});
if
(
this
.
played
)
{
greeting
.
addEventListener
(
'
click
'
,
cbk
);
switch
(
type
)
{
}
case
'
ring
'
:
if
(
bool
)
{
onSoundType
({
type
,
bool
})
{
this
.
ringtone
.
pause
();
this
.
ringtone
.
remove
();
this
.
ringtone
.
remove
();
this
.
waitRingTone
.
remove
();
this
.
pickSound
.
remove
();
this
.
ringtone
.
play
();
if
(
this
.
played
)
{
}
else
{
switch
(
type
)
{
this
.
ringtone
.
pause
();
case
'
ring
'
:
this
.
ringtone
.
remove
();
if
(
bool
)
{
}
this
.
ringtone
.
pause
();
break
;
this
.
ringtone
.
remove
();
case
'
wait
'
:
if
(
bool
)
{
this
.
ringtone
.
play
();
this
.
waitRingTone
.
pause
();
}
else
{
this
.
waitRingTone
.
remove
();
this
.
ringtone
.
pause
();
console
.
log
(
this
.
waitRingTone
,
'
sound waitRingTone
'
);
this
.
ringtone
.
remove
();
}
this
.
waitRingTone
.
play
();
break
;
}
else
{
case
'
wait
'
:
this
.
waitRingTone
.
pause
();
if
(
bool
)
{
this
.
waitRingTone
.
remove
();
this
.
waitRingTone
.
pause
();
}
this
.
waitRingTone
.
remove
();
break
;
console
.
log
(
this
.
waitRingTone
,
'
sound waitRingTone
'
);
case
'
pick
'
:
if
(
bool
)
{
this
.
waitRingTone
.
play
();
this
.
pickSound
.
remove
();
}
else
{
this
.
pickSound
.
pause
();
this
.
waitRingTone
.
pause
();
this
.
waitRingTone
.
remove
();
this
.
pickSound
.
play
();
}
}
else
{
break
;
this
.
pickSound
.
pause
();
case
'
pick
'
:
this
.
pickSound
.
remove
();
if
(
bool
)
{
}
this
.
pickSound
.
remove
();
break
;
this
.
pickSound
.
pause
();
default
:
console
.
error
(
'
onSoundType: Such a sound does not exist
'
);
this
.
pickSound
.
play
();
break
;
}
else
{
}
this
.
pickSound
.
pause
();
}
this
.
pickSound
.
remove
();
}
}
break
;
sipRegister
=
({
number
,
secret
,
wsurl
,
isIce
})
=>
{
default
:
try
{
console
.
error
(
'
onSoundType: Such a sound does not exist
'
);
if
(
window
?.
alovoice_setversion
&&
packageJson
?.
version
)
{
break
;
window
.
alovoice_setversion
(
packageJson
?.
version
);
}
}
}
if
(
this
.
options
)
{
}
if
(
typeof
BX
!==
'
undefined
'
)
BX
?.
localStorage
?.
remove
(
'
viExternalCard
'
);
sipRegister
=
({
number
,
secret
,
wsurl
,
isIce
})
=>
{
try
{
this
.
socket
=
new
WebSocketInterface
(
`wss://
${
wsurl
}
/ws`
);
if
(
window
?.
alovoice_setversion
&&
packageJson
?.
version
)
{
this
.
callSession
=
false
;
window
.
alovoice_setversion
(
packageJson
?.
version
);
this
.
sipDomain
=
wsurl
;
}
console
.
log
(
'
ua_configure
'
,
{
if
(
this
.
options
)
{
sockets
:
[
this
.
socket
],
if
(
typeof
BX
!==
'
undefined
'
)
uri
:
`sip:
${
number
}
@
${
wsurl
}
`
,
BX
?.
localStorage
?.
remove
(
'
viExternalCard
'
);
password
:
secret
,
stun_server
:
'
stun:stun.l.google.com:19302
'
,
this
.
socket
=
new
WebSocketInterface
(
`wss://
${
wsurl
}
/ws`
);
});
this
.
callSession
=
false
;
this
.
ua
=
new
UA
({
this
.
sipDomain
=
wsurl
;
sockets
:
[
this
.
socket
],
console
.
log
(
'
ua_configure
'
,
{
uri
:
`sip:
${
number
}
@
${
wsurl
}
`
,
sockets
:
[
this
.
socket
],
password
:
secret
,
uri
:
`sip:
${
number
}
@
${
wsurl
}
`
,
stun_server
:
'
stun:stun.l.google.com:19302
'
,
password
:
secret
,
register_expires
:
60
,
stun_server
:
'
stun:stun.l.google.com:19302
'
,
});
});
if
(
typeof
BX
!==
'
undefined
'
)
{
this
.
ua
=
new
UA
({
console
.
log
(
sockets
:
[
this
.
socket
],
'
setting_my_call =============================-----------
'
,
uri
:
`sip:
${
number
}
@
${
wsurl
}
`
,
);
password
:
secret
,
window
.
localStorage
.
setItem
(
stun_server
:
'
stun:stun.l.google.com:19302
'
,
BX
.
bitrix_sessid
()
+
'
_mycall
'
,
register_expires
:
60
,
this
.
ua
.
configuration
.
instance_id
,
});
);
if
(
typeof
BX
!==
'
undefined
'
)
{
window
.
localStorage
.
setItem
(
console
.
log
(
'
mycall
'
,
'
setting_my_call =============================-----------
'
,
this
.
ua
.
configuration
.
instance_id
,
);
);
window
.
localStorage
.
setItem
(
}
BX
.
bitrix_sessid
()
+
'
_mycall
'
,
this
.
ua
.
configuration
.
instance_id
,
this
.
ua
.
on
(
'
connected
'
,
(
e
)
=>
{
);
console
.
log
(
window
.
localStorage
.
setItem
(
'
%c sip_register [connected]:
'
,
'
mycall
'
,
'
font-size: 22px; color: yellow;
'
,
this
.
ua
.
configuration
.
instance_id
,
e
,
);
);
}
});
this
.
ua
.
on
(
'
disconnected
'
,
(
e
)
=>
{
this
.
ua
.
on
(
'
connected
'
,
(
e
)
=>
{
this
.
onSipStateChange
.
dynamicValue
(
'
pending
'
);
console
.
log
(
console
.
log
(
'
%c sip_register [connected]:
'
,
'
%c sip_register [disconnected]:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
});
this
.
ua
.
on
(
'
disconnected
'
,
(
e
)
=>
{
this
.
ua
.
on
(
'
registered
'
,
(
e
)
=>
{
this
.
onSipStateChange
.
dynamicValue
(
'
pending
'
);
this
.
onSipStateChange
.
dynamicValue
(
'
connected
'
);
console
.
log
(
console
.
log
(
'
%c sip_register [disconnected]:
'
,
'
%c sip_register [registered]:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
});
this
.
ua
.
on
(
'
registered
'
,
(
e
)
=>
{
this
.
ua
.
on
(
'
unregistered
'
,
(
e
)
=>
{
this
.
onSipStateChange
.
dynamicValue
(
'
connected
'
);
console
.
log
(
console
.
log
(
'
%c sip_register [unregistered]:
'
,
'
%c sip_register [registered]:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
});
this
.
ua
.
on
(
'
unregistered
'
,
(
e
)
=>
{
this
.
ua
.
on
(
'
registrationFailed
'
,
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c sip_register [unregistered]:
'
,
'
%c sip_register [registrationFailed]:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
});
this
.
ua
.
on
(
'
connecting
'
,
(
e
)
=>
{
this
.
ua
.
on
(
'
registrationFailed
'
,
(
e
)
=>
{
console
.
log
(
'
%c connecting:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
console
.
log
(
'
%c sip_register [registrationFailed]:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
ua
.
on
(
'
registrationExpiring
'
,
(
e
)
=>
{
e
,
console
.
log
(
);
'
%c registrationExpiring:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
ua
.
on
(
'
connecting
'
,
(
e
)
=>
{
e
,
console
.
log
(
'
%c connecting:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
);
this
.
ua
.
register
();
});
});
this
.
ua
.
on
(
'
registrationExpiring
'
,
(
e
)
=>
{
this
.
ua
.
on
(
'
newMessage
'
,
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c newMessage:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
'
%c registrationExpiring:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
ua
.
on
(
'
sipEvent
'
,
(
e
)
=>
{
e
,
console
.
log
(
'
%c sipEvent:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
);
});
this
.
ua
.
register
();
this
.
ua
.
on
(
'
newOptions
'
,
(
e
)
=>
{
});
console
.
log
(
'
%c newOptions:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
this
.
ua
.
on
(
'
newMessage
'
,
(
e
)
=>
{
});
console
.
log
(
'
%c newMessage:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
});
this
.
ua
.
on
(
'
newRTCSession
'
,
(
data
)
=>
{
this
.
ua
.
on
(
'
sipEvent
'
,
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c sipEvent:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
'
%c newRTCSession:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
ua
.
on
(
'
newOptions
'
,
(
e
)
=>
{
data
,
console
.
log
(
'
%c newOptions:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
);
});
this
.
callSession
=
data
.
session
;
this
.
ua
.
on
(
'
newRTCSession
'
,
(
data
)
=>
{
if
(
this
.
callSession
&&
this
.
callSession
.
connection
)
{
console
.
log
(
this
.
callSession
.
connection
.
onaddstream
=
(
e
)
=>
{
'
%c newRTCSession:
'
,
this
.
strmTrack
=
e
.
stream
.
getAudioTracks
();
'
font-size: 22px; color: yellow;
'
,
if
(
this
.
strmTrack
[
0
])
{
data
,
this
.
remoteAudio
.
srcObject
=
new
MediaStream
([
);
this
.
strmTrack
[
0
],
this
.
callSession
=
data
.
session
;
]);
this
.
remoteAudio
.
play
();
if
(
this
.
callSession
&&
this
.
callSession
.
connection
)
{
}
this
.
callSession
.
connection
.
onaddstream
=
(
e
)
=>
{
};
this
.
strmTrack
=
e
.
stream
.
getAudioTracks
();
}
if
(
this
.
strmTrack
[
0
])
{
this
.
remoteAudio
.
srcObject
=
new
MediaStream
([
this
.
setGuiPhoneState
({
this
.
strmTrack
[
0
],
funcName
:
'
modalState
'
,
]);
funcParam
:
{
this
.
remoteAudio
.
play
();
bool
:
true
,
}
callType
:
'
incoming
'
,
};
},
}
});
this
.
setGuiPhoneState
({
this
.
onSipStateChange
.
innerCallerModal
({
funcName
:
'
modalState
'
,
bool
:
true
,
funcParam
:
{
type
:
'
connectingIncoming
'
,
bool
:
true
,
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
callType
:
'
incoming
'
,
});
},
if
(
this
.
callSession
.
direction
===
'
incoming
'
)
{
});
this
.
showNotification
(()
=>
{
this
.
answerButtonClick
();
this
.
onSipStateChange
.
innerCallerModal
({
});
bool
:
true
,
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
true
});
type
:
'
connectingIncoming
'
,
this
.
setGuiPhoneState
({
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
funcName
:
'
modalState
'
,
});
stateCode
:
'
connectingIncoming
'
,
funcParam
:
{
if
(
this
.
callSession
.
direction
===
'
incoming
'
)
{
bool
:
true
,
callType
:
'
incoming
'
,
let
second
},
console
.
log
(
'
auto_answer is work:
'
,
this
.
globalHistoryData
?.
autoAnswer
)
});
if
(
this
.
globalHistoryData
?.
autoAnswer
)
{
switch
(
this
.
globalHistoryData
?.
autoAnswerSecond
)
{
// window.innerCallBegin();
case
1
:
second
=
1000
this
.
callSession
.
on
(
'
progress
'
,
(
e
)
=>
{
break
console
.
log
(
case
40
:
'
%c progress:
'
,
second
=
3000
'
font-size: 22px; color: yellow;
'
,
break
e
,
case
100
:
);
second
=
6000
this
.
setGuiPhoneState
({
break
stateCode
:
'
incoming
'
,
default
:
});
second
=
0
});
}
// incoming call here
console
.
log
(
'
auto_answer second:
'
,
second
)
this
.
callSession
.
on
(
'
accepted
'
,
()
=>
{
setTimeout
(()
=>
{
console
.
log
(
console
.
log
(
'
auto_answer run boxDialer.answerButtonClick()
'
)
'
%c newRTCSession accepted:
'
,
this
.
answerButtonClick
()
'
font-size: 22px; color: yellow;
'
,
},
second
)
e
,
}
);
// the call has answered
this
.
showNotification
(()
=>
{
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
this
.
answerButtonClick
();
this
.
setGuiPhoneState
({
});
funcName
:
'
modalState
'
,
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
true
});
funcParam
:
{
this
.
setGuiPhoneState
({
bool
:
true
,
funcName
:
'
modalState
'
,
callType
:
'
connected
'
,
stateCode
:
'
connectingIncoming
'
,
},
funcParam
:
{
});
bool
:
true
,
this
.
onSipStateChange
.
innerCallerModal
({
callType
:
'
incoming
'
,
bool
:
false
,
},
type
:
''
,
});
from
:
''
,
});
// window.innerCallBegin();
});
this
.
callSession
.
on
(
'
confirmed
'
,
()
=>
{
this
.
callSession
.
on
(
'
progress
'
,
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c newRTCSession confirmed:
'
,
'
%c progress:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
);
e
,
// this handler will be called for incoming calls too
);
console
.
log
(
this
.
setGuiPhoneState
({
'
%c incoming confirmed
'
,
stateCode
:
'
incoming
'
,
'
font-size: 22px; color: yellow;
'
,
});
);
});
this
.
onSipStateChange
.
innerCallerModal
({
// incoming call here
bool
:
true
,
this
.
callSession
.
on
(
'
accepted
'
,
()
=>
{
type
:
'
connected
'
,
console
.
log
(
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
'
%c newRTCSession accepted:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
startInnerTimer
();
e
,
this
.
setGuiPhoneState
({
);
funcName
:
'
modalState
'
,
// the call has answered
funcParam
:
{
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
bool
:
true
,
this
.
setGuiPhoneState
({
callType
:
'
connected
'
,
funcName
:
'
modalState
'
,
},
funcParam
:
{
});
bool
:
true
,
});
callType
:
'
connected
'
,
this
.
callSession
.
on
(
'
ended
'
,
()
=>
{
},
console
.
log
(
});
'
%c newRTCSession ended:
'
,
this
.
onSipStateChange
.
innerCallerModal
({
'
font-size: 22px; color: yellow;
'
,
bool
:
false
,
);
type
:
''
,
// the call has ended
from
:
''
,
console
.
log
(
'
%c incoming end
'
,
'
font-size: 22px; color: yellow;
'
);
});
this
.
onSipStateChange
.
innerCallerModal
({
});
bool
:
false
,
this
.
callSession
.
on
(
'
confirmed
'
,
()
=>
{
type
:
null
,
console
.
log
(
from
:
''
,
'
%c newRTCSession confirmed:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
stopInnerTimer
();
);
this
.
setGuiPhoneState
({
// this handler will be called for incoming calls too
funcName
:
'
modalState
'
,
console
.
log
(
funcParam
:
{
'
%c incoming confirmed
'
,
bool
:
false
,
'
font-size: 22px; color: yellow;
'
,
callType
:
''
,
);
},
this
.
onSipStateChange
.
innerCallerModal
({
});
bool
:
true
,
this
.
closeBxCall
();
type
:
'
connected
'
,
this
.
hangupButtonClick
();
from
:
this
?.
callSession
?.
_remote_identity
?.
_uri
?.
user
,
this
.
removeViExternalCard
();
});
});
this
.
startInnerTimer
();
this
.
callSession
.
on
(
'
failed
'
,
()
=>
{
this
.
setGuiPhoneState
({
// unable to establish the call
funcName
:
'
modalState
'
,
console
.
log
(
funcParam
:
{
'
%c incoming faile
'
,
bool
:
true
,
'
font-size: 22px; color: yellow;
'
,
callType
:
'
connected
'
,
);
},
this
.
onSipStateChange
.
innerCallerModal
({
});
bool
:
false
,
});
type
:
null
,
this
.
callSession
.
on
(
'
ended
'
,
()
=>
{
});
console
.
log
(
this
.
stopInnerTimer
();
'
%c newRTCSession ended:
'
,
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
'
font-size: 22px; color: yellow;
'
,
this
.
closeBxCall
();
);
this
.
hangupButtonClick
();
// the call has ended
this
.
setGuiPhoneState
({
console
.
log
(
'
%c incoming end
'
,
'
font-size: 22px; color: yellow;
'
);
funcName
:
'
modalState
'
,
this
.
onSipStateChange
.
innerCallerModal
({
funcParam
:
{
bool
:
false
,
bool
:
false
,
type
:
null
,
callType
:
''
,
from
:
''
,
},
});
});
this
.
stopInnerTimer
();
});
this
.
setGuiPhoneState
({
this
.
callSession
.
on
(
'
connecting
'
,
(
e
)
=>
{
funcName
:
'
modalState
'
,
console
.
log
(
funcParam
:
{
'
%c connecting:
'
,
bool
:
false
,
'
font-size: 22px; color: yellow;
'
,
callType
:
''
,
e
,
},
);
});
});
this
.
closeBxCall
();
this
.
callSession
.
on
(
'
sending
'
,
(
e
)
=>
{
this
.
hangupButtonClick
();
console
.
log
(
'
%c sending:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
this
.
removeViExternalCard
();
});
});
this
.
callSession
.
on
(
'
failed
'
,
()
=>
{
this
.
callSession
.
on
(
'
newDTMF
'
,
(
e
)
=>
{
// unable to establish the call
console
.
log
(
'
%c newDTMF:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
console
.
log
(
});
'
%c incoming faile
'
,
this
.
callSession
.
on
(
'
newInfo
'
,
(
e
)
=>
{
'
font-size: 22px; color: yellow;
'
,
console
.
log
(
'
%c newInfo:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
);
});
this
.
onSipStateChange
.
innerCallerModal
({
this
.
callSession
.
on
(
'
hold
'
,
(
e
)
=>
{
bool
:
false
,
console
.
log
(
type
:
null
,
'
%c ___________hold:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
stopInnerTimer
();
e
,
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
);
this
.
closeBxCall
();
});
this
.
hangupButtonClick
();
this
.
callSession
.
on
(
'
unhold
'
,
(
e
)
=>
{
this
.
setGuiPhoneState
({
console
.
log
(
funcName
:
'
modalState
'
,
'
%c ___________unhold:
'
,
funcParam
:
{
'
font-size: 22px; color: yellow;
'
,
bool
:
false
,
e
,
callType
:
''
,
);
},
});
});
this
.
callSession
.
on
(
'
muted
'
,
(
e
)
=>
{
});
console
.
log
(
'
%c muted:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
this
.
callSession
.
on
(
'
connecting
'
,
(
e
)
=>
{
});
console
.
log
(
this
.
callSession
.
on
(
'
unmuted
'
,
(
e
)
=>
{
'
%c connecting:
'
,
console
.
log
(
'
%c unmuted:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
'
font-size: 22px; color: yellow;
'
,
});
e
,
this
.
callSession
.
on
(
'
reinvite
'
,
(
e
)
=>
{
);
console
.
log
(
});
'
%c reinvite:
'
,
this
.
callSession
.
on
(
'
sending
'
,
(
e
)
=>
{
'
font-size: 22px; color: yellow;
'
,
console
.
log
(
'
%c sending:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
e
,
});
);
});
this
.
callSession
.
on
(
'
newDTMF
'
,
(
e
)
=>
{
this
.
callSession
.
on
(
'
update
'
,
(
e
)
=>
{
console
.
log
(
'
%c newDTMF:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
console
.
log
(
'
%c update:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
});
});
this
.
callSession
.
on
(
'
newInfo
'
,
(
e
)
=>
{
this
.
callSession
.
on
(
'
refer
'
,
(
e
)
=>
{
console
.
log
(
'
%c newInfo:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
console
.
log
(
'
%c refer:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
});
});
this
.
callSession
.
on
(
'
hold
'
,
(
e
)
=>
{
this
.
callSession
.
on
(
'
replaces
'
,
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c ___________hold:
'
,
'
%c replaces:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
});
this
.
callSession
.
on
(
'
unhold
'
,
(
e
)
=>
{
this
.
callSession
.
on
(
'
sdp
'
,
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c sdp:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
'
%c ___________unhold:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
callSession
.
on
(
'
icecandidate
'
,
(
e
)
=>
{
e
,
console
.
log
(
);
'
%c icecandidate:
'
,
});
'
font-size: 22px; color: yellow;
'
,
this
.
callSession
.
on
(
'
muted
'
,
(
e
)
=>
{
e
,
console
.
log
(
'
%c muted:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
);
});
});
this
.
callSession
.
on
(
'
unmuted
'
,
(
e
)
=>
{
this
.
callSession
.
on
(
'
getusermediafailed
'
,
(
e
)
=>
{
console
.
log
(
'
%c unmuted:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
console
.
log
(
});
'
%c getusermediafailed:
'
,
this
.
callSession
.
on
(
'
reinvite
'
,
(
e
)
=>
{
'
font-size: 22px; color: yellow;
'
,
console
.
log
(
e
,
'
%c reinvite:
'
,
);
'
font-size: 22px; color: yellow;
'
,
});
e
,
this
.
callSession
.
on
(
'
peerconnection: createofferfailed
'
,
(
e
)
=>
{
);
console
.
log
(
});
'
%c peerconnection: createofferfailed:
'
,
this
.
callSession
.
on
(
'
update
'
,
(
e
)
=>
{
'
font-size: 22px; color: yellow;
'
,
console
.
log
(
'
%c update:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
e
,
});
);
this
.
callSession
.
on
(
'
refer
'
,
(
e
)
=>
{
});
console
.
log
(
'
%c refer:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
this
.
callSession
.
on
(
});
'
peerconnection: setlocaldescriptionfailed
'
,
this
.
callSession
.
on
(
'
replaces
'
,
(
e
)
=>
{
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c replaces:
'
,
'
%c peerconnection: setlocaldescriptionfailed:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
},
this
.
callSession
.
on
(
'
sdp
'
,
(
e
)
=>
{
);
console
.
log
(
'
%c sdp:
'
,
'
font-size: 22px; color: yellow;
'
,
e
);
this
.
callSession
.
on
(
});
'
peerconnection: setremotedescriptionfailed
'
,
this
.
callSession
.
on
(
'
icecandidate
'
,
(
e
)
=>
{
(
e
)
=>
{
console
.
log
(
console
.
log
(
'
%c icecandidate:
'
,
'
%c peerconnection: setremotedescriptionfailed:
'
,
'
font-size: 22px; color: yellow;
'
,
'
font-size: 22px; color: yellow;
'
,
e
,
e
,
);
);
});
},
this
.
callSession
.
on
(
'
getusermediafailed
'
,
(
e
)
=>
{
);
console
.
log
(
}
'
%c getusermediafailed:
'
,
});
'
font-size: 22px; color: yellow;
'
,
e
,
this
.
ua
.
start
();
);
}
});
}
catch
(
err
)
{
this
.
callSession
.
on
(
'
peerconnection: createofferfailed
'
,
(
e
)
=>
{
console
.
log
(
`jsSip_error: `
,
err
);
console
.
log
(
}
'
%c peerconnection: createofferfailed:
'
,
};
'
font-size: 22px; color: yellow;
'
,
e
,
getBxUiState
(
sipState
)
{
);
// if (sipState && !!sipState.length) sipState = this.sipState;
});
let
uiStates
=
{
this
.
callSession
.
on
(
incoming
:
'
1
'
,
'
peerconnection: setlocaldescriptionfailed
'
,
transferIncoming
:
'
2
'
,
(
e
)
=>
{
outgoing
:
'
3
'
,
console
.
log
(
connectingIncoming
:
'
4
'
,
'
%c peerconnection: setlocaldescriptionfailed:
'
,
connectingOutgoing
:
'
5
'
,
'
font-size: 22px; color: yellow;
'
,
connected
:
'
6
'
,
e
,
transferring
:
'
7
'
,
);
transferFailed
:
'
8
'
,
},
transferConnected
:
'
9
'
,
);
idle
:
'
10
'
,
this
.
callSession
.
on
(
error
:
'
11
'
,
'
peerconnection: setremotedescriptionfailed
'
,
moneyError
:
'
12
'
,
(
e
)
=>
{
sipPhoneError
:
'
13
'
,
console
.
log
(
redial
:
'
14
'
,
'
%c peerconnection: setremotedescriptionfailed:
'
,
externalCard
:
'
15
'
,
'
font-size: 22px; color: yellow;
'
,
};
e
,
console
.
log
(
'
getBxUiState_inset:
'
,
sipState
,
uiStates
[
sipState
]);
);
this
.
sipBxState
=
uiStates
[
sipState
];
},
return
sipState
&&
uiStates
[
sipState
]
?
uiStates
[
sipState
]
:
''
;
);
}
}
});
callBxMethods
({
bxMethodName
,
bxFuncParams
,
callback
})
{
if
(
window
.
BX24
&&
window
.
BX24
.
placement
)
{
this
.
ua
.
start
();
window
?.
BX24
.
placement
.
call
(
bxMethodName
,
bxFuncParams
,
callback
);
}
}
else
if
(
window
.
alovoicePhone
&&
window
.
alovoicePhone
.
callMethods
)
{
}
catch
(
err
)
{
window
.
alovoicePhone
.
callMethods
[
bxMethodName
](
bxFuncParams
,
callback
);
console
.
log
(
`jsSip_error: `
,
err
);
}
}
if
(
bxFuncParams
.
uiState
==
'
5
'
)
{
};
this
.
removeViExternalCard
();
}
getBxUiState
(
sipState
)
{
}
// if (sipState && !!sipState.length) sipState = this.sipState;
closeBxCall
()
{
let
uiStates
=
{
if
(
window
.
BX24
&&
window
.
BX24
.
placement
)
{
incoming
:
'
1
'
,
window
?.
BX24
.
placement
.
call
(
'
CallCardClose
'
,
{},
()
=>
{});
transferIncoming
:
'
2
'
,
}
else
if
(
outgoing
:
'
3
'
,
window
.
alovoicePhone
&&
connectingIncoming
:
'
4
'
,
window
.
alovoicePhone
.
callMethods
&&
connectingOutgoing
:
'
5
'
,
window
.
alovoicePhone
.
bodClose
connected
:
'
6
'
,
)
{
transferring
:
'
7
'
,
window
?.
alovoicePhone
?.
bodClose
();
transferFailed
:
'
8
'
,
}
transferConnected
:
'
9
'
,
}
idle
:
'
10
'
,
error
:
'
11
'
,
setGuiPhoneState
({
stateCode
,
funcName
,
funcParam
})
{
moneyError
:
'
12
'
,
if
(
window
?.
alovoice_wsphone
&&
!!
stateCode
?.
length
)
{
sipPhoneError
:
'
13
'
,
console
.
log
(
redial
:
'
14
'
,
'
this_getBxUiState_stateCode
'
,
externalCard
:
'
15
'
,
stateCode
,
};
this
.
getBxUiState
(
stateCode
),
console
.
log
(
'
getBxUiState_inset:
'
,
sipState
,
uiStates
[
sipState
]);
);
this
.
sipBxState
=
uiStates
[
sipState
];
this
.
callBxMethods
({
return
sipState
&&
uiStates
[
sipState
]
?
uiStates
[
sipState
]
:
''
;
bxMethodName
:
'
CallCardSetUiState
'
,
}
bxFuncParams
:
{
uiState
:
this
.
getBxUiState
(
stateCode
)
},
callback
:
(
e
)
=>
{
callBxMethods
({
bxMethodName
,
bxFuncParams
,
callback
})
{
console
.
log
(
e
,
`CallCardSetUiState method done
${
e
}
`
);
if
(
window
.
BX24
&&
window
.
BX24
.
placement
)
{
},
window
?.
BX24
.
placement
.
call
(
bxMethodName
,
bxFuncParams
,
callback
);
});
}
else
if
(
window
.
alovoicePhone
&&
window
.
alovoicePhone
.
callMethods
)
{
}
else
if
(
window
.
alovoicePhone
.
callMethods
[
bxMethodName
](
bxFuncParams
,
callback
);
!
window
?.
alovoice_wsphone
&&
}
!
stateCode
?.
length
&&
if
(
bxFuncParams
.
uiState
==
'
5
'
)
{
!!
funcName
&&
this
.
removeViExternalCard
();
this
.
onSipStateChange
[
funcName
]
!==
'
undefined
'
}
)
{
}
this
.
onSipStateChange
[
funcName
](
funcParam
);
}
closeBxCall
()
{
}
if
(
window
.
BX24
&&
window
.
BX24
.
placement
)
{
window
?.
BX24
.
placement
.
call
(
'
CallCardClose
'
,
{},
()
=>
{
bxLog
(...
datas
)
{
});
console
.
log
(
`%c BXLOG:`
,
datas
,
'
background-color: red;
'
);
}
else
if
(
}
window
.
alovoicePhone
&&
window
.
alovoicePhone
.
callMethods
&&
onSessionEvent
({
type
,
event
})
{}
window
.
alovoicePhone
.
bodClose
)
{
selectUser
()
{
window
?.
alovoicePhone
?.
bodClose
();
BX
.
Runtime
.
loadExtension
(
'
ui.entity-selector
'
).
then
((
exports
)
=>
{
}
const
{
Dialog
,
TagSelector
}
=
exports
;
}
const
dialog
=
new
BX
.
UI
.
EntitySelector
.
Dialog
({
setGuiPhoneState
({
stateCode
,
funcName
,
funcParam
})
{
// targetNode: button,
if
(
window
?.
alovoice_wsphone
&&
!!
stateCode
?.
length
)
{
enableSearch
:
true
,
console
.
log
(
multiple
:
false
,
'
this_getBxUiState_stateCode
'
,
context
:
'
MY_MODULE_CONTEXT
'
,
stateCode
,
entities
:
[
this
.
getBxUiState
(
stateCode
),
{
);
id
:
'
user
'
,
// пользователи
this
.
callBxMethods
({
options
:
{
selectFields
:
[
'
ufPhoneInner
'
]
},
bxMethodName
:
'
CallCardSetUiState
'
,
},
bxFuncParams
:
{
uiState
:
this
.
getBxUiState
(
stateCode
)},
{
callback
:
(
e
)
=>
{
id
:
'
department
'
,
// структура компании: выбор только пользователей
console
.
log
(
e
,
`CallCardSetUiState method done
${
e
}
`
);
},
},
],
});
events
:
{
}
else
if
(
'
_Item:onSelect
'
:
(
event
)
=>
{
!
window
?.
alovoice_wsphone
&&
const
{
item
}
=
event
.
getData
();
!
stateCode
?.
length
&&
const
dialog
=
event
.
getTarget
();
!!
funcName
&&
const
selectedItems
=
dialog
.
getSelectedItems
();
this
.
onSipStateChange
[
funcName
]
!==
'
undefined
'
)
{
if
(
item
.
customData
.
get
(
'
ufPhoneInner
'
))
{
this
.
onSipStateChange
[
funcName
](
funcParam
);
this
.
transferButtonClick
(
item
.
customData
.
get
(
'
ufPhoneInner
'
));
}
}
}
},
get
'
Item:onSelect
'
()
{
bxLog
(...
datas
)
{
return
this
[
'
_Item:onSelect
'
];
console
.
log
(
`%c BXLOG:`
,
datas
,
'
background-color: red;
'
);
},
}
set
'
Item:onSelect
'
(
value
)
{
this
[
'
_Item:onSelect
'
]
=
value
;
onSessionEvent
({
type
,
event
})
{
},
}
},
});
selectUser
()
{
dialog
.
show
();
BX
.
Runtime
.
loadExtension
(
'
ui.entity-selector
'
).
then
((
exports
)
=>
{
});
const
{
Dialog
,
TagSelector
}
=
exports
;
}
const
dialog
=
new
BX
.
UI
.
EntitySelector
.
Dialog
({
// call_connected;
// targetNode: button,
setSipStateChangeCallback
(
callback
,
funcName
)
{
enableSearch
:
true
,
this
.
onSipStateChange
[
funcName
]
=
callback
.
bind
(
this
);
multiple
:
false
,
}
context
:
'
MY_MODULE_CONTEXT
'
,
entities
:
[
sipHangUp
()
{
{
console
.
log
(
'
sipHangUp
'
);
id
:
'
user
'
,
// пользователи
}
options
:
{
selectFields
:
[
'
ufPhoneInner
'
]},
sipUnRegister
()
{
},
console
.
log
(
'
sipUnRegister
'
);
{
}
id
:
'
department
'
,
// структура компании: выбор только пользователей
sipTransfer
()
{
},
console
.
log
(
'
sipTransfer
'
);
],
}
events
:
{
'
_Item:onSelect
'
:
(
event
)
=>
{
initialized
(
phoneNumber
)
{
const
{
item
}
=
event
.
getData
();
this
.
sipBxState
=
null
;
const
dialog
=
event
.
getTarget
();
const
selectedItems
=
dialog
.
getSelectedItems
();
this
.
callDirection
=
'
out
'
;
let
phoneNumberString
=
phoneNumber
.
toString
();
if
(
item
.
customData
.
get
(
'
ufPhoneInner
'
))
{
this
.
transferButtonClick
(
item
.
customData
.
get
(
'
ufPhoneInner
'
));
if
(
phoneNumberString
.
length
)
{
}
this
.
onSipStateChange
.
phoneModal
(
false
);
},
this
.
options
.
extraHeaders
=
[
`X-ALOVOICE-EXTNUM:
${
this
.
extnum
}
`
];
get
'
Item:onSelect
'
()
{
this
.
callSession
=
this
.
ua
.
call
(
return
this
[
'
_Item:onSelect
'
];
'
sip:
'
+
phoneNumberString
+
'
@
'
+
this
.
sipDomain
,
},
this
.
options
,
set
'
Item:onSelect
'
(
value
)
{
);
this
[
'
_Item:onSelect
'
]
=
value
;
// this.callSession.connection.addEventListener('addstream', (event) => {
},
// console.log('--== ss OUT STREAM: ');
},
// this.remoteAudio.srcObject = event.stream;
});
// this.remoteAudio.play();
dialog
.
show
();
// });
});
}
else
{
}
toast
.
error
(
'
Do not correct number
'
,
{
style
:
{
// call_connected;
zIndex
:
'
99999999999999999
'
,
setSipStateChangeCallback
(
callback
,
funcName
)
{
},
this
.
onSipStateChange
[
funcName
]
=
callback
.
bind
(
this
);
});
}
}
// this.onSipStateChange.phoneModal(false);
sipHangUp
()
{
}
console
.
log
(
'
sipHangUp
'
);
}
skipButtonClick
()
{
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
sipUnRegister
()
{
this
.
hangupButtonClick
();
console
.
log
(
'
sipUnRegister
'
);
}
}
answerButtonClick
()
{
sipTransfer
()
{
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
console
.
log
(
'
sipTransfer
'
);
this
.
callSession
?.
answer
(
this
.
options
);
}
this
.
callSession
.
connection
.
addEventListener
(
'
addstream
'
,
(
event
)
=>
{
this
.
remoteAudio
.
srcObject
=
event
.
stream
;
initialized
(
phoneNumber
)
{
this
.
remoteAudio
.
play
();
this
.
sipBxState
=
null
;
});
}
this
.
callDirection
=
'
out
'
;
let
phoneNumberString
=
phoneNumber
.
toString
();
sipSendDTMF
(
code
)
{
this
.
callSession
.
sendDTMF
(
code
);
if
(
phoneNumberString
.
length
)
{
}
this
.
onSipStateChange
.
phoneModal
(
false
);
this
.
options
.
extraHeaders
=
[
`X-ALOVOICE-EXTNUM:
${
this
.
extnum
}
`
];
addCommentButtonClick
()
{
this
.
callSession
=
this
.
ua
.
call
(
console
.
log
(
'
addCommentButtonClick
'
);
'
sip:
'
+
phoneNumberString
+
'
@
'
+
this
.
sipDomain
,
}
this
.
options
,
muteButtonClick
()
{
);
let
{
audio
}
=
this
.
callSession
.
isMuted
();
// this.callSession.connection.addEventListener('addstream', (event) => {
if
(
audio
)
{
// console.log('--== ss OUT STREAM: ');
this
.
callSession
.
unmute
();
// this.remoteAudio.srcObject = event.stream;
console
.
log
(
'
muteButtonClick_unmute
'
);
// this.remoteAudio.play();
// });
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callMute
:
false
});
}
else
{
}
else
{
toast
.
error
(
'
Do not correct number
'
,
{
this
.
callSession
.
mute
();
style
:
{
console
.
log
(
'
muteButtonClick_mute
'
);
zIndex
:
'
99999999999999999
'
,
},
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callMute
:
true
});
});
}
}
}
// this.onSipStateChange.phoneModal(false);
holdButtonClick
()
{
}
let
{
local
}
=
this
.
callSession
.
isOnHold
();
console
.
log
(
'
local:
'
,
local
);
skipButtonClick
()
{
if
(
local
)
{
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
this
.
callSession
.
unhold
();
this
.
hangupButtonClick
();
}
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callHold
:
false
});
}
else
{
answerButtonClick
()
{
this
.
callSession
.
hold
();
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
this
.
callSession
?.
answer
(
this
.
options
);
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callHold
:
true
});
this
.
callSession
.
connection
.
addEventListener
(
'
addstream
'
,
(
event
)
=>
{
}
this
.
remoteAudio
.
srcObject
=
event
.
stream
;
}
this
.
remoteAudio
.
play
();
});
closeButtonClick
()
{
}
this
.
hangupButtonClick
();
}
sipSendDTMF
(
code
)
{
hangupButtonClick
()
{
this
.
callSession
.
sendDTMF
(
code
);
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
}
this
.
onSipStateChange
.
innerCallerModal
({
bool
:
false
,
addCommentButtonClick
()
{
type
:
null
,
console
.
log
(
'
addCommentButtonClick
'
);
from
:
''
,
}
});
console
.
log
(
muteButtonClick
()
{
'
hangupButtonClick========-----------
'
,
let
{
audio
}
=
this
.
callSession
.
isMuted
();
this
.
callSession
.
_status
,
if
(
audio
)
{
);
this
.
callSession
.
unmute
();
if
(
this
.
callSession
&&
this
.
callSession
.
_status
!=
'
8
'
)
console
.
log
(
'
muteButtonClick_unmute
'
);
this
.
callSession
.
terminate
();
}
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callMute
:
false
});
}
else
{
transferButtonClick
(
number
)
{
this
.
callSession
.
mute
();
this
.
callSession
.
refer
(
number
,
this
.
options
);
console
.
log
(
'
muteButtonClick_mute
'
);
}
cancelTransferButtonClick
()
{
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callMute
:
true
});
console
.
log
(
'
cancelTransferButtonClick
'
);
}
}
}
completeTransferButtonClick
()
{
console
.
log
(
'
completeTransferButtonClick
'
);
holdButtonClick
()
{
}
let
{
local
}
=
this
.
callSession
.
isOnHold
();
nextButtonClick
()
{
console
.
log
(
'
local:
'
,
local
);
console
.
log
(
'
nextButtonClick
'
);
if
(
local
)
{
}
this
.
callSession
.
unhold
();
entityChanged
()
{
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callHold
:
false
});
console
.
log
(
'
entityChanged
'
);
}
else
{
}
this
.
callSession
.
hold
();
qualityMeterClick
()
{
console
.
log
(
'
qualityMeterClick
'
);
this
.
onSipStateChange
[
'
setCallEvents
'
]({
callHold
:
true
});
}
}
dialpadButtonClick
(
c
)
{
}
console
.
log
(
'
dialpadButtonClick
'
);
this
.
sipSendDTMF
(
c
);
closeButtonClick
()
{
}
this
.
hangupButtonClick
();
notifyAdminButtonClick
()
{
}
console
.
log
(
'
notifyAdminButtonClick
'
);
}
hangupButtonClick
()
{
this
.
onSoundType
({
type
:
'
ring
'
,
bool
:
false
});
stateLog
(
state
)
{
this
.
onSipStateChange
.
innerCallerModal
({
let
stColor
=
state
&&
state
.
slice
(
0
,
4
)
==
'
call
'
?
'
blue
'
:
'
green
'
;
bool
:
false
,
if
(
state
&&
state
.
slice
(
0
,
8
)
==
'
register
'
)
{
type
:
null
,
stColor
=
'
yellow
'
;
from
:
''
,
}
});
let
css
=
'
color:
'
+
stColor
+
'
; font-size: 20px;
'
;
console
.
log
(
'
hangupButtonClick========-----------
'
,
console
.
log
(
'
---onSessionEvent EVENT: %c %s
'
,
css
,
state
);
this
.
callSession
.
_status
,
}
);
if
(
this
.
callSession
&&
this
.
callSession
.
_status
!=
'
8
'
)
this
.
callSession
.
terminate
();
}
transferButtonClick
(
number
)
{
this
.
callSession
.
refer
(
number
,
this
.
options
);
}
cancelTransferButtonClick
()
{
console
.
log
(
'
cancelTransferButtonClick
'
);
}
completeTransferButtonClick
()
{
console
.
log
(
'
completeTransferButtonClick
'
);
}
nextButtonClick
()
{
console
.
log
(
'
nextButtonClick
'
);
}
entityChanged
()
{
console
.
log
(
'
entityChanged
'
);
}
qualityMeterClick
()
{
console
.
log
(
'
qualityMeterClick
'
);
}
dialpadButtonClick
(
c
)
{
console
.
log
(
'
dialpadButtonClick
'
);
this
.
sipSendDTMF
(
c
);
}
notifyAdminButtonClick
()
{
console
.
log
(
'
notifyAdminButtonClick
'
);
}
stateLog
(
state
)
{
let
stColor
=
state
&&
state
.
slice
(
0
,
4
)
==
'
call
'
?
'
blue
'
:
'
green
'
;
if
(
state
&&
state
.
slice
(
0
,
8
)
==
'
register
'
)
{
stColor
=
'
yellow
'
;
}
let
css
=
'
color:
'
+
stColor
+
'
; font-size: 20px;
'
;
console
.
log
(
'
---onSessionEvent EVENT: %c %s
'
,
css
,
state
);
}
}
}
src/root/index.jsx
View file @
9b62f42b
...
@@ -39,9 +39,11 @@ const Root = ({wsphonedata, onSetDnd, setWsphonedata, callMethod}) => {
...
@@ -39,9 +39,11 @@ const Root = ({wsphonedata, onSetDnd, setWsphonedata, callMethod}) => {
}
}
},
[
secondLine
]);
},
[
secondLine
]);
useEffect
(()
=>
{
boxDialer
.
setGlobalHistoryData
(
useColorConfigStore
.
state
)
},
[
useColorConfigStore
.
state
])
useEffect
(()
=>
{
useEffect
(()
=>
{
boxDialer
.
globalHistoryData
=
useColorConfigStore
.
state
if
(
wsphonedata
&&
wsphonedata
?.
number
)
{
if
(
wsphonedata
&&
wsphonedata
?.
number
)
{
boxDialer
.
setSipStateChangeCallback
(
setDynamicValue
,
'
dynamicValue
'
);
boxDialer
.
setSipStateChangeCallback
(
setDynamicValue
,
'
dynamicValue
'
);
boxDialer
.
setSipStateChangeCallback
(
setModalState
,
'
modalState
'
);
boxDialer
.
setSipStateChangeCallback
(
setModalState
,
'
modalState
'
);
...
@@ -90,33 +92,11 @@ const Root = ({wsphonedata, onSetDnd, setWsphonedata, callMethod}) => {
...
@@ -90,33 +92,11 @@ const Root = ({wsphonedata, onSetDnd, setWsphonedata, callMethod}) => {
};
};
useEffect
(()
=>
{
// useEffect(()=> {
console
.
log
(
'
auto_answer running:
'
,
modalState
.
callType
===
'
incoming
'
&&
modalState
.
bool
)
// console.log('auto_answer running: ', modalState.callType === 'incoming' && modalState.bool)
if
(
modalState
.
callType
===
'
incoming
'
&&
modalState
.
bool
){
//
let
second
// }, [modalState.callType, modalState.bool, useColorConfigStore.state?.autoAnswer, useColorConfigStore.state?.autoAnswerSecond])
if
(
useColorConfigStore
.
state
?.
autoAnswer
)
{
//
switch
(
useColorConfigStore
.
state
?.
autoAnswerSecond
)
{
case
1
:
second
=
1000
break
case
40
:
second
=
3000
break
case
100
:
second
=
6000
break
default
:
second
=
0
}
console
.
log
(
'
auto_answer second:
'
,
second
)
setTimeout
(()
=>
{
console
.
log
(
'
auto_answer run boxDialer.answerButtonClick()
'
)
boxDialer
.
answerButtonClick
()
},
second
)
}
}
},
[
modalState
.
callType
,
modalState
.
bool
,
useColorConfigStore
.
state
?.
autoAnswer
,
useColorConfigStore
.
state
?.
autoAnswerSecond
])
const
selectWidjetType
=
(
type
)
=>
{
const
selectWidjetType
=
(
type
)
=>
{
switch
(
type
)
{
switch
(
type
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment