1
1
import { v4 as uuidv4 } from 'uuid' ;
2
2
3
- const deafultHeartbeatIntervalMs = 15 * 1000 ;
4
- const deafultHeartbeatReadTimeoutMs = 45 * 1000 ;
3
+ const defaultHeartbeatIntervalMs = 15 * 1000 ;
4
+ const defaultHeartbeatReadTimeoutMs = 45 * 1000 ;
5
5
6
6
const validCallStates = {
7
7
None : 'None' ,
@@ -13,17 +13,17 @@ const isValidCallState = (callState, callHref) => {
13
13
return false ;
14
14
}
15
15
16
- return ( callState === validCallStates . None )
17
- || ( typeof callHref === 'string' && callHref !== '' ) ;
16
+ return callState === validCallStates . None || ( typeof callHref === 'string' && callHref !== '' ) ;
18
17
} ;
19
18
20
19
const getHeartbeat = ( voipHeartbeatHandler ) => {
21
20
const now = new Date ( ) . toISOString ( ) ;
22
- const { customerCode, sessionId, callState, callHref } = voipHeartbeatHandler ;
21
+ const { customerCode, sessionId, participantType , callState, callHref } = voipHeartbeatHandler ;
23
22
return {
24
23
type : 'HEARTBEAT' ,
25
24
at_time : now ,
26
25
session_id : sessionId ,
26
+ participant_type : participantType ,
27
27
customer : customerCode ,
28
28
current_call_state : callState ,
29
29
current_call_href : callHref ,
@@ -44,19 +44,22 @@ class VoipHeartbeatHandler {
44
44
* Track API
45
45
* @param {number } [options.heartbeatReadTimeoutMs] The time to wait for receiving a heartbeat
46
46
* from Track API
47
+ * @param {string } [options.participantType] Indication of the type of participant that is
48
+ * reporting a heartbeat. Valid values are "User" (default) and "Supervisor"
47
49
*/
48
50
constructor ( realTimeClient , customerCode , options = { } ) {
49
51
this . realTimeClient = realTimeClient ;
50
52
this . customerCode = customerCode ;
51
53
52
54
// uuidv4 is randomly generated.
53
55
this . sessionId = uuidv4 ( ) ;
56
+ this . participantType = options . participantType || 'User' ;
54
57
this . callState = validCallStates . None ;
55
58
this . callHref = '' ;
56
59
this . handlers = { } ;
57
60
58
- this . heartbeatIntervalMs = options . heartbeatIntervalMs || deafultHeartbeatIntervalMs ;
59
- this . heartbeatReadTimeoutMs = options . heartbeatReadTimeoutMs || deafultHeartbeatReadTimeoutMs ;
61
+ this . heartbeatIntervalMs = options . heartbeatIntervalMs || defaultHeartbeatIntervalMs ;
62
+ this . heartbeatReadTimeoutMs = options . heartbeatReadTimeoutMs || defaultHeartbeatReadTimeoutMs ;
60
63
61
64
this . setCallState = this . setCallState . bind ( this ) ;
62
65
this . sendHeartbeat = this . sendHeartbeat . bind ( this ) ;
@@ -84,10 +87,7 @@ class VoipHeartbeatHandler {
84
87
throw new Error ( 'Invalid call state.' ) ;
85
88
}
86
89
87
- const {
88
- callState : oldCallState ,
89
- callHref : oldCallHref ,
90
- } = this ;
90
+ const { callState : oldCallState , callHref : oldCallHref } = this ;
91
91
92
92
this . callState = callState ;
93
93
this . callHref = callHref ;
@@ -117,14 +117,8 @@ class VoipHeartbeatHandler {
117
117
}
118
118
this . heartbeatTimeoutInterval = setTimeout ( this . onHeartbeatTimeout , heartbeatReadTimeoutMs ) ;
119
119
120
- const {
121
- desired_call_state : desiredCallState ,
122
- desired_call_href : desiredCallHref ,
123
- } = heartbeat ;
124
- const {
125
- previousDesiredCallState,
126
- previousDesiredCallHref,
127
- } = this ;
120
+ const { desired_call_state : desiredCallState , desired_call_href : desiredCallHref } = heartbeat ;
121
+ const { previousDesiredCallState, previousDesiredCallHref } = this ;
128
122
129
123
const hasDesiredCallStateChanged =
130
124
desiredCallState !== previousDesiredCallState || desiredCallHref !== previousDesiredCallHref ;
@@ -154,11 +148,9 @@ class VoipHeartbeatHandler {
154
148
// actually sent. wait until then until we queue up the next
155
149
// heartbeat.
156
150
const heartbeat = getHeartbeat ( self ) ;
157
- self . realTimeClient
158
- . sendMessage ( heartbeat )
159
- . then ( ( ) => {
160
- self . heartbeatTimeout = setTimeout ( self . sendHeartbeat , heartbeatIntervalMs ) ;
161
- } ) ;
151
+ self . realTimeClient . sendMessage ( heartbeat ) . then ( ( ) => {
152
+ self . heartbeatTimeout = setTimeout ( self . sendHeartbeat , heartbeatIntervalMs ) ;
153
+ } ) ;
162
154
}
163
155
164
156
/**
0 commit comments