@exotel-npm-dev/webrtc-client-sdk 1.0.11 → 1.0.13
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 +4 -1
- package/Makefile +16 -0
- package/dist/exotelsdk.js +491 -220
- package/dist/exotelsdk.js.map +1 -1
- package/package.json +3 -3
- package/src/api/callAPI/Call.js +1 -2
- package/src/api/omAPI/Diagnostics.js +120 -121
- package/src/api/omAPI/DiagnosticsListener.js +13 -12
- package/src/api/registerAPI/RegisterListener.js +12 -12
- package/src/listeners/CallListener.js +10 -10
- package/src/listeners/Callback.js +132 -132
- package/src/listeners/ExWebClient.js +25 -18
- package/src/listeners/ExotelVoiceClientListener.js +9 -9
- package/src/listeners/SessionListeners.js +110 -110
- package/src/api/omAPI/WebrtcLogger.js +0 -55
|
@@ -1,123 +1,123 @@
|
|
|
1
1
|
import { sessionCallback } from './Callback';
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { FetchTabInfo } from '../constants/common';
|
|
4
|
-
import {
|
|
4
|
+
import { webrtcSIPPhone } from '@exotel-npm-dev/webrtc-core-sdk';
|
|
5
5
|
|
|
6
|
-
var logger =
|
|
6
|
+
var logger = webrtcSIPPhone.getLogger();
|
|
7
7
|
/**
|
|
8
8
|
* Session listeners is invoked when user opens two tabs, the data in tab 1 is
|
|
9
9
|
* copied into tab 2
|
|
10
10
|
*/
|
|
11
|
-
export function SessionListener
|
|
11
|
+
export function SessionListener() {
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const channel = new BroadcastChannel('app-data');
|
|
14
|
+
channel.addEventListener('message', (event) => {
|
|
15
|
+
if (event.data.message == "re-register-needed") {
|
|
16
|
+
/** Send the hash to app seeking for reregistration */
|
|
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')
|
|
41
|
+
|
|
42
|
+
const credentials = {
|
|
43
|
+
user: window.sessionStorage.getItem('user'),
|
|
44
|
+
selectedPhone: window.localStorage.getItem('selectedPhone'),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
window.addEventListener('storage', (event) => {
|
|
48
|
+
/**
|
|
49
|
+
* When user tries to duplicate tab, this gets called in Tab1
|
|
50
|
+
*/
|
|
51
|
+
if (event.key === 'REQUESTING_SHARED_CREDENTIALS' && credentials) {
|
|
52
|
+
window.localStorage.setItem('CREDENTIALS_SHARING', JSON.stringify(credentials))
|
|
53
|
+
window.localStorage.removeItem('CREDENTIALS_SHARING')
|
|
54
|
+
/**
|
|
55
|
+
* When the data is to be shared between two tabs then add the current state onto that session storage
|
|
56
|
+
*/
|
|
57
|
+
//sessionCallback.triggerSessionCallback();
|
|
58
|
+
}
|
|
59
|
+
if (event.key === 'CREDENTIALS_SHARING' && credentials !== null) {
|
|
60
|
+
|
|
61
|
+
const newData = JSON.parse(event.newValue);
|
|
62
|
+
if (event.newValue !== null) {
|
|
63
|
+
window.sessionStorage.setItem('user', newData.user);
|
|
64
|
+
window.sessionStorage.setItem('isAuthenticated', true);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Fetch the array of tabs and add the tab, put it on session also
|
|
68
|
+
*/
|
|
69
|
+
const currentTab = {
|
|
70
|
+
tabID: uuidv4(),
|
|
71
|
+
tabType: 'child',
|
|
72
|
+
tabStatus: 'active'
|
|
73
|
+
}
|
|
74
|
+
const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
|
|
75
|
+
/** Based on activeSessionTab id fetch the type */
|
|
76
|
+
|
|
77
|
+
if (window.sessionStorage.getItem('activeSessionTab') !== null && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
|
|
78
|
+
logger.log('Adding a child tab spawned from parent....');
|
|
79
|
+
/** In order to keep tabID same for all the child ones, we are using below IF to distinguish */
|
|
80
|
+
|
|
81
|
+
if (tabArr.length > 1 && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
|
|
82
|
+
if (!document.hidden) {
|
|
83
|
+
const lastIndex = (tabArr.length) - 1;
|
|
84
|
+
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
32
85
|
}
|
|
33
|
-
|
|
86
|
+
|
|
87
|
+
} else {
|
|
88
|
+
tabArr.push(currentTab);
|
|
89
|
+
window.localStorage.removeItem('tabs');
|
|
90
|
+
window.localStorage.setItem('tabs', JSON.stringify(tabArr));
|
|
91
|
+
const lastIndex = (tabArr.length) - 1;
|
|
92
|
+
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
34
93
|
}
|
|
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')
|
|
41
94
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
tabID: uuidv4(),
|
|
71
|
-
tabType: 'child',
|
|
72
|
-
tabStatus: 'active'
|
|
73
|
-
}
|
|
74
|
-
const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
|
|
75
|
-
/** Based on activeSessionTab id fetch the type */
|
|
76
|
-
|
|
77
|
-
if(window.sessionStorage.getItem('activeSessionTab') !== null && window.sessionStorage.getItem('activeSessionTab') == "parent0"){
|
|
78
|
-
logger.log('Adding a child tab spawned from parent....');
|
|
79
|
-
/** In order to keep tabID same for all the child ones, we are using below IF to distinguish */
|
|
80
|
-
|
|
81
|
-
if(tabArr.length > 1 && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
|
|
82
|
-
if(!document.hidden){
|
|
83
|
-
const lastIndex = (tabArr.length) - 1;
|
|
84
|
-
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}else {
|
|
88
|
-
tabArr.push(currentTab);
|
|
89
|
-
window.localStorage.removeItem('tabs');
|
|
90
|
-
window.localStorage.setItem('tabs', JSON.stringify(tabArr));
|
|
91
|
-
const lastIndex = (tabArr.length) - 1;
|
|
92
|
-
window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
|
|
93
|
-
}
|
|
94
|
-
|
|
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
|
-
}
|
|
102
|
-
//window.localStorage.setItem('selectedPhone', newData.selectedPhone);
|
|
103
|
-
return;
|
|
104
|
-
//}
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* When a tab is closed
|
|
109
|
-
*/
|
|
110
|
-
if(event.key === 'CREDENTIALS_FLUSH' && credentials){
|
|
111
|
-
window.sessionStorage.removeItem('user');
|
|
112
|
-
window.sessionStorage.removeItem('selectedPhone');
|
|
113
|
-
window.sessionStorage.removeItem('isAuthenticated')
|
|
114
|
-
window.sessionStorage.removeItem('activeSession');
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* When any tab is closed, active call gets terminated
|
|
118
|
-
*/
|
|
119
|
-
if(event.key === 'CALL_FLUSH'){
|
|
120
|
-
window.sessionStorage.removeItem('activeSession');
|
|
121
|
-
}
|
|
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
|
+
}
|
|
102
|
+
//window.localStorage.setItem('selectedPhone', newData.selectedPhone);
|
|
103
|
+
return;
|
|
104
|
+
//}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* When a tab is closed
|
|
109
|
+
*/
|
|
110
|
+
if (event.key === 'CREDENTIALS_FLUSH' && credentials) {
|
|
111
|
+
window.sessionStorage.removeItem('user');
|
|
112
|
+
window.sessionStorage.removeItem('selectedPhone');
|
|
113
|
+
window.sessionStorage.removeItem('isAuthenticated')
|
|
114
|
+
window.sessionStorage.removeItem('activeSession');
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* When any tab is closed, active call gets terminated
|
|
118
|
+
*/
|
|
119
|
+
if (event.key === 'CALL_FLUSH') {
|
|
120
|
+
window.sessionStorage.removeItem('activeSession');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
123
|
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/* ES6 LOGGER */
|
|
2
|
-
/*
|
|
3
|
-
import Logger from 'node-logger-es6'
|
|
4
|
-
|
|
5
|
-
var es6Logger = Logger.configure(
|
|
6
|
-
{
|
|
7
|
-
level: 'debug',
|
|
8
|
-
rotation: 'd',
|
|
9
|
-
size: 5,
|
|
10
|
-
json: true,
|
|
11
|
-
timestamp: true
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/* CUSTOM-LOGGER */
|
|
17
|
-
/* Note currently customLogger uses console only
|
|
18
|
-
we can replace it with any other logger for
|
|
19
|
-
instances: es6Logger or ameyoLogger or winstonLogger.
|
|
20
|
-
essentially the idea is not to duplicate the logic of
|
|
21
|
-
handling levels and output stream.
|
|
22
|
-
*/
|
|
23
|
-
export var customLogger = {
|
|
24
|
-
|
|
25
|
-
log : (arg1, ...args) => {
|
|
26
|
-
console.log(arg1, args)
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
info : (arg1, ...args) => {
|
|
30
|
-
console.log(arg1, args)
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
warn : (arg1, ...args) => {
|
|
34
|
-
console.log(arg1, args)
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
error : (arg1, ...args) => {
|
|
38
|
-
console.log(arg1, args)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/* CONSOLE LOGGER */
|
|
44
|
-
var consoleLogger = console;
|
|
45
|
-
|
|
46
|
-
/* FINAL LOGGER TO USE */
|
|
47
|
-
export function webrtcLogger() {
|
|
48
|
-
if (customLogger) {
|
|
49
|
-
return customLogger;
|
|
50
|
-
} else {
|
|
51
|
-
return consoleLogger;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|