@exotel-npm-dev/webrtc-client-sdk 1.0.1 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exotel-npm-dev/webrtc-client-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "client sdk for webrtc based on webrtc core sdk",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -195,119 +195,119 @@ export function ExSynchronousHandler() {
195
195
  }
196
196
  }
197
197
 
198
- export const ExotelWebClient = {
198
+ export class ExotelWebClient {
199
199
 
200
200
 
201
201
 
202
- ctrlr : null,
203
- call : null,
204
- eventListener : null,
205
- callListener : null,
202
+ ctrlr = null;
203
+ call = null;
204
+ eventListener = null;
205
+ callListener = null;
206
206
  /* OLD-Way to be revisited for multile phone support */
207
207
  //this.webRTCPhones = {};
208
208
 
209
- sipAccountInfo : null,
209
+ sipAccountInfo = null;
210
210
 
211
- initWebrtc : (sipAccountInfo_,
211
+ initWebrtc = (sipAccountInfo_,
212
212
  RegisterEventCallBack, CallListenerCallback, SessionCallback) => {
213
213
 
214
- if (!ExotelWebClient.eventListener) {
215
- ExotelWebClient.eventListener = new ExotelVoiceClientListener();
214
+ if (!this.eventListener) {
215
+ this.eventListener = new ExotelVoiceClientListener();
216
216
  }
217
217
 
218
- if (!ExotelWebClient.callListener) {
219
- ExotelWebClient.callListener = new CallListener();
218
+ if (!this.callListener) {
219
+ this.callListener = new CallListener();
220
220
  }
221
221
 
222
- if (!ExotelWebClient.ctrlr) {
223
- ExotelWebClient.ctrlr = new CallController();
222
+ if (!this.ctrlr) {
223
+ this.ctrlr = new CallController();
224
224
  }
225
225
 
226
- if (!ExotelWebClient.call) {
227
- ExotelWebClient.call = new Call();
226
+ if (!this.call) {
227
+ this.call = new Call();
228
228
  }
229
229
 
230
230
  logger.log("Exotel Client Initialised with " + JSON.stringify(sipAccountInfo_))
231
- ExotelWebClient.sipAccountInfo = sipAccountInfo_;
232
- if ( !ExotelWebClient.sipAccountInfo["userName"] || !ExotelWebClient.sipAccountInfo["sipdomain"] || !ExotelWebClient.sipAccountInfo["port"]) {
231
+ this.sipAccountInfo = sipAccountInfo_;
232
+ if ( !this.sipAccountInfo["userName"] || !this.sipAccountInfo["sipdomain"] || !this.sipAccountInfo["port"]) {
233
233
  return false;
234
234
  }
235
- ExotelWebClient.sipAccountInfo["sipUri"] = "wss://" + ExotelWebClient.sipAccountInfo["userName"] + "@" + ExotelWebClient.sipAccountInfo["sipdomain"] + ":" + ExotelWebClient.sipAccountInfo["port"];
235
+ this.sipAccountInfo["sipUri"] = "wss://" + this.sipAccountInfo["userName"] + "@" + this.sipAccountInfo["sipdomain"] + ":" + this.sipAccountInfo["port"];
236
236
 
237
237
  callbacks.initializeCallback(CallListenerCallback);
238
238
  registerCallback.initializeRegisterCallback(RegisterEventCallBack);
239
239
  logger.log("Initializing session callback")
240
240
  sessionCallback.initializeSessionCallback(SessionCallback);
241
- ExotelWebClient.setEventListener(ExotelWebClient.eventListener);
241
+ this.setEventListener(this.eventListener);
242
242
  return true;
243
- },
243
+ };
244
244
 
245
- DoRegister : () => {
246
- DoRegisterRL(ExotelWebClient.sipAccountInfo, ExotelWebClient)
247
- },
245
+ DoRegister = () => {
246
+ DoRegisterRL(this.sipAccountInfo, this)
247
+ };
248
248
 
249
- UnRegister : () => {
250
- UnRegisterRL(ExotelWebClient.sipAccountInfo, ExotelWebClient)
251
- },
249
+ UnRegister = () => {
250
+ UnRegisterRL(this.sipAccountInfo, this)
251
+ };
252
252
 
253
- initDiagnostics : (saveDiagnosticsCallback, keyValueSetCallback) => {
253
+ initDiagnostics = (saveDiagnosticsCallback, keyValueSetCallback) => {
254
254
  initDiagnosticsDL(saveDiagnosticsCallback, keyValueSetCallback)
255
- },
255
+ };
256
256
 
257
- closeDiagnostics : () => {
257
+ closeDiagnostics = () => {
258
258
  closeDiagnosticsDL()
259
- },
259
+ };
260
260
 
261
- startSpeakerDiagnosticsTest : () => {
261
+ startSpeakerDiagnosticsTest = () => {
262
262
  startSpeakerDiagnosticsTestDL()
263
- },
263
+ };
264
264
 
265
- stopSpeakerDiagnosticsTest : (speakerTestResponse='none') => {
265
+ stopSpeakerDiagnosticsTest = (speakerTestResponse='none') => {
266
266
  stopSpeakerDiagnosticsTestDL(speakerTestResponse)
267
- },
267
+ };
268
268
 
269
- startMicDiagnosticsTest : () => {
269
+ startMicDiagnosticsTest = () => {
270
270
  startMicDiagnosticsTestDL()
271
- },
271
+ };
272
272
 
273
- stopMicDiagnosticsTest : (micTestResponse='none') => {
273
+ stopMicDiagnosticsTest = (micTestResponse='none') => {
274
274
  stopMicDiagnosticsTestDL(micTestResponse)
275
- },
275
+ };
276
276
 
277
- startNetworkDiagnostics : () => {
277
+ startNetworkDiagnostics = () => {
278
278
  startNetworkDiagnosticsDL()
279
- ExotelWebClient.DoRegister()
280
- },
279
+ this.DoRegister()
280
+ };
281
281
 
282
- stopNetworkDiagnostics : () => {
282
+ stopNetworkDiagnostics = () => {
283
283
  stopNetworkDiagnosticsDL()
284
- },
284
+ };
285
285
 
286
- SessionListener : () => {
286
+ SessionListener = () => {
287
287
  SessionListenerSL()
288
- },
288
+ };
289
289
 
290
290
  /**
291
291
  * function that returns the instance of the call controller object object
292
292
  */
293
293
 
294
- getCallController :() => {
295
- return ExotelWebClient.ctrlr;
296
- },
294
+ getCallController =() => {
295
+ return this.ctrlr;
296
+ };
297
297
 
298
- getCall :() => {
299
- if (!ExotelWebClient.call) {
300
- ExotelWebClient.call = call = new Call();
298
+ getCall =() => {
299
+ if (!this.call) {
300
+ this.call = call = new Call();
301
301
  }
302
- return ExotelWebClient.call;
303
- },
302
+ return this.call;
303
+ };
304
304
 
305
305
  /**
306
306
  * Dummy function to set the event listener object
307
307
  */
308
- setEventListener :(eventListener) => {
309
- ExotelWebClient.eventListener = eventListener;
310
- },
308
+ setEventListener =(eventListener) => {
309
+ this.eventListener = eventListener;
310
+ };
311
311
 
312
312
 
313
313
  /**
@@ -317,42 +317,42 @@ export const ExotelWebClient = {
317
317
  * @param {*} param
318
318
  */
319
319
 
320
- registerEventCallback :(event, phone, param) => {
320
+ registerEventCallback =(event, phone, param) => {
321
321
 
322
322
  logger.log("Dialer: registerEventCallback: Received ---> " + event + 'phone....', phone + 'param....', param)
323
323
  if (event === "connected") {
324
324
  /**
325
325
  * When registration is successful then send the phone number of the same to UI
326
326
  */
327
- ExotelWebClient.eventListener.onInitializationSuccess(phone);
327
+ this.eventListener.onInitializationSuccess(phone);
328
328
  } else if( event === "failed_to_start" || event === "transport_error"){
329
329
  /**
330
330
  * If registration fails
331
331
  */
332
- ExotelWebClient.eventListener.onInitializationFailure(phone);
332
+ this.eventListener.onInitializationFailure(phone);
333
333
  } else if( event === "sent_request"){
334
334
  /**
335
335
  * If registration request waiting...
336
336
  */
337
- ExotelWebClient.eventListener.onInitializationWaiting(phone);
337
+ this.eventListener.onInitializationWaiting(phone);
338
338
  }
339
- },
339
+ };
340
340
  /**
341
341
  * Event listener for calls, any change in sipjsphone will trigger the callback here
342
342
  * @param {*} event
343
343
  * @param {*} phone
344
344
  * @param {*} param
345
345
  */
346
- callEventCallback :(event, phone, param) => {
346
+ callEventCallback =(event, phone, param) => {
347
347
  logger.log("Dialer: callEventCallback: Received ---> " + event + 'param sent....' + param + 'for phone....' + phone)
348
348
  if (event === "i_new_call") {
349
- ExotelWebClient.callListener.onIncomingCall(param,phone)
349
+ this.callListener.onIncomingCall(param,phone)
350
350
  } else if (event === "connected") {
351
- ExotelWebClient.callListener.onCallEstablished(param,phone);
351
+ this.callListener.onCallEstablished(param,phone);
352
352
  } else if (event === "terminated") {
353
- ExotelWebClient.callListener.onCallEnded(param,phone);
353
+ this.callListener.onCallEnded(param,phone);
354
354
  }
355
- },
355
+ };
356
356
 
357
357
  /**
358
358
  * Event listener for diagnostic tests, any change in diagnostic tests will trigger this callback
@@ -360,34 +360,34 @@ export const ExotelWebClient = {
360
360
  * @param {*} phone
361
361
  * @param {*} param
362
362
  */
363
- diagnosticEventCallback :(event, phone, param) => {
363
+ diagnosticEventCallback =(event, phone, param) => {
364
364
  webrtcTroubleshooterEventBus.sendDiagnosticEvent(event, phone, param)
365
- },
365
+ };
366
366
 
367
367
  /**
368
368
  * Function to unregister a phone
369
369
  * @param {*} sipAccountInfo
370
370
  */
371
- unregister :(sipAccountInfo) => {
371
+ unregister =(sipAccountInfo) => {
372
372
  // webrtcSIPPhone.unregister(sipAccountInfo)
373
373
  webrtcSIPPhone.sipUnRegisterWebRTC();
374
- },
374
+ };
375
375
 
376
376
 
377
- webRTCStatusCallbackHandler :(msg1, arg1) => {
377
+ webRTCStatusCallbackHandler =(msg1, arg1) => {
378
378
  logger.log("webRTCStatusCallbackHandler: " + msg1 + " " + arg1)
379
- },
379
+ };
380
380
 
381
381
  /**
382
382
  * initialize function called when user wants to register client
383
383
  */
384
- initialize :(uiContext, hostName,subscriberName,
384
+ initialize =(uiContext, hostName,subscriberName,
385
385
  displayName,accountSid,subscriberToken,
386
386
  sipAccountInfo) => {
387
387
 
388
388
  let wssPort = sipAccountInfo.port;
389
389
  let wsPort = 4442;
390
- ExotelWebClient.sipAccntInfo = {
390
+ this.sipAccntInfo = {
391
391
  'userName':'',
392
392
  'authUser':'',
393
393
  'domain':'',
@@ -397,6 +397,7 @@ export const ExotelWebClient = {
397
397
  'secret':'',
398
398
  'sipUri':'',
399
399
  'security':'',
400
+ 'endpoint':'',
400
401
  'port':'',
401
402
  'contactHost':''
402
403
  }
@@ -406,63 +407,65 @@ export const ExotelWebClient = {
406
407
  fetchPublicIP(sipAccountInfo);
407
408
 
408
409
  /* Temporary till we figure out the arguments - Start */
409
- ExotelWebClient.domain = hostName = sipAccountInfo.domain;
410
- ExotelWebClient.sipdomain = sipAccountInfo.sipdomain;
411
- ExotelWebClient.accountName = ExotelWebClient.userName = sipAccountInfo.userName;
412
- ExotelWebClient.authUser = subscriberName = sipAccountInfo.authUser;
413
- ExotelWebClient.displayName = sipAccountInfo.displayName;
414
- ExotelWebClient.accountSid = 'exotelt1';
415
- ExotelWebClient.subscriberToken = sipAccountInfo.secret;
416
- ExotelWebClient.secret = ExotelWebClient.password = sipAccountInfo.secret;
417
- ExotelWebClient.security = sipAccountInfo.security;
418
- ExotelWebClient.port = sipAccountInfo.port;
419
- ExotelWebClient.contactHost = sipAccountInfo.contactHost;
420
- ExotelWebClient.sipWsPort = 5061;
421
- ExotelWebClient.sipPort = 5061;
422
- ExotelWebClient.sipSecurePort = 5062;
410
+ this.domain = hostName = sipAccountInfo.domain;
411
+ this.sipdomain = sipAccountInfo.sipdomain;
412
+ this.accountName = this.userName = sipAccountInfo.userName;
413
+ this.authUser = subscriberName = sipAccountInfo.authUser;
414
+ this.displayName = sipAccountInfo.displayName;
415
+ this.accountSid = 'exotelt1';
416
+ this.subscriberToken = sipAccountInfo.secret;
417
+ this.secret = this.password = sipAccountInfo.secret;
418
+ this.security = sipAccountInfo.security ? sipAccountInfo.security : "wss";
419
+ this.endpoint = sipAccountInfo.endpoint ? sipAccountInfo.endpoint : "wss";
420
+ this.port = sipAccountInfo.port;
421
+ this.contactHost = sipAccountInfo.contactHost;
422
+ this.sipWsPort = 5061;
423
+ this.sipPort = 5061;
424
+ this.sipSecurePort = 5062;
423
425
  /* Temporary till we figure out the arguments - End */
424
426
 
425
427
  /* This is permanent -Start */
426
428
  let webrtcPort = wssPort;
427
429
 
428
- if (ExotelWebClient.security === 'ws') {
430
+ if (this.security === 'ws') {
429
431
  webrtcPort = wsPort;
430
- }
432
+ }
431
433
 
432
434
 
433
435
 
434
- ExotelWebClient.sipAccntInfo['userName'] = ExotelWebClient.userName;
435
- ExotelWebClient.sipAccntInfo['authUser'] = subscriberName;
436
- ExotelWebClient.sipAccntInfo['domain'] = hostName;
437
- ExotelWebClient.sipAccntInfo['sipdomain'] = ExotelWebClient.sipdomain;
438
- ExotelWebClient.sipAccntInfo['accountName'] = ExotelWebClient.userName;
439
- ExotelWebClient.sipAccntInfo['secret'] = ExotelWebClient.password;
440
- ExotelWebClient.sipAccntInfo['sipuri'] = ExotelWebClient.sipuri;
441
- ExotelWebClient.sipAccntInfo['security'] = ExotelWebClient.security;
442
- ExotelWebClient.sipAccntInfo['port'] = webrtcPort;
443
- ExotelWebClient.sipAccntInfo['contactHost'] = ExotelWebClient.contactHost;
444
- localStorage.setItem('contactHost', ExotelWebClient.contactHost);
436
+ this.sipAccntInfo['userName'] = this.userName;
437
+ this.sipAccntInfo['authUser'] = subscriberName;
438
+ this.sipAccntInfo['domain'] = hostName;
439
+ this.sipAccntInfo['sipdomain'] = this.sipdomain;
440
+ this.sipAccntInfo['accountName'] = this.userName;
441
+ this.sipAccntInfo['secret'] = this.password;
442
+ this.sipAccntInfo['sipuri'] = this.sipuri;
443
+ this.sipAccntInfo['security'] = this.security;
444
+ this.sipAccntInfo['endpoint'] = this.endpoint;
445
+ this.sipAccntInfo['port'] = webrtcPort;
446
+ this.sipAccntInfo['contactHost'] = this.contactHost;
447
+ localStorage.setItem('contactHost', this.contactHost);
445
448
  /* This is permanent -End */
446
449
 
447
450
  /**
448
451
  * Call the webclient function inside this and pass register and call callbacks as arg
449
452
  */
450
- var synchronousHandler = new ExSynchronousHandler(ExotelWebClient);
451
- var delegationHandler = new ExDelegationHandler(ExotelWebClient);
453
+ var synchronousHandler = new ExSynchronousHandler(this);
454
+ var delegationHandler = new ExDelegationHandler(this);
452
455
 
453
- var userName = ExotelWebClient.userName;
456
+ var userName = this.userName;
454
457
  /* OLD-Way to be revisited for multile phone support */
455
458
  //webRTCPhones[userName] = webRTC;
456
459
 
457
460
  /* New-Way */
458
461
  webrtcSIPPhone.registerPhone("sipjs",delegationHandler);
459
- webrtcSIPPhone.registerWebRTCClient(ExotelWebClient.sipAccntInfo, synchronousHandler);
462
+ webrtcSIPPhone.registerWebRTCClient(this.sipAccntInfo, synchronousHandler);
460
463
 
461
464
  /**
462
465
  * Store the intervalID against a map
463
466
  */
464
467
  intervalIDMap.set(userName, intervalId);
465
- }
468
+ };
466
469
  }
467
470
 
468
471
  export default ExotelWebClient;