@exotel-npm-dev/webrtc-client-sdk 2.0.5 → 3.0.2

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.
@@ -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 { FetchTabInfo } from '../constants/common';
4
- import { webrtcSIPPhone } from '@exotel-npm-dev/webrtc-core-sdk';
2
+ import { getLogger } from "@exotel-npm-dev/webrtc-core-sdk";
5
3
 
6
- var logger = webrtcSIPPhone.getLogger();
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 function SessionListener() {
9
+ export class SessionListener {
10
+ sessionCallback = null;
11
+ constructor(sessionCallback) {
12
+ this.sessionCallback = sessionCallback;
13
+ }
12
14
 
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')
15
+ onSessionEstablished = function (session) {
16
+ logger.log("SessionListener: onSessionEstablished");
17
+ this.sessionCallback.triggerCallback("established", session);
18
+ }
41
19
 
42
- const credentials = {
43
- user: window.sessionStorage.getItem('user'),
44
- selectedPhone: window.localStorage.getItem('selectedPhone'),
20
+ onSessionTerminated = function (session) {
21
+ logger.log("SessionListener: onSessionTerminated");
22
+ this.sessionCallback.triggerCallback("terminated", session);
45
23
  }
46
24
 
47
- window.addEventListener('storage', (event) => {
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
- * 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();
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
- 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
- }
64
+ window.addEventListener('storage', (event) => {
66
65
  /**
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'
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
- const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
75
- /** Based on activeSessionTab id fetch the type */
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
- 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 */
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
- if (tabArr.length > 1 && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
82
- if (!document.hidden) {
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
- tabArr.push(currentTab);
89
- window.localStorage.removeItem('tabs');
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
- //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
- };
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
+ }