@exotel-npm-dev/webrtc-client-sdk 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog +9 -0
- package/dist/exotelsdk.js +1881 -1536
- package/dist/exotelsdk.js.map +1 -1
- package/index.js +2 -1
- package/package.json +2 -2
- package/src/api/callAPI/Call.js +17 -13
- package/src/api/omAPI/Diagnostics.js +48 -19
- package/src/api/omAPI/DiagnosticsListener.js +19 -8
- package/src/api/registerAPI/RegisterListener.js +2 -2
- package/src/listeners/CallListener.js +28 -31
- package/src/listeners/Callback.js +59 -50
- package/src/listeners/ExWebClient.js +216 -200
- package/src/listeners/ExotelVoiceClientListener.js +18 -7
- package/src/listeners/SessionListeners.js +114 -96
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { registerCallback } from "./Callback";
|
|
2
1
|
import { diagnosticsCallback } from "./Callback";
|
|
3
2
|
|
|
4
3
|
export class ExotelVoiceClientListener {
|
|
4
|
+
|
|
5
|
+
registerCallback = null;
|
|
6
|
+
constructor(registerCallback) {
|
|
7
|
+
this.registerCallback = registerCallback;
|
|
8
|
+
|
|
9
|
+
}
|
|
5
10
|
onInitializationSuccess(phone) {
|
|
6
11
|
/**
|
|
7
12
|
* Abstract class for Initialization Success
|
|
8
13
|
*/
|
|
9
|
-
registerCallback.initializeRegister("registered", phone);
|
|
14
|
+
this.registerCallback.initializeRegister("registered", phone);
|
|
10
15
|
/**
|
|
11
16
|
* Triggers UI callback to indicate the status of the registered phone
|
|
12
17
|
*/
|
|
13
|
-
registerCallback.triggerRegisterCallback();
|
|
18
|
+
this.registerCallback.triggerRegisterCallback();
|
|
14
19
|
diagnosticsCallback.triggerKeyValueSetCallback("userReg", "registered", phone);
|
|
15
20
|
}
|
|
16
21
|
|
|
@@ -18,8 +23,8 @@ export class ExotelVoiceClientListener {
|
|
|
18
23
|
/**
|
|
19
24
|
* If register fails send error message to Callback function
|
|
20
25
|
*/
|
|
21
|
-
registerCallback.initializeRegister("unregistered", phone);
|
|
22
|
-
registerCallback.triggerRegisterCallback();
|
|
26
|
+
this.registerCallback.initializeRegister("unregistered", phone);
|
|
27
|
+
this.registerCallback.triggerRegisterCallback();
|
|
23
28
|
diagnosticsCallback.triggerKeyValueSetCallback("userReg", "unregistered", phone);
|
|
24
29
|
}
|
|
25
30
|
|
|
@@ -27,11 +32,17 @@ export class ExotelVoiceClientListener {
|
|
|
27
32
|
/**
|
|
28
33
|
* If register fails send error message to Callback function
|
|
29
34
|
*/
|
|
30
|
-
registerCallback.initializeRegister("sent_request", phone);
|
|
31
|
-
registerCallback.triggerRegisterCallback();
|
|
35
|
+
this.registerCallback.initializeRegister("sent_request", phone);
|
|
36
|
+
this.registerCallback.triggerRegisterCallback();
|
|
32
37
|
diagnosticsCallback.triggerKeyValueSetCallback("userReg", "sent_request", phone);
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
onRegistrationStateChanged(state, phone) {
|
|
41
|
+
this.registerCallback.initializeRegister(state, phone);
|
|
42
|
+
this.registerCallback.triggerRegisterCallback();
|
|
43
|
+
diagnosticsCallback.triggerKeyValueSetCallback("userReg", state, phone);
|
|
44
|
+
}
|
|
45
|
+
|
|
35
46
|
onLog(LogLevel, tag, message) {
|
|
36
47
|
/**
|
|
37
48
|
* To get SDK logs
|
|
@@ -1,123 +1,141 @@
|
|
|
1
|
-
import { sessionCallback } from './Callback';
|
|
2
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
-
import {
|
|
4
|
-
import { webrtcSIPPhone } from '@exotel-npm-dev/webrtc-core-sdk';
|
|
2
|
+
import { getLogger } from "@exotel-npm-dev/webrtc-core-sdk";
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
const logger = getLogger();
|
|
7
5
|
/**
|
|
8
6
|
* Session listeners is invoked when user opens two tabs, the data in tab 1 is
|
|
9
7
|
* copied into tab 2
|
|
10
8
|
*/
|
|
11
|
-
export
|
|
9
|
+
export class SessionListener {
|
|
10
|
+
sessionCallback = null;
|
|
11
|
+
constructor(sessionCallback) {
|
|
12
|
+
this.sessionCallback = sessionCallback;
|
|
13
|
+
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
sessionCallback.initializeSession('re-register', event.data.hashMsg);
|
|
18
|
-
sessionCallback.triggerSessionCallback();
|
|
19
|
-
} else if (event.data.message == 'logout') {
|
|
20
|
-
sessionCallback.initializeSession('logout', '');
|
|
21
|
-
sessionCallback.triggerSessionCallback();
|
|
22
|
-
} else if (event.data.message == 'login-successful') {
|
|
23
|
-
const loginObj = {
|
|
24
|
-
phone: window.localStorage.getItem('currentUser'),
|
|
25
|
-
tabHash: event.data.tabHash
|
|
26
|
-
}
|
|
27
|
-
sessionCallback.initializeSession('login-successful', JSON.stringify(loginObj));
|
|
28
|
-
sessionCallback.triggerSessionCallback();
|
|
29
|
-
} else if (window.sessionStorage.getItem("activeSessionTab") !== null) {
|
|
30
|
-
if (event.data.callState !== null && event.data.callState !== undefined) {
|
|
31
|
-
sessionCallback.initializeSession(event.data.callState, event.data.callNumber);
|
|
32
|
-
}
|
|
33
|
-
sessionCallback.triggerSessionCallback();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Add listeners for all storage events
|
|
38
|
-
*/
|
|
39
|
-
window.localStorage.setItem('REQUESTING_SHARED_CREDENTIALS', Date.now().toString())
|
|
40
|
-
window.localStorage.removeItem('REQUESTING_SHARED_CREDENTIALS')
|
|
15
|
+
onSessionEstablished = function (session) {
|
|
16
|
+
logger.log("SessionListener: onSessionEstablished");
|
|
17
|
+
this.sessionCallback.triggerCallback("established", session);
|
|
18
|
+
}
|
|
41
19
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
onSessionTerminated = function (session) {
|
|
21
|
+
logger.log("SessionListener: onSessionTerminated");
|
|
22
|
+
this.sessionCallback.triggerCallback("terminated", session);
|
|
45
23
|
}
|
|
46
24
|
|
|
47
|
-
|
|
25
|
+
onSessionEvent(event) {
|
|
26
|
+
this.sessionCallback.triggerSessionCallback(event);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onTBD() {
|
|
30
|
+
const channel = new BroadcastChannel('app-data');
|
|
31
|
+
channel.addEventListener('message', (event) => {
|
|
32
|
+
if (event.data.message == "re-register-needed") {
|
|
33
|
+
/** Send the hash to app seeking for reregistration */
|
|
34
|
+
this.sessionCallback.initializeSession('re-register', event.data.hashMsg);
|
|
35
|
+
this.sessionCallback.triggerSessionCallback();
|
|
36
|
+
} else if (event.data.message == 'logout') {
|
|
37
|
+
this.sessionCallback.initializeSession('logout', '');
|
|
38
|
+
this.sessionCallback.triggerSessionCallback();
|
|
39
|
+
} else if (event.data.message == 'login-successful') {
|
|
40
|
+
const loginObj = {
|
|
41
|
+
phone: window.localStorage.getItem('currentUser'),
|
|
42
|
+
tabHash: event.data.tabHash
|
|
43
|
+
}
|
|
44
|
+
this.sessionCallback.initializeSession('login-successful', JSON.stringify(loginObj));
|
|
45
|
+
this.sessionCallback.triggerSessionCallback();
|
|
46
|
+
} else if (window.sessionStorage.getItem("activeSessionTab") !== null) {
|
|
47
|
+
if (event.data.callState !== null && event.data.callState !== undefined) {
|
|
48
|
+
this.sessionCallback.initializeSession(event.data.callState, event.data.callNumber);
|
|
49
|
+
}
|
|
50
|
+
this.sessionCallback.triggerSessionCallback();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
48
53
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//sessionCallback.triggerSessionCallback();
|
|
54
|
+
* Add listeners for all storage events
|
|
55
|
+
*/
|
|
56
|
+
window.localStorage.setItem('REQUESTING_SHARED_CREDENTIALS', Date.now().toString())
|
|
57
|
+
window.localStorage.removeItem('REQUESTING_SHARED_CREDENTIALS')
|
|
58
|
+
|
|
59
|
+
const credentials = {
|
|
60
|
+
user: window.sessionStorage.getItem('user'),
|
|
61
|
+
selectedPhone: window.localStorage.getItem('selectedPhone'),
|
|
58
62
|
}
|
|
59
|
-
if (event.key === 'CREDENTIALS_SHARING' && credentials !== null) {
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
if (event.newValue !== null) {
|
|
63
|
-
window.sessionStorage.setItem('user', newData.user);
|
|
64
|
-
window.sessionStorage.setItem('isAuthenticated', true);
|
|
65
|
-
}
|
|
64
|
+
window.addEventListener('storage', (event) => {
|
|
66
65
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
* When user tries to duplicate tab, this gets called in Tab1
|
|
67
|
+
*/
|
|
68
|
+
if (event.key === 'REQUESTING_SHARED_CREDENTIALS' && credentials) {
|
|
69
|
+
window.localStorage.setItem('CREDENTIALS_SHARING', JSON.stringify(credentials))
|
|
70
|
+
window.localStorage.removeItem('CREDENTIALS_SHARING')
|
|
71
|
+
/**
|
|
72
|
+
* When the data is to be shared between two tabs then add the current state onto that session storage
|
|
73
|
+
*/
|
|
74
|
+
//sessionCallback.triggerSessionCallback();
|
|
73
75
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
if (event.key === 'CREDENTIALS_SHARING' && credentials !== null) {
|
|
77
|
+
|
|
78
|
+
const newData = JSON.parse(event.newValue);
|
|
79
|
+
if (event.newValue !== null) {
|
|
80
|
+
window.sessionStorage.setItem('user', newData.user);
|
|
81
|
+
window.sessionStorage.setItem('isAuthenticated', true);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Fetch the array of tabs and add the tab, put it on session also
|
|
85
|
+
*/
|
|
86
|
+
const currentTab = {
|
|
87
|
+
tabID: uuidv4(),
|
|
88
|
+
tabType: 'child',
|
|
89
|
+
tabStatus: 'active'
|
|
90
|
+
}
|
|
91
|
+
const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
|
|
92
|
+
/** Based on activeSessionTab id fetch the type */
|
|
93
|
+
|
|
94
|
+
if (window.sessionStorage.getItem('activeSessionTab') !== null && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
|
|
95
|
+
logger.log('Adding a child tab spawned from parent....');
|
|
96
|
+
/** In order to keep tabID same for all the child ones, we are using below IF to distinguish */
|
|
76
97
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
98
|
+
if (tabArr.length > 1 && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
|
|
99
|
+
if (!document.hidden) {
|
|
100
|
+
const lastIndex = (tabArr.length) - 1;
|
|
101
|
+
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
102
|
+
}
|
|
80
103
|
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
} else {
|
|
105
|
+
tabArr.push(currentTab);
|
|
106
|
+
window.localStorage.removeItem('tabs');
|
|
107
|
+
window.localStorage.setItem('tabs', JSON.stringify(tabArr));
|
|
83
108
|
const lastIndex = (tabArr.length) - 1;
|
|
84
109
|
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
85
110
|
}
|
|
86
111
|
|
|
112
|
+
|
|
87
113
|
} else {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
window.localStorage.setItem('tabs', JSON.stringify(tabArr));
|
|
114
|
+
/** pull from the tabarray and then add it to the session storage */
|
|
115
|
+
|
|
91
116
|
const lastIndex = (tabArr.length) - 1;
|
|
92
117
|
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
93
118
|
}
|
|
119
|
+
//window.localStorage.setItem('selectedPhone', newData.selectedPhone);
|
|
120
|
+
return;
|
|
121
|
+
//}
|
|
94
122
|
|
|
95
|
-
|
|
96
|
-
} else {
|
|
97
|
-
/** pull from the tabarray and then add it to the session storage */
|
|
98
|
-
|
|
99
|
-
const lastIndex = (tabArr.length) - 1;
|
|
100
|
-
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
101
123
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
window.sessionStorage.removeItem('activeSession');
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
+
/**
|
|
125
|
+
* When a tab is closed
|
|
126
|
+
*/
|
|
127
|
+
if (event.key === 'CREDENTIALS_FLUSH' && credentials) {
|
|
128
|
+
window.sessionStorage.removeItem('user');
|
|
129
|
+
window.sessionStorage.removeItem('selectedPhone');
|
|
130
|
+
window.sessionStorage.removeItem('isAuthenticated')
|
|
131
|
+
window.sessionStorage.removeItem('activeSession');
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* When any tab is closed, active call gets terminated
|
|
135
|
+
*/
|
|
136
|
+
if (event.key === 'CALL_FLUSH') {
|
|
137
|
+
window.sessionStorage.removeItem('activeSession');
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|