@exotel-npm-dev/webrtc-client-sdk 1.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.
@@ -0,0 +1,43 @@
1
+ import { webrtcLogger } from "../omAPI/WebrtcLogger"
2
+
3
+ var logger = webrtcLogger()
4
+
5
+ /**
6
+ * Function to register the phone onto a webRTC client
7
+ * @param {*} sipAccountInfo
8
+ * @param {*} exWebClient
9
+ */
10
+ export function DoRegister(sipAccountInfo, exWebClient) {
11
+ /**
12
+ * When user registers the agent phone for the first time, register your callback onto webrtc client
13
+ */
14
+ let userContext = "IN";
15
+ /**
16
+ * CHANGE IS REQUIRED - in the initialize function provision is to be given to pass Callback functions as arguments
17
+ */
18
+ try {
19
+ exWebClient.initialize(userContext,
20
+ sipAccountInfo.domain, //hostname
21
+ sipAccountInfo.userName, //subscriberName
22
+ sipAccountInfo.displayname,//displayName
23
+ sipAccountInfo.accountSid,//accountSid
24
+ '', sipAccountInfo); // subscriberToken
25
+ } catch(e) {
26
+ logger.log("Register failed ", e)
27
+ }
28
+
29
+ }
30
+
31
+
32
+ /**
33
+ * Function to UnRegister the phone from a webRTC client
34
+ * @param {*} sipAccountInfo
35
+ * @param {*} exWebClient
36
+ */
37
+ export function UnRegister(sipAccountInfo, exWebClient){
38
+ try {
39
+ exWebClient.unregister(sipAccountInfo);
40
+ } catch (e) {
41
+ logger.log("Unregister failed ", e)
42
+ }
43
+ }
@@ -0,0 +1,6 @@
1
+ export const NETWORK_ERROR = 'NETWORK_ERROR';
2
+ export const INTERNAL_ERROR = 'INTERNAL_ERROR';
3
+ export const AUTHENTICATION_INVALID_TOKEN = 'AUTHENTICATION_INVALID_TOKEN';
4
+ export const AUTHENTICATION_EXPIRED_TOKEN = 'AUTHENTICATION_EXPIRED_TOKEN';
5
+ export const SERVER_ERROR = 'SERVER_ERROR';
6
+
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Function to fetch the tab details from tabID
3
+ */
4
+ export function FetchTabInfo(tabID){
5
+ const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
6
+ for(var x=0; x<tabArr.length; x++){
7
+ if(tabArr[x].tabID == tabID){
8
+ return tabArr[x];
9
+ }
10
+ }
11
+ return null;
12
+ }
@@ -0,0 +1,8 @@
1
+ export function CallController() {
2
+ /**
3
+ * Dummy function to set Call listener object
4
+ */
5
+ this.setCallListener = function(callListener) {
6
+ this.callListener = callListener;
7
+ }
8
+ }
@@ -0,0 +1,38 @@
1
+ import { webrtcLogger } from "../api/omAPI/WebrtcLogger"
2
+ import { callbacks } from "./Callback";
3
+
4
+ var logger = webrtcLogger()
5
+
6
+ export function CallListener() {
7
+ this.onIncomingCall = function(call,phone){
8
+ /**
9
+ * When there is an incoming call, [INVITE is received on SIP] send a call back to the
10
+ */
11
+ logger.log("CallListener:Initialise call")
12
+ callbacks.initializeCall(call,phone)
13
+
14
+ /** Triggers the callback on the UI end with message indicating it to be an incoming call */
15
+ logger.log("CallListener:Trigger Incoming")
16
+ callbacks.triggerCallback("incoming");
17
+ }
18
+ this.onCallEstablished = function(call,phone){
19
+ /**
20
+ * When connection is established [ACK is sent by other party on SIP]
21
+ */
22
+ logger.log("CallListener:Initialise call")
23
+ callbacks.initializeCall(call,phone)
24
+ /** Triggers the callback on the UI end with message indicating call has been established*/
25
+ logger.log("CallListener:Trigger Connected")
26
+ callbacks.triggerCallback("connected")
27
+ }
28
+ this.onCallEnded = function(call,phone) {
29
+ /**
30
+ * When other party ends the call [BYE is received and sent by SIP]
31
+ */
32
+ logger.log("CallListener:Initialise call")
33
+ callbacks.initializeCall(call,phone)
34
+ /** Triggers the callback on the UI end with message indicating call has ended */
35
+ logger.log("CallListener:Trigger Call Ended")
36
+ callbacks.triggerCallback("callEnded")
37
+ }
38
+ }
@@ -0,0 +1,176 @@
1
+ import { webrtcLogger } from "../api/omAPI/WebrtcLogger"
2
+
3
+ var logger = webrtcLogger()
4
+
5
+ /**
6
+ * The call backs are called through this function. First initiates the call object and then
7
+ * triggers the callback to indicate the same
8
+ */
9
+
10
+ /**
11
+ * Initializes call event callbacks and also sends to which phone callback was received
12
+ */
13
+ export var callbacks = {
14
+ callback: null,
15
+ call: null,
16
+ phone:'',
17
+ initializeCallback: function(CallListenerCallback){
18
+ this.callback = CallListenerCallback;
19
+ },
20
+ initializeCall: function(call, phone){
21
+ this.call = call;
22
+ this.phone = phone;
23
+ },
24
+ triggerCallback: function(eventType){
25
+ const callbackFunc = this.callback;
26
+ const call = this.call;
27
+ return callbackFunc(call, eventType, this.phone);
28
+ }
29
+ };
30
+ /**
31
+ * Initializes register callback and also sets to which phone registration was renewed
32
+ */
33
+ export var registerCallback = {
34
+ registerCallbackHandler :null,
35
+ registerState: null,
36
+ phone:'',
37
+ initializeRegisterCallback: function(RegisterEventCallBack){
38
+ registerCallback.registerCallbackHandler = RegisterEventCallBack;
39
+ },
40
+ initializeRegister: function(state, phone){
41
+ registerCallback.registerState = state;
42
+ registerCallback.phone = phone;
43
+ },
44
+ triggerRegisterCallback: function(){
45
+ const callbackFunc = registerCallback.registerCallbackHandler;
46
+ const state = registerCallback.registerState
47
+ return callbackFunc(state, registerCallback.phone);
48
+ }
49
+ };
50
+ /**
51
+ * Sets all the phone instances
52
+ */
53
+ export var phoneInstance = {
54
+ phones:[],
55
+ addPhone: function(webRTCPhone){
56
+ const { length } = this.phones;
57
+ const id = length + 1;
58
+ const found = this.phones.some(el => el.username === webRTCPhone.username);
59
+ if (!found) this.phones.push(webRTCPhone);
60
+
61
+ },
62
+ getPhone: function(phone){
63
+ for(var x=0; x<this.phones.length; x++){
64
+ if(this.phones[x].username == phone){
65
+ logger.log('Username...' + this.phones[x].username);
66
+ return this.phones[x];
67
+ }
68
+ }
69
+ },
70
+ getPhones: function(){
71
+ return this.phones;
72
+ },
73
+ removePhone: function(phone){
74
+ for(var x=0; x<this.phones.length; x++){
75
+ if(this.phones[x].username == phone){
76
+ this.phones.splice(x, 1);
77
+ }
78
+ }
79
+ }
80
+ };
81
+
82
+ export var sessionCallback = {
83
+ sessioncallback: null,
84
+ callState: null,
85
+ document: null,
86
+ documentCallback: null,
87
+ phone:'',
88
+ initializeSessionCallback: function(SessionCallback) {
89
+ this.sessioncallback = SessionCallback;
90
+ },
91
+ intializeDocumentCallback: function(DocumentCallback){
92
+ this.documentCallback = DocumentCallback;
93
+ },
94
+ initializeSession: function(state, phone){
95
+ this.callState = state;
96
+ this.phone = phone;
97
+ },
98
+ initializeDocument: function(calldocument){
99
+ this.document = calldocument;
100
+ },
101
+ triggerDocumentCallback: function(){
102
+ const documentCallbackFunc = this.documentCallback;
103
+ return documentCallbackFunc(this.document);
104
+ },
105
+ triggerSessionCallback: function() {
106
+ const sessionCallBackFunc = this.sessioncallback;
107
+ if (sessionCallBackFunc) {
108
+ return sessionCallBackFunc(this.callState, this.phone);
109
+ } else {
110
+ logger.log("Session callback is null")
111
+ return;
112
+ }
113
+ }
114
+ }
115
+
116
+ export var diagnosticsCallback = {
117
+ saveDiagnosticsCallback: null,
118
+ keyValueSetCallback: null,
119
+
120
+ setDiagnosticsReportCallback: function(saveDiagnosticsCallback) {
121
+ window.localStorage.setItem('troubleShootReport', "")
122
+ this.saveDiagnosticsCallback = saveDiagnosticsCallback;
123
+ },
124
+ setKeyValueCallback: function(keyValueSetCallback) {
125
+ this.keyValueSetCallback = keyValueSetCallback;
126
+ },
127
+
128
+ triggerDiagnosticsSaveCallback: function(saveStatus, saveDescription){
129
+ this.saveDiagnosticsCallback(saveStatus, saveDescription);
130
+ return true;
131
+ },
132
+ triggerKeyValueSetCallback: function(key, status, value){
133
+ if (this.keyValueSetCallback) {
134
+ this.keyValueSetCallback(key, status, value);
135
+ }
136
+ return true;
137
+ },
138
+
139
+ }
140
+
141
+ export var webrtcTroubleshooterEventBus = {
142
+
143
+ microphoneTestSuccessEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("mic", 100, "mic ok");},
144
+ microphoneTestFailedEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("mic", 0, "mic failed");},
145
+ microphoneTestDoneEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("mic", 0, "mic done");},
146
+ speakerTestSuccessEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("speaker", true, "speaker ok");},
147
+ speakerTestFailedEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("speaker", false, "speaker failed");},
148
+ speakerTestDoneEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("speaker", false, "speaker done");},
149
+ wsConTestSuccessEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("wss","connected", "ws ok"); },
150
+ wsConTestFailedEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("wss","disconnected", "ws failed"); },
151
+ wsConTestDoneEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("wss","error", "ws done"); },
152
+ userRegTestSuccessEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("userReg","registered", "registered");},
153
+ userRegTestFailedEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("userReg","unregistered", "unregistered");},
154
+ userRegTestDoneEvent: function () {diagnosticsCallback.triggerKeyValueSetCallback("userReg","error", "error done");},
155
+ udpTestCompletedEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("udp", true,"udp ok");},
156
+ tcpTestCompletedEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("tcp",true, "tcp ok"); },
157
+ ipv6TestCompletedEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("ipv6", false, "ipv6 done");},
158
+ hostCandidateTestCompletedEvent: function () { diagnosticsCallback.triggerKeyValueSetCallback("host",true, "host ok");},
159
+ reflexCandidateTestCompletedEvent: function (event, phone, param) {
160
+ logger.log("diagnosticEventCallback: Received ---> " + event + 'param sent....' + param + 'for phone....' + phone)
161
+ diagnosticsCallback.triggerKeyValueSetCallback("srflx",true, "reflex ok");
162
+ }
163
+ }
164
+
165
+
166
+ export var timerSession = {
167
+
168
+ callTimer: '',
169
+ getTimer: function(){
170
+ return this.callTimer;
171
+ },
172
+ setCallTimer: function(callTimer){
173
+ this.callTimer = callTimer;
174
+ window.localStorage.setItem('callTimer', callTimer)
175
+ }
176
+ }