@exotel-npm-dev/webrtc-client-sdk 1.0.24 → 2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exotel-npm-dev/webrtc-client-sdk",
3
- "version": "1.0.24",
3
+ "version": "2.0.2",
4
4
  "description": "client sdk for webrtc based on webrtc core sdk",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,6 +29,6 @@
29
29
  "webpack-cli": "^4.10.0"
30
30
  },
31
31
  "dependencies": {
32
- "@exotel-npm-dev/webrtc-core-sdk": "1.0.18"
32
+ "@exotel-npm-dev/webrtc-core-sdk": "^1.0.21"
33
33
  }
34
- }
34
+ }
@@ -0,0 +1,40 @@
1
+ const MAX_LOG_LINES = 1000;
2
+ const LOG_STORAGE_KEY = 'webrtc_sdk_logs';
3
+
4
+ const LogManager = {
5
+ onLog(level, msg, args = []) {
6
+ const timestamp = new Date().toISOString();
7
+ const line = `[${timestamp}] [${level.toUpperCase()}] ${msg} ${args.map(arg => JSON.stringify(arg)).join(" ")}`.trim();
8
+
9
+ let logs = JSON.parse(localStorage.getItem(LOG_STORAGE_KEY)) || [];
10
+ logs.push(line);
11
+ if (logs.length > MAX_LOG_LINES) {
12
+ logs = logs.slice(-MAX_LOG_LINES); // rotate
13
+ }
14
+
15
+ localStorage.setItem(LOG_STORAGE_KEY, JSON.stringify(logs));
16
+ },
17
+
18
+ getLogs() {
19
+ return JSON.parse(localStorage.getItem(LOG_STORAGE_KEY)) || [];
20
+ },
21
+
22
+ downloadLogs(filename) {
23
+ if (!filename) {
24
+ const now = new Date();
25
+ const formattedDate = now.toISOString().split('T')[0]; // Gets YYYY-MM-DD
26
+ filename = `webrtc_sdk_logs_${formattedDate}.txt`;
27
+ }
28
+ const blob = new Blob([LogManager.getLogs().join('\n')], { type: 'text/plain' });
29
+ const url = URL.createObjectURL(blob);
30
+
31
+ const a = document.createElement('a');
32
+ a.href = url;
33
+ a.download = filename;
34
+ a.click();
35
+ URL.revokeObjectURL(url);
36
+ },
37
+
38
+ };
39
+
40
+ export default LogManager;
@@ -24,27 +24,34 @@ export function Call() {
24
24
  /**
25
25
  * When agent clicks on mute
26
26
  */
27
- logger.log('mute toggle clicked')
28
- let dummyFlag = null;
29
- webrtcSIPPhone.webRTCMuteUnmute(null);
27
+ logger.log('Call: MuteToggle');
28
+ webrtcSIPPhone.webRTCMuteUnmute();
30
29
  }
31
30
 
32
31
  this.Mute = function () {
33
32
  /**
34
33
  * When agent clicks on mute
35
34
  */
36
- logger.log('mute clicked')
37
- let dummyFlag = true;
38
- webrtcSIPPhone.webRTCMuteUnmute(dummyFlag);
35
+ var isMicEnabled = webrtcSIPPhone.getMuteStatus();
36
+ logger.log('Call: Mute: isMicEnabled: ', isMicEnabled);
37
+ if (isMicEnabled) {
38
+ webrtcSIPPhone.muteAction(true);
39
+ } else {
40
+ logger.log('Call: Mute: Already muted');
41
+ }
39
42
  }
40
-
43
+
41
44
  this.UnMute = function () {
42
45
  /**
43
46
  * When agent clicks on mute
44
47
  */
45
- logger.log('unmute clicked')
46
- let dummyFlag = false;
47
- webrtcSIPPhone.webRTCMuteUnmute(dummyFlag);
48
+ var isMicEnabled = webrtcSIPPhone.getMuteStatus();
49
+ logger.log('Call: UnMute: isMicEnabled: ', isMicEnabled);
50
+ if (isMicEnabled) {
51
+ logger.log('Call: Unmute: Already unmuted');
52
+ } else {
53
+ webrtcSIPPhone.muteAction(false);
54
+ }
48
55
  }
49
56
 
50
57
  this.HoldToggle = function () {
@@ -12,6 +12,7 @@ import { webrtcTroubleshooterEventBus } from "./Callback";
12
12
 
13
13
  import { webrtcSIPPhone } from '@exotel-npm-dev/webrtc-core-sdk';
14
14
  import { CallDetails } from "../api/callAPI/CallDetails";
15
+ import LogManager from '../api/LogManager.js';
15
16
 
16
17
  var intervalId;
17
18
  var intervalIDMap = new Map();
@@ -67,7 +68,7 @@ export function ExDelegationHandler(exClient_) {
67
68
  }
68
69
 
69
70
  this.onCallStatSipJsSessionEvent = function (ev) {
70
- logger.log("delegationHandler: onCallStatSipJsSessionEvent\n");
71
+ logger.log("delegationHandler: onCallStatSipJsSessionEvent",ev);
71
72
  }
72
73
 
73
74
  this.sendWebRTCEventsToFSM = function (eventType, sipMethod) {
@@ -224,9 +225,24 @@ export class ExotelWebClient {
224
225
  //this.webRTCPhones = {};
225
226
 
226
227
  sipAccountInfo = null;
228
+ clientSDKLoggerCallback = null;
229
+
230
+ constructor() {
231
+ /*
232
+ Register the logger callback and emit the onLog event
233
+ */
234
+ logger.registerLoggerCallback(function (type, message, args) {
235
+
236
+ LogManager.onLog(type, message, args);
237
+ if (this.clientSDKLoggerCallback)
238
+ this.clientSDKLoggerCallback("log", arg1, args);
239
+
240
+ });
241
+ }
242
+
227
243
 
228
244
  initWebrtc = (sipAccountInfo_,
229
- RegisterEventCallBack, CallListenerCallback, SessionCallback) => {
245
+ RegisterEventCallBack, CallListenerCallback, SessionCallback, enableAutoAudioDeviceChangeHandling=false) => {
230
246
 
231
247
  if (!this.eventListener) {
232
248
  this.eventListener = new ExotelVoiceClientListener();
@@ -244,7 +260,8 @@ export class ExotelWebClient {
244
260
  this.call = new Call();
245
261
  }
246
262
 
247
- logger.log("Exotel Client Initialised with " + JSON.stringify(sipAccountInfo_))
263
+ sipAccountInfo_.enableAutoAudioDeviceChangeHandling = enableAutoAudioDeviceChangeHandling;
264
+ logger.log("ExWebClient: initWebrtc: Exotel Client Initialised with " + JSON.stringify(sipAccountInfo_))
248
265
  this.sipAccountInfo = sipAccountInfo_;
249
266
  if (!this.sipAccountInfo["userName"] || !this.sipAccountInfo["sipdomain"] || !this.sipAccountInfo["port"]) {
250
267
  return false;
@@ -253,16 +270,16 @@ export class ExotelWebClient {
253
270
 
254
271
  callbacks.initializeCallback(CallListenerCallback);
255
272
  registerCallback.initializeRegisterCallback(RegisterEventCallBack);
256
- logger.log("Initializing session callback")
273
+ logger.log("ExWebClient: initWebrtc: Initializing session callback")
257
274
  sessionCallback.initializeSessionCallback(SessionCallback);
258
275
  this.setEventListener(this.eventListener);
259
276
  return true;
260
277
  };
261
278
 
262
279
  DoRegister = () => {
263
- logger.log("ExWebClient:DoRegister Entry")
280
+ logger.log("ExWebClient: DoRegister: Entry")
264
281
  if (!this.isReadyToRegister) {
265
- logger.warn("ExWebClient:DoRegister SDK is not ready to register");
282
+ logger.warn("ExWebClient: DoRegister: SDK is not ready to register");
266
283
  return false;
267
284
  }
268
285
  DoRegisterRL(this.sipAccountInfo, this);
@@ -270,7 +287,7 @@ export class ExotelWebClient {
270
287
  };
271
288
 
272
289
  UnRegister = () => {
273
- logger.log("ExWebClient:UnRegister Entry")
290
+ logger.log("ExWebClient: UnRegister: Entry")
274
291
  UnRegisterRL(this.sipAccountInfo, this)
275
292
  };
276
293
 
@@ -343,7 +360,7 @@ export class ExotelWebClient {
343
360
 
344
361
  registerEventCallback = (event, phone, param) => {
345
362
 
346
- logger.log("Dialer: registerEventCallback: Received ---> " + event + 'phone....', phone + 'param....', param)
363
+ logger.log("ExWebClient: registerEventCallback: Received ---> " + event + 'phone....', phone + 'param....', param)
347
364
  if (event === "connected") {
348
365
  /**
349
366
  * When registration is successful then send the phone number of the same to UI
@@ -351,7 +368,7 @@ export class ExotelWebClient {
351
368
  this.eventListener.onInitializationSuccess(phone);
352
369
  this.registrationInProgress = false;
353
370
  if (this.unregisterInitiated) {
354
- logger.log("ExWebClient:registerEventCallback unregistering due to unregisterInitiated");
371
+ logger.log("ExWebClient: registerEventCallback: unregistering due to unregisterInitiated");
355
372
  this.unregisterInitiated = false;
356
373
  this.unregister();
357
374
  }
@@ -366,7 +383,7 @@ export class ExotelWebClient {
366
383
  this.isReadyToRegister = true;
367
384
  }
368
385
  if (this.shouldAutoRetry) {
369
- logger.log("ExWebClient:registerEventCallback Autoretrying");
386
+ logger.log("ExWebClient: registerEventCallback: Autoretrying");
370
387
  DoRegisterRL(this.sipAccountInfo, this, 5000);
371
388
  }
372
389
  } else if (event === "sent_request") {
@@ -383,7 +400,7 @@ export class ExotelWebClient {
383
400
  * @param {*} param
384
401
  */
385
402
  callEventCallback = (event, phone, param) => {
386
- logger.log("Dialer: callEventCallback: Received ---> " + event + 'param sent....' + param + 'for phone....' + phone)
403
+ logger.log("ExWebClient: callEventCallback: Received ---> " + event + 'param sent....' + param + 'for phone....' + phone)
387
404
  if (event === "i_new_call") {
388
405
  this.callListener.onIncomingCall(param, phone)
389
406
  } else if (event === "connected") {
@@ -408,7 +425,7 @@ export class ExotelWebClient {
408
425
  * @param {*} sipAccountInfo
409
426
  */
410
427
  unregister = (sipAccountInfo) => {
411
- logger.log("ExWebClient:unregister Entry");
428
+ logger.log("ExWebClient: unregister: Entry");
412
429
  this.shouldAutoRetry = false;
413
430
  this.unregisterInitiated = true;
414
431
  if (!this.registrationInProgress) {
@@ -420,7 +437,7 @@ export class ExotelWebClient {
420
437
 
421
438
 
422
439
  webRTCStatusCallbackHandler = (msg1, arg1) => {
423
- logger.log("webRTCStatusCallbackHandler: " + msg1 + " " + arg1)
440
+ logger.log("ExWebClient: webRTCStatusCallbackHandler: " + msg1 + " " + arg1)
424
441
  };
425
442
 
426
443
  /**
@@ -449,7 +466,7 @@ export class ExotelWebClient {
449
466
  'contactHost': ''
450
467
  }
451
468
 
452
- logger.log('Sending register for the number..', subscriberName);
469
+ logger.log('ExWebClient: initialize: Sending register for the number..', subscriberName);
453
470
 
454
471
  fetchPublicIP(sipAccountInfo);
455
472
 
@@ -505,7 +522,7 @@ export class ExotelWebClient {
505
522
  //webRTCPhones[userName] = webRTC;
506
523
 
507
524
  /* New-Way */
508
- webrtcSIPPhone.registerPhone("sipjs", delegationHandler);
525
+ webrtcSIPPhone.registerPhone("sipjs", delegationHandler, sipAccountInfo.enableAutoAudioDeviceChangeHandling);
509
526
  webrtcSIPPhone.registerWebRTCClient(this.sipAccntInfo, synchronousHandler);
510
527
 
511
528
  /**
@@ -557,28 +574,33 @@ export class ExotelWebClient {
557
574
  }
558
575
  })
559
576
  .catch(function (error) {
560
- logger.log("something went wrong during checkClientStatus ", error);
577
+ logger.log("ExWebClient: checkClientStatus: something went wrong during checkClientStatus ", error);
561
578
  callback("media_permission_denied");
562
579
  });
563
580
  };
564
581
 
565
- changeAudioInputDevice(deviceId, onSuccess, onError) {
566
- logger.log(`in changeAudioInputDevice() of ExWebClient.js`);
567
- webrtcSIPPhone.changeAudioInputDevice(deviceId, onSuccess, onError);
582
+ changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange = false) {
583
+ logger.log(`ExWebClient: changeAudioInputDevice: Entry`);
584
+ webrtcSIPPhone.changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange);
568
585
  }
569
586
 
570
- changeAudioOutputDevice(deviceId, onSuccess, onError) {
571
- logger.log(`in changeAudioOutputDevice() of ExWebClient.js`);
572
- webrtcSIPPhone.changeAudioOutputDevice(deviceId, onSuccess, onError);
587
+ changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange = false) {
588
+ logger.log(`ExWebClient: changeAudioOutputDevice: Entry`);
589
+ webrtcSIPPhone.changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange);
590
+ }
591
+
592
+ downloadLogs() {
593
+ logger.log(`ExWebClient: downloadLogs: Entry`);
594
+ LogManager.downloadLogs();
573
595
  }
574
596
 
575
597
  setPreferredCodec(codecName) {
576
- logger.log("ExWebClient:setPreferredCodec entry");
598
+ logger.log("ExWebClient: setPreferredCodec: Entry");
577
599
  webrtcSIPPhone.setPreferredCodec(codecName);
578
600
  }
579
601
 
580
602
  registerLoggerCallback(callback) {
581
- logger.registerLoggerCallback(callback);
603
+ this.clientSDKLoggerCallback = callback;
582
604
  }
583
605
 
584
606
  registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback) {