@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.
package/dist/exotelsdk.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * WebRTC CLient SIP version 2.0.5
3
+ * WebRTC CLient SIP version 3.0.2
4
4
  *
5
5
  */
6
6
  (function webpackUniversalModuleDefinition(root, factory) {
@@ -25,11 +25,13 @@ return /******/ (() => { // webpackBootstrap
25
25
  "use strict";
26
26
  __webpack_require__.r(__webpack_exports__);
27
27
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
28
- /* harmony export */ webrtcSIPPhone: () => (/* reexport safe */ _src_webrtcSIPPhone__WEBPACK_IMPORTED_MODULE_0__.webrtcSIPPhone)
28
+ /* harmony export */ WebrtcSIPPhone: () => (/* reexport safe */ _src_webrtcSIPPhone__WEBPACK_IMPORTED_MODULE_0__["default"]),
29
+ /* harmony export */ getLogger: () => (/* reexport safe */ _src_webrtcSIPPhone__WEBPACK_IMPORTED_MODULE_0__.getLogger)
29
30
  /* harmony export */ });
30
31
  /* harmony import */ var _src_webrtcSIPPhone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/webrtcSIPPhone */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/webrtcSIPPhone.js");
31
32
 
32
33
 
34
+
33
35
  /***/ }),
34
36
 
35
37
  /***/ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/audioDeviceManager.js":
@@ -48,14 +50,13 @@ __webpack_require__.r(__webpack_exports__);
48
50
 
49
51
 
50
52
  const logger = _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__["default"];
51
- let enableAutoAudioDeviceChangeHandling = false;
52
53
  const audioDeviceManager = {
53
54
  resetInputDevice: false,
54
55
  resetOutputDevice: false,
55
56
  currentAudioInputDeviceId: "default",
56
57
  currentAudioOutputDeviceId: "default",
57
58
  mediaDevices: [],
58
-
59
+ enableAutoAudioDeviceChangeHandling: false,
59
60
  // Method to set the resetInputDevice flag
60
61
  setResetInputDeviceFlag(value) {
61
62
  this.resetInputDevice = value;
@@ -69,7 +70,7 @@ const audioDeviceManager = {
69
70
  async changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange) {
70
71
  logger.log(`SIPJSPhone:changeAudioInputDevice entry`);
71
72
  try {
72
- if (enableAutoAudioDeviceChangeHandling && !forceDeviceChange) {
73
+ if (this.enableAutoAudioDeviceChangeHandling && !forceDeviceChange) {
73
74
  if (deviceId == audioDeviceManager.currentAudioInputDeviceId) {
74
75
  logger.log(`SIPJSPhone:changeAudioInputDevice current input device is same as ${deviceId} hence not changing`);
75
76
  if (onError) onError("current input device is same as " + deviceId + " hence not changing");
@@ -94,11 +95,11 @@ const audioDeviceManager = {
94
95
  },
95
96
 
96
97
  async changeAudioOutputDevice(audioRemote, deviceId, onSuccess, onError, forceDeviceChange) {
97
- logger.log(`audioDeviceManager:changeAudioOutputDevice : entry`);
98
+ logger.log(`audioDeviceManager:changeAudioOutputDevice : entry`);
98
99
  const audioElement = audioRemote;
99
100
  if (typeof audioElement.sinkId !== 'undefined') {
100
101
  try {
101
- if (enableAutoAudioDeviceChangeHandling && !forceDeviceChange) {
102
+ if (this.enableAutoAudioDeviceChangeHandling && !forceDeviceChange) {
102
103
  if (deviceId == audioDeviceManager.currentAudioOutputDeviceId) {
103
104
  logger.log(`SIPJSPhone:changeAudioOutputDevice current output device is same as ${deviceId}`);
104
105
  if (onError) onError("current output device is same as " + deviceId);
@@ -123,7 +124,6 @@ const audioDeviceManager = {
123
124
  logger.log(`audioDeviceManager:changeAudioOutputDevice Output device changed to: ${deviceId}`);
124
125
  if (onSuccess) onSuccess();
125
126
 
126
-
127
127
  } catch (error) {
128
128
  logger.error('audioDeviceManager:changeAudioOutputDevice Error changing output device:', error);
129
129
  if (onError) onError(error);
@@ -135,6 +135,10 @@ const audioDeviceManager = {
135
135
  }
136
136
  },
137
137
 
138
+ setEnableAutoAudioDeviceChangeHandling(flag) {
139
+ this.enableAutoAudioDeviceChangeHandling = flag;
140
+ },
141
+
138
142
  async resetAudioDevice(audioRemote, onInputDeviceChangeCallback, onOutputDeviceChangeCallback) {
139
143
  audioDeviceManager._resetAudioDevice(audioRemote, onInputDeviceChangeCallback, onOutputDeviceChangeCallback, audioDeviceManager.resetOutputDevice, audioDeviceManager.resetInputDevice);
140
144
  },
@@ -182,10 +186,6 @@ const audioDeviceManager = {
182
186
  if (callback) callback();
183
187
  },
184
188
 
185
- setEnableAutoAudioDeviceChangeHandling(flag) {
186
- enableAutoAudioDeviceChangeHandling = flag;
187
- },
188
-
189
189
  };
190
190
 
191
191
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (audioDeviceManager);
@@ -12626,7 +12626,7 @@ class UserAgentCore {
12626
12626
  case _messages__WEBPACK_IMPORTED_MODULE_7__.C.CANCEL:
12627
12627
  throw new Error(`Unexpected out of dialog request method ${message.method}.`);
12628
12628
  // removed by dead control flow
12629
- {}
12629
+
12630
12630
  case _messages__WEBPACK_IMPORTED_MODULE_7__.C.INFO:
12631
12631
  // Use of the INFO method does not constitute a separate dialog usage.
12632
12632
  // INFO messages are always part of, and share the fate of, an invite
@@ -20856,25 +20856,13 @@ __webpack_require__.r(__webpack_exports__);
20856
20856
  /* harmony import */ var _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./audioDeviceManager.js */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/audioDeviceManager.js");
20857
20857
  /* harmony import */ var _coreSDKLogger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./coreSDKLogger.js */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/coreSDKLogger.js");
20858
20858
  /* harmony import */ var _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./webrtcSIPPhoneEventDelegate */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/webrtcSIPPhoneEventDelegate.js");
20859
- /*
20860
- * SIPJS WebRTC SIP Phone - to interact with SIPJS Library
20861
- */
20862
-
20863
20859
  var SIP = __webpack_require__(/*! ./sip-0.20.0.js */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/sip-0.20.0.js")
20864
20860
  ;
20865
20861
 
20866
20862
 
20867
20863
 
20868
- let enableAutoAudioDeviceChangeHandling = false;
20869
- var lastTransportState = "";
20870
- var lastRegistererState = "";
20871
- var initializeComplete = false;
20872
- var webRTCStatus = "offline"; // ready -> registered, offline -> unregistered,
20873
- var callBackHandler = null;
20874
- let txtPublicIdentity = "";
20875
- var bMicEnable = true;
20876
- var bHoldEnable = false;
20877
- var bDisableVideo = true;
20864
+ let logger = _coreSDKLogger_js__WEBPACK_IMPORTED_MODULE_1__["default"];
20865
+
20878
20866
  var beeptone = document.createElement("audio");
20879
20867
  beeptone.src = __webpack_require__(/*! ./static/beep.wav */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/static/beep.wav");
20880
20868
  var ringtone = document.createElement("audio");
@@ -20886,26 +20874,12 @@ dtmftone.src = __webpack_require__(/*! ./static/dtmf.wav */ "./node_modules/@exo
20886
20874
 
20887
20875
  var audioRemote = document.createElement("audio");
20888
20876
 
20889
-
20890
- let txtDisplayName, txtPrivateIdentity, txtHostNameWithPort, txtHostName, txtWebSocketPort, txtAccountName;
20891
- let txtSecurity, txtSipDomain, txtWSPort, txtSipPort, txtSipSecurePort, txtContactHost, endpoint;
20892
- let txtPassword, txtRealm, txtTurnServer, txtCredential, txtTurnUri, txtWebsocketURL, txtUDPURL;
20893
-
20894
-
20895
- let register_flag = false;
20896
- var ctxSip = {};
20897
- var registerer = null;
20898
-
20899
-
20900
- let logger = _coreSDKLogger_js__WEBPACK_IMPORTED_MODULE_1__["default"];
20901
- /* NL Additions - Start */
20902
-
20903
20877
  function getLogger() {
20878
+ let uaLogger;
20904
20879
 
20905
20880
  try {
20906
20881
  let userAgent = SIP.UserAgent
20907
20882
  uaLogger = userAgent.getLogger("sip.WebrtcLib")
20908
- //let loggerFactory = userAgent.getLoggerFactory()
20909
20883
  } catch (e) {
20910
20884
  logger.log("sipjsphone: getLogger: No userAgent.getLogger, Using console log")
20911
20885
  return console;
@@ -20920,17 +20894,143 @@ function getLogger() {
20920
20894
  }
20921
20895
  }
20922
20896
 
20923
- /* NL Additions - End */
20897
+ class SIPJSPhone {
20898
+
20899
+ constructor(delegate, username) {
20900
+ this.webrtcSIPPhoneEventDelegate = delegate;
20901
+ this.username = username;
20902
+ this.ctxSip = {};
20903
+ this.lastRegistererState = "";
20904
+ this.lastTransportState = "";
20905
+ this.registererTimer = null;
20906
+ this.txtDisplayName = "";
20907
+ this.txtPassword = "";
20908
+ this.txtPrivateIdentity = "";
20909
+ this.txtPublicIdentity = "";
20910
+ this.txtRealm = "";
20911
+ this.txtHostName = "";
20912
+ this.txtSipDomain = "";
20913
+ this.txtWebsocketURL = "";
20914
+ this.txtWebSocketPort = "";
20915
+ this.txtHostNameWithPort = "";
20916
+ this.txtSecurity = "";
20917
+ this.txtWSPort = "";
20918
+ this.endpoint = "";
20919
+ this.preferredCodec = null;
20920
+ this.userAgent = null;
20921
+ this.registerer = null;
20922
+ this.session = null;
20923
+ this.remoteStream = null;
20924
+ this.localStream = null;
20925
+ this.registerAttempts = 0;
20926
+ this.maxRegisterAttempts = 3;
20927
+ this.registerTimer = null;
20928
+ this.isRegistered = false;
20929
+ this.isConnecting = false;
20930
+ this.isDisconnected = false;
20931
+ this.isMuted = false;
20932
+ this.isHold = false;
20933
+ this.isCallActive = false;
20934
+ this.isCallEnded = false;
20935
+ this.isCallRejected = false;
20936
+ this.isCallAccepted = false;
20937
+ this.isCallInProgress = false;
20938
+ this.isCallEstablished = false;
20939
+ this.isCallTerminated = false;
20940
+ this.isCallFailed = false;
20941
+ this.isCallBusy = false;
20942
+ this.isCallNoAnswer = false;
20943
+ this.isCallCanceled = false;
20944
+ this.isCallTimeout = false;
20945
+ this.isCallError = false;
20946
+ this.isCallUnknown = false;
20947
+ this.isCallOther = false;
20948
+ this.isCallNone = false;
20949
+ this.isCallAll = false;
20950
+ this.isCallAny = false;
20951
+ this.isCallSome = false;
20952
+ this.isCallMany = false;
20953
+ this.isCallFew = false;
20954
+ this.isCallSeveral = false;
20955
+ this.isCallNumerous = false;
20956
+ this.isCallCountless = false;
20957
+ this.isCallInnumerable = false;
20958
+ this.isCallUncountable = false;
20959
+ this.isCallInfinite = false;
20960
+ this.isCallEndless = false;
20961
+ this.isCallBoundless = false;
20962
+ this.isCallLimitless = false;
20963
+ this.isCallUnlimited = false;
20964
+ this.isCallUnrestricted = false;
20965
+ this.isCallUnconstrained = false;
20966
+ this.isCallUnbounded = false;
20967
+ this.isCallUnconfined = false;
20968
+ this.isCallUnfettered = false;
20969
+ this.isCallUnhampered = false;
20970
+ this.isCallUnhindered = false;
20971
+ this.isCallUnimpeded = false;
20972
+ this.isCallUnobstructed = false;
20973
+ this.isCallUnrestrained = false;
20974
+ this.isCallUnrestricted = false;
20975
+ this.isCallUnshackled = false;
20976
+ this.isCallUntrammeled = false;
20977
+ this.bMicEnable = true;
20978
+ this.bHoldEnable = false;
20979
+ this.register_flag = false;
20980
+ this.enableAutoAudioDeviceChangeHandling = false;
20981
+
20982
+ this.ringtone = ringtone;
20983
+ this.beeptone = beeptone;
20984
+ this.ringbacktone = ringbacktone;
20985
+ this.dtmftone = dtmftone;
20986
+ this.audioRemote = document.createElement("audio");
20987
+ this.audioRemote.style.display = 'none';
20988
+ document.body.appendChild(this.audioRemote);
20989
+
20990
+ this.addPreferredCodec = this.addPreferredCodec.bind(this);
20991
+
20992
+ // In the constructor, after initializing audio elements:
20993
+ [this.ringtone, this.beeptone, this.ringbacktone, this.dtmftone].forEach(audio => {
20994
+ audio.muted = false;
20995
+ audio.volume = 1.0;
20996
+ });
20997
+ }
20998
+
20999
+ attachGlobalDeviceChangeListener() {
21000
+ logger.log("SIPJSPhone: Attaching global devicechange event listener enableAutoAudioDeviceChangeHandling = ", this.enableAutoAudioDeviceChangeHandling);
21001
+ navigator.mediaDevices.addEventListener('devicechange', this._onDeviceChange.bind(this));
21002
+ }
21003
+
21004
+ setEnableAutoAudioDeviceChangeHandling(flag) {
21005
+ logger.log("sipjsphone: setEnableAutoAudioDeviceChangeHandling: entry, enableAutoAudioDeviceChangeHandling = ",flag);
21006
+ this.enableAutoAudioDeviceChangeHandling = flag;
21007
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.setEnableAutoAudioDeviceChangeHandling(flag);
21008
+ }
21009
+
21010
+ init(onInitDoneCallback) {
21011
+
21012
+ const preInit = () => {
21013
+ logger.log("sipjsphone: init:readyState, calling postInit")
21014
+ this.postInit(onInitDoneCallback);
21015
+ }
21016
+
21017
+ const oReadyStateTimer = setInterval(() => {
21018
+ if (document.readyState === "complete") {
21019
+ clearInterval(oReadyStateTimer);
21020
+ logger.log("sipjsphone: init:readyState, calling preinit")
21021
+ preInit();
21022
+ }
21023
+ }, 100);
20924
21024
 
20925
- //var intervalID = 0;
20926
- function postInit(onInitDoneCallback) {
21025
+ }
20927
21026
 
20928
- ctxSip = {
21027
+ postInit(onInitDoneCallback) {
21028
+ this.ctxSip = {
20929
21029
  config: {},
20930
- ringtone: ringtone,
20931
- ringbacktone: ringbacktone,
20932
- dtmfTone: dtmftone,
20933
- beeptone: beeptone,
21030
+ ringtone: this.ringtone,
21031
+ ringbacktone: this.ringbacktone,
21032
+ dtmfTone: this.dtmftone,
21033
+ beeptone: this.beeptone,
20934
21034
  Sessions: [],
20935
21035
  callTimers: {},
20936
21036
  callActiveID: null,
@@ -20939,90 +21039,88 @@ function postInit(onInitDoneCallback) {
20939
21039
  ringToneIntervalID: 0,
20940
21040
  ringtoneCount: 30,
20941
21041
 
20942
- startRingTone: function () {
21042
+ startRingTone: () => {
20943
21043
  try {
20944
21044
  var count = 0;
20945
- if (!ctxSip.ringtone) {
20946
- ctxSip.ringtone = ringtone;
21045
+ if (!this.ctxSip.ringtone) {
21046
+ this.ctxSip.ringtone = this.ringtone;
20947
21047
  }
20948
- ctxSip.ringtone.load();
20949
- ctxSip.ringToneIntervalID = setInterval(function () {
20950
- ctxSip.ringtone.play()
21048
+ logger.log('DEBUG: startRingTone called, audio element:', this.ctxSip.ringtone);
21049
+ logger.log('DEBUG: startRingTone src:', this.ctxSip.ringtone.src);
21050
+ this.ctxSip.ringtone.load();
21051
+ this.ctxSip.ringToneIntervalID = setInterval(() => {
21052
+ this.ctxSip.ringtone.play()
20951
21053
  .then(() => {
20952
- // Audio is playing.
20953
- logger.log("sipjsphone: startRingTone: Audio is playing: count=" + count + " ctxSip.ringToneIntervalID=" + ctxSip.ringToneIntervalID + " ctxSip.ringtoneCount=" + ctxSip.ringtoneCount);
21054
+ logger.log("DEBUG: startRingTone: Audio is playing...");
20954
21055
  })
20955
21056
  .catch(e => {
20956
- logger.log("sipjsphone: startRingTone: Exception:", e);
21057
+ logger.log("DEBUG: startRingTone: Exception:", e);
20957
21058
  });
20958
21059
  count++;
20959
- if (count > ctxSip.ringtoneCount) {
20960
- clearInterval(ctxSip.ringToneIntervalID);
21060
+ if (count > this.ctxSip.ringtoneCount) {
21061
+ clearInterval(this.ctxSip.ringToneIntervalID);
20961
21062
  }
20962
- }, 500)
20963
-
20964
-
20965
-
20966
- } catch (e) { logger.log("sipjsphone: startRingTone: Exception:", e); }
21063
+ }, 500);
21064
+ } catch (e) {
21065
+ logger.log("DEBUG: startRingTone: Exception:", e);
21066
+ }
20967
21067
  },
20968
21068
 
20969
- stopRingTone: function () {
20970
- try {
21069
+ stopRingTone: () => {
21070
+ try {
20971
21071
 
20972
- if (!ctxSip.ringtone) {
20973
- ctxSip.ringtone = ringtone;
20974
- }
20975
- ctxSip.ringtone.pause();
20976
- logger.log("sipjsphone: stopRingTone: intervalID:", ctxSip.ringToneIntervalID);
20977
- clearInterval(ctxSip.ringToneIntervalID)
21072
+ if (!this.ctxSip.ringtone) {
21073
+ this.ctxSip.ringtone = this.ringtone;
21074
+ }
21075
+ this.ctxSip.ringtone.pause();
21076
+ logger.log("sipjsphone: stopRingTone: intervalID:", this.ctxSip.ringToneIntervalID);
21077
+ clearInterval(this.ctxSip.ringToneIntervalID)
20978
21078
  } catch (e) { logger.log("sipjsphone: stopRingTone: Exception:", e); }
20979
21079
  },
20980
21080
 
20981
- startRingbackTone: function () {
20982
- if (!ctxSip.ringbacktone) {
20983
- ctxSip.ringbacktone = ringbacktone;
21081
+ startRingbackTone: () => {
21082
+ if (!this.ctxSip.ringbacktone) {
21083
+ this.ctxSip.ringbacktone = this.ringbacktone;
20984
21084
  }
20985
21085
  try {
20986
- ctxSip.ringbacktone.play().then(() => {
20987
- // Audio is playing.
20988
- logger.log("sipjsphone: startRingbackTone: Audio is playing:");
20989
- })
20990
- .catch(e => {
20991
- logger.log("sipjsphone: startRingbackTone: Exception:", e);
20992
- });
21086
+ this.ctxSip.ringbacktone.play()
21087
+ .then(() => {
21088
+ logger.log("sipjsphone: startRingbackTone: Audio is playing...");
21089
+ })
21090
+ .catch(e => {
21091
+ logger.log("sipjsphone: startRingbackTone: Exception:", e);
21092
+ // Optionally, prompt user to interact with the page to enable audio
21093
+ });
20993
21094
  } catch (e) { logger.log("sipjsphone: startRingbackTone: Exception:", e); }
20994
21095
  },
20995
21096
 
20996
- stopRingbackTone: function () {
20997
- if (!ctxSip.ringbacktone) {
20998
- ctxSip.ringbacktone = ringbacktone;
20999
- }
21000
- try { ctxSip.ringbacktone.pause(); } catch (e) { logger.log("sipjsphone: stopRingbackTone: Exception:", e); }
21001
- },
21097
+ stopRingbackTone: () => {
21098
+ if (!this.ctxSip.ringbacktone) {
21099
+ this.ctxSip.ringbacktone = this.ringbacktone;
21100
+ }
21101
+ try { this.ctxSip.ringbacktone.pause(); } catch (e) { logger.log("sipjsphone: stopRingbackTone: Exception:", e); }
21102
+ },
21002
21103
 
21003
- // Genereates a rendom string to ID a call
21004
- getUniqueID: function () {
21104
+ getUniqueID: () => {
21005
21105
  return Math.random().toString(36).substr(2, 9);
21006
21106
  },
21007
21107
 
21008
- newSession: function (newSess) {
21108
+ newSession: (newSess) => {
21009
21109
 
21010
21110
  newSess.displayName = newSess.remoteIdentity.displayName || newSess.remoteIdentity.uri.user;
21011
- newSess.ctxid = ctxSip.getUniqueID();
21012
- ctxSip.callActiveID = newSess.ctxid;
21111
+ newSess.ctxid = this.ctxSip.getUniqueID();
21112
+ this.ctxSip.callActiveID = newSess.ctxid;
21013
21113
 
21014
21114
 
21015
21115
  newSess.stateChange.addListener((newState) => {
21016
21116
  switch (newState) {
21017
21117
  case SIP.SessionState.Establishing:
21018
- // Session is establishing.
21019
21118
  break;
21020
21119
  case SIP.SessionState.Established:
21021
- onInvitationSessionAccepted(newSess);
21120
+ this.onInvitationSessionAccepted(newSess);
21022
21121
  break;
21023
21122
  case SIP.SessionState.Terminated:
21024
- // Session has terminated.
21025
- onInvitationSessionTerminated();
21123
+ this.onInvitationSessionTerminated();
21026
21124
  break;
21027
21125
  default:
21028
21126
  break;
@@ -21037,10 +21135,10 @@ function postInit(onInitDoneCallback) {
21037
21135
  let lastIceState = "unknown";
21038
21136
 
21039
21137
  try {
21040
- let callId = ctxSip.callActiveID;
21041
- let username = ctxSip.config.authorizationUsername;
21138
+ let callId = this.ctxSip.callActiveID;
21139
+ let username = this.ctxSip.config.authorizationUsername;
21042
21140
  let pc = sdh._peerConnection;
21043
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].initGetStats(pc, callId, username);
21141
+ this.webrtcSIPPhoneEventDelegate.initGetStats(pc, callId, username);
21044
21142
  } catch (e) {
21045
21143
  logger.log("sipjsphone: newSession: something went wrong while initing getstats");
21046
21144
  logger.log(e);
@@ -21048,48 +21146,49 @@ function postInit(onInitDoneCallback) {
21048
21146
 
21049
21147
  sdh.peerConnectionDelegate = {
21050
21148
  onnegotiationneeded: (event) => {
21051
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatNegoNeeded();
21149
+ this.webrtcSIPPhoneEventDelegate.onCallStatNegoNeeded();
21052
21150
  },
21053
21151
  onsignalingstatechange: (event) => {
21054
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSignalingStateChange(event.target.signalingState);
21152
+ this.webrtcSIPPhoneEventDelegate.onCallStatSignalingStateChange(event.target.signalingState);
21055
21153
  },
21056
21154
  onconnectionstatechange: (event) => {
21057
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onStatPeerConnectionConnectionStateChange(event.target.connectionState);
21155
+ this.webrtcSIPPhoneEventDelegate.onStatPeerConnectionConnectionStateChange(event.target.connectionState);
21058
21156
  },
21059
21157
  oniceconnectionstatechange: (event) => {
21060
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onStatPeerConnectionIceConnectionStateChange(event.target.iceConnectionState);
21158
+ this.webrtcSIPPhoneEventDelegate.onStatPeerConnectionIceConnectionStateChange(event.target.iceConnectionState);
21061
21159
  },
21062
21160
  onicegatheringstatechange: (event) => {
21063
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onStatPeerConnectionIceGatheringStateChange(event.target.iceGatheringState);
21161
+ this.webrtcSIPPhoneEventDelegate.onStatPeerConnectionIceGatheringStateChange(event.target.iceGatheringState);
21064
21162
  }
21065
21163
 
21066
21164
  };
21067
21165
 
21068
21166
  };
21069
- ctxSip.Sessions[newSess.ctxid] = newSess;
21167
+ this.ctxSip.Sessions[newSess.ctxid] = newSess;
21070
21168
 
21071
21169
  let status;
21072
21170
  if (newSess.direction === 'incoming') {
21073
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsSessionEvent('incoming');
21171
+ logger.log('DEBUG: Incoming call detected, about to start ring tone');
21172
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('incoming');
21074
21173
  status = "Incoming: " + newSess.displayName;
21075
- ctxSip.startRingTone();
21174
+ this.ctxSip.startRingTone();
21076
21175
  //sip call method was invoking after 500 ms because of race between server push and
21077
21176
  //webrtc websocket autoanswer
21078
- setTimeout(sipCall, 500);
21177
+ setTimeout(() => this.sipCall(), 500);
21079
21178
 
21080
21179
  }
21081
- ctxSip.setCallSessionStatus(status);
21180
+ this.ctxSip.setCallSessionStatus(status);
21082
21181
 
21083
21182
 
21084
21183
  },
21085
21184
 
21086
21185
  // getUser media request refused or device was not present
21087
- getUserMediaFailure: function (e) {
21186
+ getUserMediaFailure: (e) => {
21088
21187
 
21089
21188
  },
21090
21189
 
21091
- getUserMediaSuccess: function (stream) {
21092
- ctxSip.Stream = stream;
21190
+ getUserMediaSuccess: (stream) => {
21191
+ this.ctxSip.Stream = stream;
21093
21192
  },
21094
21193
 
21095
21194
  /**
@@ -21098,7 +21197,7 @@ function postInit(onInitDoneCallback) {
21098
21197
  * @param {string}
21099
21198
  * status
21100
21199
  */
21101
- setCallSessionStatus: function (status) {
21200
+ setCallSessionStatus: (status) => {
21102
21201
 
21103
21202
  },
21104
21203
 
@@ -21108,7 +21207,7 @@ function postInit(onInitDoneCallback) {
21108
21207
  * @param {string}
21109
21208
  * status
21110
21209
  */
21111
- setStatus: function (status) {
21210
+ setStatus: (status) => {
21112
21211
  },
21113
21212
 
21114
21213
  /**
@@ -21120,14 +21219,14 @@ function postInit(onInitDoneCallback) {
21120
21219
  * status Enum 'ringing', 'answered', 'ended', 'holding',
21121
21220
  * 'resumed'
21122
21221
  */
21123
- logCall: function (session, status) { },
21222
+ logCall: (session, status) => { },
21124
21223
 
21125
21224
 
21126
21225
 
21127
21226
 
21128
- sipHangUp: function (sessionid) {
21227
+ sipHangUp: (sessionid) => {
21129
21228
 
21130
- var s = ctxSip.Sessions[sessionid];
21229
+ var s = this.ctxSip.Sessions[sessionid];
21131
21230
  // s.terminate();
21132
21231
  if (!s) {
21133
21232
  return;
@@ -21145,13 +21244,13 @@ function postInit(onInitDoneCallback) {
21145
21244
 
21146
21245
  },
21147
21246
 
21148
- sipSendDTMF: function (digit) {
21247
+ sipSendDTMF: (digit) => {
21149
21248
 
21150
- try { ctxSip.dtmfTone.play(); } catch (e) { logger.log("sipjsphone: sipSendDTMF: Exception:", e); }
21249
+ try { this.ctxSip.dtmfTone.play(); } catch (e) { logger.log("sipjsphone: sipSendDTMF: Exception:", e); }
21151
21250
 
21152
- var a = ctxSip.callActiveID;
21251
+ var a = this.ctxSip.callActiveID;
21153
21252
  if (a) {
21154
- var s = ctxSip.Sessions[a];
21253
+ var s = this.ctxSip.Sessions[a];
21155
21254
 
21156
21255
  if (!/^[0-9A-D#*,]$/.exec(digit)) {
21157
21256
  return Promise.reject(new Error("Invalid DTMF tone."));
@@ -21175,31 +21274,31 @@ function postInit(onInitDoneCallback) {
21175
21274
  }
21176
21275
  },
21177
21276
 
21178
- setError: function (err, title, msg, closable) { },
21277
+ setError: (err, title, msg, closable) => { },
21179
21278
 
21180
21279
 
21181
21280
 
21182
21281
 
21183
- phoneMuteButtonPressed: function (sessionid) {
21184
- logger.log(" sipjsphone: phoneMuteButtonPressed: bMicEnable, sessionid", bMicEnable, sessionid);
21185
- var s = ctxSip.Sessions[sessionid];
21282
+ phoneMuteButtonPressed: (sessionid) => {
21283
+ logger.log(" sipjsphone: phoneMuteButtonPressed: bMicEnable, sessionid", this.bMicEnable, sessionid);
21284
+ var s = this.ctxSip.Sessions[sessionid];
21186
21285
 
21187
- if (bMicEnable) {
21188
- toggleMute(s, true);
21189
- bMicEnable = false;
21286
+ if (this.bMicEnable) {
21287
+ this.toggleMute(s, true);
21288
+ this.bMicEnable = false;
21190
21289
  } else {
21191
- toggleMute(s, false);
21192
- bMicEnable = true;
21290
+ this.toggleMute(s, false);
21291
+ this.bMicEnable = true;
21193
21292
  }
21194
21293
  },
21195
21294
 
21196
21295
  //NL --Implement hold button start
21197
- phoneMute: function (sessionid, bMute) {
21296
+ phoneMute: (sessionid, bMute) => {
21198
21297
  if (sessionid) {
21199
- var s = ctxSip.Sessions[sessionid];
21298
+ var s = this.ctxSip.Sessions[sessionid];
21200
21299
  logger.log(" sipjsphone: phoneMute: bMute", bMute)
21201
- toggleMute(s, bMute);
21202
- bMicEnable = !bMute;
21300
+ this.toggleMute(s, bMute);
21301
+ this.bMicEnable = !bMute;
21203
21302
  }
21204
21303
  else{
21205
21304
  logger.log(" sipjsphone: phoneMute: doing nothing as sessionid not found")
@@ -21207,24 +21306,24 @@ function postInit(onInitDoneCallback) {
21207
21306
  }
21208
21307
  },
21209
21308
 
21210
- phoneHold: function (sessionid, bHold) {
21309
+ phoneHold: (sessionid, bHold) => {
21211
21310
  if (sessionid) {
21212
- var s = ctxSip.Sessions[sessionid];
21311
+ var s = this.ctxSip.Sessions[sessionid];
21213
21312
  logger.log("sipjsphone: phoneHold: bHold", bHold)
21214
- toggleHold(s, bHold);
21215
- bHoldEnable = bHold;
21313
+ this.toggleHold(s, bHold);
21314
+ this.bHoldEnable = bHold;
21216
21315
  }
21217
21316
  },
21218
21317
 
21219
- phoneHoldButtonPressed: function (sessionid) {
21318
+ phoneHoldButtonPressed: (sessionid) => {
21220
21319
  if (sessionid) {
21221
- var s = ctxSip.Sessions[sessionid];
21222
- if (bHoldEnable) {
21223
- toggleHold(s, false);
21224
- bHoldEnable = false;
21320
+ var s = this.ctxSip.Sessions[sessionid];
21321
+ if (this.bHoldEnable) {
21322
+ this.toggleHold(s, false);
21323
+ this.bHoldEnable = false;
21225
21324
  } else {
21226
- toggleHold(s, true);
21227
- bHoldEnable = true;
21325
+ this.toggleHold(s, true);
21326
+ this.bHoldEnable = true;
21228
21327
  }
21229
21328
  }
21230
21329
  },
@@ -21234,7 +21333,7 @@ function postInit(onInitDoneCallback) {
21234
21333
  * Tests for a capable browser, return bool, and shows an error modal on
21235
21334
  * fail.
21236
21335
  */
21237
- hasWebRTC: function () {
21336
+ hasWebRTC: () => {
21238
21337
 
21239
21338
  if (navigator.webkitGetUserMedia) {
21240
21339
  return true;
@@ -21243,7 +21342,7 @@ function postInit(onInitDoneCallback) {
21243
21342
  } else if (navigator.getUserMedia) {
21244
21343
  return true;
21245
21344
  } else {
21246
- ctxSip.setError(true, 'Unsupported Browser.', 'Your browser does not support the features required for this phone.');
21345
+ this.ctxSip.setError(true, 'Unsupported Browser.', 'Your browser does not support the features required for this phone.');
21247
21346
  logger.error("WebRTC support not found");
21248
21347
  return false;
21249
21348
  }
@@ -21252,124 +21351,151 @@ function postInit(onInitDoneCallback) {
21252
21351
  };
21253
21352
 
21254
21353
 
21255
- if (!ctxSip.hasWebRTC) {
21354
+ if (!this.ctxSip.hasWebRTC()) {
21256
21355
  alert('Your browser don\'t support WebRTC.\naudio/video calls will be disabled.');
21257
21356
  }
21258
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].setWebRTCFSMMapper("sipjs");
21357
+
21358
+ // Use the correct delegate property
21359
+ if (this.webrtcSIPPhoneEventDelegate?.setWebRTCFSMMapper) {
21360
+ this.webrtcSIPPhoneEventDelegate.setWebRTCFSMMapper("sipjs");
21361
+ }
21362
+
21259
21363
  logger.log("sipjsphone: init: Initialization complete...")
21260
- initializeComplete = true;
21364
+ this.initializeComplete = true;
21365
+ if (onInitDoneCallback) {
21261
21366
  onInitDoneCallback();
21367
+ }
21262
21368
  }
21263
21369
 
21264
- const addPreferredCodec = (description) => {
21265
- logger.log("sipjsphone:addPreferredCodec entry");
21266
- // Ensure a preferred codec is set
21267
- if (!SIPJSPhone.preferredCodec) {
21268
- logger.info("sipjsphone:addPreferredCodec: No preferred codec set. Using default.");
21269
- return Promise.resolve(description);
21270
- }
21370
+ addPreferredCodec(description) {
21371
+ logger.log("sipjsphone:addPreferredCodec entry");
21372
+ // Ensure a preferred codec is set
21373
+ if (!this.preferredCodec) {
21374
+ logger.info("sipjsphone:addPreferredCodec: No preferred codec set. Using default.");
21375
+ return Promise.resolve(description);
21376
+ }
21271
21377
 
21272
- const { payloadType, rtpMap, fmtp } = SIPJSPhone.preferredCodec;
21273
- const codecRtpMap = `a=rtpmap:${payloadType} ${rtpMap}`;
21274
- const codecFmtp = fmtp ? `a=fmtp:${payloadType} ${fmtp}` : "";
21378
+ const { payloadType, rtpMap, fmtp } = this.preferredCodec;
21379
+ const codecRtpMap = `a=rtpmap:${payloadType} ${rtpMap}`;
21380
+ const codecFmtp = fmtp ? `a=fmtp:${payloadType} ${fmtp}` : "";
21275
21381
 
21276
- logger.log("sipjsphone:addPreferredCodec: Original SDP:", description.sdp);
21382
+ logger.log("sipjsphone:addPreferredCodec: Original SDP:", description.sdp);
21277
21383
 
21278
- // Parse SDP into lines
21279
- let sdpLines = description.sdp.split("\r\n");
21384
+ // Parse SDP into lines
21385
+ let sdpLines = description.sdp.split("\r\n");
21280
21386
 
21281
- // Check if Opus is already in the SDP
21282
- const existingOpusIndex = sdpLines.findIndex((line) => line.includes(`a=rtpmap`) && line.includes("opus/48000/2"));
21283
- const audioMLineIndex = sdpLines.findIndex((line) => line.startsWith("m=audio"));
21387
+ // Check if Opus is already in the SDP
21388
+ const existingOpusIndex = sdpLines.findIndex((line) => line.includes(`a=rtpmap`) && line.includes("opus/48000/2"));
21389
+ const audioMLineIndex = sdpLines.findIndex((line) => line.startsWith("m=audio"));
21284
21390
 
21285
- if (existingOpusIndex !== -1 && audioMLineIndex !== -1) {
21286
- logger.log("sipjsphone:addPreferredCodec: Opus codec already exists. Prioritizing it.");
21391
+ if (existingOpusIndex !== -1 && audioMLineIndex !== -1) {
21392
+ logger.log("sipjsphone:addPreferredCodec: Opus codec already exists. Prioritizing it.");
21287
21393
 
21288
- // Extract and modify the audio m-line
21289
- let audioMLine = sdpLines[audioMLineIndex];
21290
- audioMLine = audioMLine.replace("RTP/SAVP", "RTP/AVP");
21394
+ // Extract and modify the audio m-line
21395
+ let audioMLine = sdpLines[audioMLineIndex];
21396
+ audioMLine = audioMLine.replace("RTP/SAVP", "RTP/AVP");
21291
21397
 
21292
- const codecs = audioMLine.split(" ");
21293
- const mLineStart = codecs.slice(0, 3); // "m=audio <port> <protocol>"
21294
- const mLineCodecs = codecs.slice(3);
21398
+ const codecs = audioMLine.split(" ");
21399
+ const mLineStart = codecs.slice(0, 3); // "m=audio <port> <protocol>"
21400
+ const mLineCodecs = codecs.slice(3);
21295
21401
 
21296
- // Move existing Opus payload type to the top
21297
- const opusPayloadType = sdpLines[existingOpusIndex].match(/a=rtpmap:(\d+)/)[1];
21298
- const opusIndex = mLineCodecs.indexOf(opusPayloadType);
21402
+ // Move existing Opus payload type to the top
21403
+ const opusPayloadType = sdpLines[existingOpusIndex].match(/a=rtpmap:(\d+)/)[1];
21404
+ const opusIndex = mLineCodecs.indexOf(opusPayloadType);
21299
21405
 
21300
- if (opusIndex !== -1) {
21301
- // Remove Opus from its current position
21302
- mLineCodecs.splice(opusIndex, 1);
21303
- }
21304
- // Add Opus to the beginning of the codec list
21305
- mLineCodecs.unshift(opusPayloadType);
21406
+ if (opusIndex !== -1) {
21407
+ // Remove Opus from its current position
21408
+ mLineCodecs.splice(opusIndex, 1);
21409
+ }
21410
+ // Add Opus to the beginning of the codec list
21411
+ mLineCodecs.unshift(opusPayloadType);
21306
21412
 
21307
- // Update the audio m-line
21308
- sdpLines[audioMLineIndex] = `${mLineStart.join(" ")} ${mLineCodecs.join(" ")}`;
21309
- } else if (audioMLineIndex !== -1) {
21310
- logger.log("sipjsphone:addPreferredCodec: Opus codec not found. Adding it to SDP.");
21413
+ // Update the audio m-line
21414
+ sdpLines[audioMLineIndex] = `${mLineStart.join(" ")} ${mLineCodecs.join(" ")}`;
21415
+ } else if (audioMLineIndex !== -1) {
21416
+ logger.log("sipjsphone:addPreferredCodec: Opus codec not found. Adding it to SDP.");
21311
21417
 
21312
- // Extract and modify the audio m-line
21313
- let audioMLine = sdpLines[audioMLineIndex];
21314
- audioMLine = audioMLine.replace("RTP/SAVP", "RTP/AVP");
21418
+ // Extract and modify the audio m-line
21419
+ let audioMLine = sdpLines[audioMLineIndex];
21420
+ audioMLine = audioMLine.replace("RTP/SAVP", "RTP/AVP");
21315
21421
 
21316
- const codecs = audioMLine.split(" ");
21317
- const mLineStart = codecs.slice(0, 3); // "m=audio <port> <protocol>"
21318
- const mLineCodecs = codecs.slice(3);
21422
+ const codecs = audioMLine.split(" ");
21423
+ const mLineStart = codecs.slice(0, 3); // "m=audio <port> <protocol>"
21424
+ const mLineCodecs = codecs.slice(3);
21319
21425
 
21320
- // Add Opus payload type to the top
21321
- mLineCodecs.unshift(payloadType.toString());
21426
+ // Add Opus payload type to the top
21427
+ mLineCodecs.unshift(payloadType.toString());
21322
21428
 
21323
- // Update the audio m-line
21324
- sdpLines[audioMLineIndex] = `${mLineStart.join(" ")} ${mLineCodecs.join(" ")}`;
21429
+ // Update the audio m-line
21430
+ sdpLines[audioMLineIndex] = `${mLineStart.join(" ")} ${mLineCodecs.join(" ")}`;
21325
21431
 
21326
- // Add Opus-specific attributes to the SDP
21327
- if (!sdpLines.includes(codecRtpMap)) {
21328
- sdpLines.splice(audioMLineIndex + 1, 0, codecRtpMap); // Add rtpmap after m=audio
21329
- }
21330
- if (fmtp && !sdpLines.includes(codecFmtp)) {
21331
- sdpLines.splice(audioMLineIndex + 2, 0, codecFmtp); // Add fmtp after rtpmap
21432
+ // Add Opus-specific attributes to the SDP
21433
+ if (!sdpLines.includes(codecRtpMap)) {
21434
+ sdpLines.splice(audioMLineIndex + 1, 0, codecRtpMap); // Add rtpmap after m=audio
21435
+ }
21436
+ if (fmtp && !sdpLines.includes(codecFmtp)) {
21437
+ sdpLines.splice(audioMLineIndex + 2, 0, codecFmtp); // Add fmtp after rtpmap
21438
+ }
21439
+ } else {
21440
+ logger.error("sipjsphone:addPreferredCodec: No audio m-line found in SDP. Cannot modify.");
21441
+ return Promise.resolve(description);
21332
21442
  }
21333
- } else {
21334
- logger.error("sipjsphone:addPreferredCodec: No audio m-line found in SDP. Cannot modify.");
21335
- return Promise.resolve(description);
21336
- }
21337
21443
 
21338
- // Remove any duplicate lines
21339
- sdpLines = [...new Set(sdpLines)];
21444
+ // Remove any duplicate lines
21445
+ sdpLines = [...new Set(sdpLines)];
21340
21446
 
21341
- // Combine back into SDP
21342
- description.sdp = sdpLines.join("\r\n");
21343
- logger.log("sipjsphone:addPreferredCodec: Modified SDP:", description.sdp);
21447
+ // Combine back into SDP
21448
+ description.sdp = sdpLines.join("\r\n");
21449
+ logger.log("sipjsphone:addPreferredCodec: Modified SDP:", description.sdp);
21344
21450
 
21345
- return Promise.resolve(description);
21346
- };
21451
+ return Promise.resolve(description);
21452
+ }
21347
21453
 
21348
- function sipRegister() {
21454
+ sipRegister() {
21455
+ logger.log("sipjsphone: sipRegister: Starting registration with config:", [{
21456
+ authorizationUsername: this.txtPrivateIdentity,
21457
+ authorizationPassword: this.txtPassword,
21458
+ uri: this.txtPublicIdentity,
21459
+ websocketURL: this.txtWebsocketURL,
21460
+ realm: this.txtRealm
21461
+ }]);
21349
21462
 
21350
- lastRegistererState = "";
21463
+ try {
21464
+ if (!this.txtRealm || !this.txtPrivateIdentity || !this.txtPublicIdentity) {
21465
+ logger.error("sipjsphone: sipRegister: Missing required credentials");
21466
+ return;
21467
+ }
21351
21468
 
21352
- cleanupRegistererTimer();
21469
+ const uri = SIP.UserAgent.makeURI(this.txtPublicIdentity);
21470
+ if (!uri) {
21471
+ logger.error("sipjsphone: sipRegister: Failed to create SIP URI");
21472
+ return;
21473
+ }
21353
21474
 
21354
- try {
21355
- ctxSip.config = {
21356
- authorizationPassword: txtPassword,
21357
- authorizationUsername: txtDisplayName,
21358
- displayName: txtDisplayName,
21359
- uri: SIP.UserAgent.makeURI(txtPublicIdentity),
21360
- hackWssInTransport: true,
21361
- allowLegacyNotifications: true,
21362
- contactParams: {
21363
- transport: "wss"
21364
- },
21475
+ const userAgentConfig = {
21476
+ uri: uri,
21365
21477
  transportOptions: {
21366
- server: txtWebsocketURL,
21478
+ server: this.txtWebsocketURL,
21367
21479
  traceSip: true,
21368
21480
  reconnectionAttempts: 0
21369
-
21370
21481
  },
21371
21482
  logBuiltinEnabled: false,
21372
- logConnector: sipPhoneLogger,
21483
+ logConfiguration: true,
21484
+ authorizationUsername: this.txtPrivateIdentity,
21485
+ authorizationPassword: this.txtPassword,
21486
+ registerOptions: {
21487
+ expires: 300
21488
+ },
21489
+ displayName: this.txtDisplayName,
21490
+ hackWssInTransport: true,
21491
+ stunServers: ["stun:stun.l.google.com:19302"],
21492
+ hackIpInContact: true,
21493
+ forceRport: true,
21494
+ hackViaTcp: false,
21495
+ hackAllowUnregisteredOptionTags: false,
21496
+ viaHost: this.txtHostName,
21497
+ allowLegacyNotifications: true,
21498
+ logConnector: this.sipPhoneLogger.bind(this),
21373
21499
  logLevel: "log",
21374
21500
  sessionDescriptionHandlerFactoryOptions: {
21375
21501
  constraints: {
@@ -21377,337 +21503,245 @@ function sipRegister() {
21377
21503
  video: false
21378
21504
  }
21379
21505
  },
21380
- stunServers: ["stun:stun.l.google.com:19302"],
21381
- registerOptions: {
21382
- expires: 300
21383
- }
21384
-
21385
- };
21506
+ delegate: {
21507
+ onInvite: (incomingSession) => {
21508
+ logger.log("onInvite called");
21509
+ if (this.ctxSip.callActiveID == null) {
21510
+ // Tell the PSTN/SIP proxy we are ringing so it doesn't CANCEL
21511
+ incomingSession.progress({ statusCode: 180, reasonPhrase: "Ringing" });
21512
+ incomingSession.direction = "incoming";
21513
+ this.ctxSip.newSession(incomingSession);
21514
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("i_new_call", "CALL", incomingSession);
21515
+ } else {
21516
+ incomingSession.reject({ statusCode: 486 });
21517
+ }
21518
+ }
21519
+ }
21520
+ };
21386
21521
 
21387
- if (!txtRealm || !txtPrivateIdentity || !txtPublicIdentity) {
21388
- return;
21389
- }
21390
- // enable notifications if not already done
21391
- if (window.webkitNotifications
21392
- && window.webkitNotifications.checkPermission() != 0) {
21393
- window.webkitNotifications.requestPermission();
21394
- }
21522
+ logger.log("sipjsphone: sipRegister: Created UserAgent with config:", [userAgentConfig]);
21523
+ this.ctxSip.userAgent = new SIP.UserAgent(userAgentConfig);
21524
+ this.ctxSip.userAgent.start();
21525
+ this.ctxSip.phone = this.ctxSip.userAgent;
21526
+ const registererConfig = {
21527
+ expires: 300,
21528
+ refreshFrequency: 80,
21529
+ registrar: SIP.UserAgent.makeURI(`sip:${this.txtSipDomain}`),
21530
+ logConfiguration: true
21531
+ };
21395
21532
 
21396
- ctxSip.phone = new SIP.UserAgent(ctxSip.config);
21397
- registerPhoneEventListeners();
21533
+ this.ctxSip.registerer = new SIP.Registerer(this.ctxSip.userAgent, registererConfig);
21534
+ this.registerer = this.ctxSip.registerer;
21535
+ this.ctxSip.registerer.stateChange.addListener(this.registererStateEventListner.bind(this));
21536
+ this.ctxSip.registerer.waitingChange.addListener(this.registererWaitingChangeListener.bind(this));
21537
+ this.registerer = this.ctxSip.registerer;
21398
21538
 
21399
- } catch (e) {
21400
- webRTCStatus = "offline";
21401
- if (callBackHandler != null)
21402
- if (callBackHandler.onResponse)
21403
- callBackHandler.onResponse("error");
21539
+ this.ctxSip.userAgent.transport.stateChange.addListener(this.transportStateChangeListener.bind(this));
21540
+ } catch (error) {
21541
+ logger.error("sipjsphone: sipRegister: Error during registration setup:", error);
21542
+ }
21404
21543
  }
21405
- register_flag = false;
21406
- }
21407
21544
 
21408
- let registererStateEventListner = (newState) => {
21545
+ registererStateEventListner(newState) {
21546
+ logger.log("sipjsphone: registererStateEventListner: Registration state changed to:", [newState]);
21409
21547
 
21410
- lastRegistererState = newState;
21411
- if (ctxSip.phone && ctxSip.phone.transport && ctxSip.phone.transport.isConnected()) {
21412
- sipPhoneLogger("debug", "", "", "sipjslog registerer new state " + newState);
21548
+ switch (newState) {
21549
+ case "Registered":
21550
+ logger.log("sipjsphone: registererStateEventListner: Registration successful");
21551
+ this.webRTCStatus = "ready";
21552
+ this.isRegistered = true;
21553
+
21554
+ // Update UI state
21555
+ if (this.callBackHandler && typeof this.callBackHandler.onResponse === 'function') {
21556
+ this.callBackHandler.onResponse("ready");
21557
+ }
21413
21558
 
21414
- switch (newState) {
21415
- case SIP.RegistererState.Registered:
21416
- break;
21417
- case SIP.RegistererState.Unregistered:
21418
- onUserAgentRegistrationFailed();
21559
+ if (this.webrtcSIPPhoneEventDelegate && typeof this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM === 'function') {
21560
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("registered", "CONNECTION");
21561
+ }
21419
21562
  break;
21420
- case SIP.RegistererState.Terminated:
21421
- onUserAgentRegistrationTerminated();
21563
+ case "Unregistered":
21564
+ logger.error("sipjsphone: registererStateEventListner: Registration failed");
21565
+ this.webRTCStatus = "offline";
21566
+ this.isRegistered = false;
21567
+
21568
+ // Update UI state
21569
+ if (this.callBackHandler && typeof this.callBackHandler.onResponse === 'function') {
21570
+ this.callBackHandler.onResponse("error");
21571
+ }
21572
+
21573
+ if (this.webrtcSIPPhoneEventDelegate && typeof this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM === 'function') {
21574
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("unregistered", "CONNECTION");
21575
+ }
21422
21576
  break;
21577
+ case "Terminated":
21578
+ logger.log("sipjsphone: registererStateEventListner: Registration terminated");
21579
+ this.webRTCStatus = "offline";
21580
+ this.isRegistered = false;
21581
+
21582
+ // Update UI state
21583
+ if (this.callBackHandler && typeof this.callBackHandler.onResponse === 'function') {
21584
+ this.callBackHandler.onResponse("error");
21585
+ }
21423
21586
 
21424
- default:
21587
+ if (this.webrtcSIPPhoneEventDelegate && typeof this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM === 'function') {
21588
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("terminated", "CONNECTION");
21589
+ }
21425
21590
  break;
21426
21591
  }
21592
+ this.lastRegistererState = newState;
21427
21593
  }
21428
21594
 
21429
21595
 
21430
- };
21431
-
21432
-
21433
-
21434
- let registererWaitingChangeListener = (b) => {
21435
- if (registerer && registerer.state == SIP.RegistererState.Registered) {
21436
- onUserAgentRegistered();
21437
- }
21438
-
21439
- };
21440
-
21441
- let transportStateChangeListener = (newState) => {
21442
- lastTransportState = newState;
21443
- sipPhoneLogger("debug", "", "", "sipjslog transport new state " + newState);
21444
-
21445
- switch (newState) {
21446
-
21447
- case SIP.TransportState.Connecting:
21448
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsTransportEvent('connecting');
21449
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("starting", "CONNECTION");
21450
- break;
21451
- case SIP.TransportState.Connected:
21452
- onUserAgentTransportConnected();
21453
- break;
21454
- case SIP.TransportState.Disconnected:
21455
- onUserAgentTransportDisconnected();
21456
- break;
21457
- default:
21458
- break;
21459
21596
 
21597
+ registererWaitingChangeListener(b) {
21598
+ if (this.registerer && this.registerer.state == SIP.RegistererState.Registered) {
21599
+ this.registererStateEventListner("Registered");
21600
+ }
21460
21601
 
21461
21602
  }
21462
- };
21463
-
21464
- function registerPhoneEventListeners() {
21465
-
21466
- ctxSip.phone.delegate = {};
21467
-
21468
-
21469
-
21470
-
21471
- ctxSip.phone.transport.stateChange.addListener(transportStateChangeListener);
21472
-
21473
- registerer = new SIP.Registerer(ctxSip.phone, { expires: 300, refreshFrequency: 80 });
21474
21603
 
21604
+ transportStateChangeListener(newState) {
21605
+ logger.log("sipjsphone: transportStateChangeListener: Transport state changed to:", [newState]);
21606
+ this.lastTransportState = newState;
21475
21607
 
21476
- ctxSip.phone.delegate.onInvite = (incomingSession) => {
21477
- if (ctxSip.callActiveID == null) {
21478
- var s = incomingSession;
21479
- s.direction = 'incoming';
21480
- ctxSip.newSession(s);
21481
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onRecieveInvite(incomingSession);
21482
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("i_new_call", "CALL");
21483
- } else {
21484
- incomingSession.reject({
21485
- statusCode: 480,
21486
- reasonPhrase: "4001"
21487
- });
21608
+ if (newState === "Connected") {
21609
+ logger.log("sipjsphone: transportStateChangeListener: WebSocket connected");
21610
+ this.onUserAgentTransportConnected();
21488
21611
  }
21489
- };
21490
-
21491
21612
 
21613
+ if (newState === "Disconnected") {
21614
+ logger.log("sipjsphone: transportStateChangeListener: WebSocket disconnected");
21492
21615
 
21493
- ctxSip.phone.start();
21494
-
21495
- }
21496
-
21616
+ if (this.webrtcSIPPhoneEventDelegate && typeof this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent === 'function') {
21617
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent("disconnected");
21618
+ }
21497
21619
 
21620
+ // PATCH: Surface this as an 'unregistered' terminal state
21621
+ this.registererStateEventListner("Unregistered");
21498
21622
 
21499
- function uiOnConnectionEvent(b_connected, b_connecting) { // should be enum:
21500
- // connecting,
21501
- // connected,
21502
- // terminating,
21503
- // terminated
21504
- if (b_connected || b_connecting) {
21505
- register_flag = true;
21506
- webRTCStatus = "ready";
21507
- } else {
21508
- register_flag = false;
21509
- destroySocketConnection();
21623
+ this.onUserAgentTransportDisconnected();
21624
+ }
21510
21625
 
21626
+ if (this.webrtcSIPPhoneEventDelegate && this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent) {
21627
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent(newState);
21628
+ }
21511
21629
  }
21512
21630
 
21513
-
21514
- }
21515
-
21516
-
21517
- function destroySocketConnection() {
21631
+ /**
21632
+ * Closes the underlying WebSocket transport and removes listeners so
21633
+ * that SIP.js can GC everything cleanly.
21634
+ * Call-site: disconnect(), sipUnRegister(), uiOnConnectionEvent()…
21635
+ */
21636
+ destroySocketConnection() {
21518
21637
  try {
21519
-
21520
- if (ctxSip.phone && ctxSip.phone.transport.isConnected()) {
21521
- ctxSip.phone.transport.disconnect();
21522
- }
21523
- } catch (e) {
21524
- logger.log("sipjsphone: destroySocketConnection: ERROR", e);
21638
+ // The transport object lives on the SIP.js Phone (UserAgent.transport)
21639
+ const transport = this.ctxSip?.phone?.transport;
21640
+ if (!transport) {
21641
+ return; // nothing to do
21642
+ }
21643
+
21644
+ // SIP.js 0.20 ⇢ state-driven API; older builds still expose isConnected()
21645
+ const connected =
21646
+ typeof transport.isConnected === "function"
21647
+ ? transport.isConnected()
21648
+ : transport.state === 2; // TransportState.Connected === 2
21649
+
21650
+ if (connected) {
21651
+ // 0.20 has async disconnect; earlier versions are sync – await is OK for both
21652
+ transport.disconnect();
21653
+ }
21654
+ } catch (e) {
21655
+ logger.error("destroySocketConnection: cleanup failed", e);
21525
21656
  }
21526
- }
21527
-
21528
-
21529
- function uiCallTerminated(s_description) {
21530
- if (window.btnBFCP)
21531
- window.btnBFCP.disabled = true;
21532
-
21533
- ctxSip.stopRingTone();
21534
- ctxSip.stopRingbackTone();
21535
-
21536
- if (callBackHandler != null)
21537
- if (callBackHandler.onResponse)
21538
- callBackHandler.onResponse("disconnected");
21539
-
21540
-
21541
- }
21542
-
21543
-
21544
- function sipCall() {
21545
- logger.log("sipjsphone: sipCall: testing emit accept_reject");
21546
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("accept_reject", "CALL");
21547
- }
21657
+ }
21548
21658
 
21549
21659
 
21660
+ uiOnConnectionEvent(b_connected, b_connecting) {
21661
+ logger.log("sipjsphone: uiOnConnectionEvent: Connection state changed:", [b_connected, b_connecting]);
21550
21662
 
21663
+ if (b_connecting) {
21664
+ this.webRTCStatus = "connecting";
21665
+ } else if (b_connected) {
21666
+ this.webRTCStatus = "ready";
21667
+ } else {
21668
+ this.webRTCStatus = "offline";
21669
+ }
21551
21670
 
21552
- function sipPhoneLogger(level, category, label, content) {
21553
- try {
21554
- if (content) {
21555
- if (content.startsWith("Sending WebSocket")) {
21556
- handleWebSocketMessageContent(content, "sent");
21557
- } else if (content.startsWith("Received WebSocket text message")) {
21558
- handleWebSocketMessageContent(content, "recv");
21671
+ if (this.callBackHandler && typeof this.callBackHandler.onResponse === 'function') {
21672
+ if (b_connected) {
21673
+ this.callBackHandler.onResponse("ready");
21674
+ } else if (b_connecting) {
21675
+ this.callBackHandler.onResponse("connecting");
21676
+ } else {
21677
+ this.callBackHandler.onResponse("error");
21559
21678
  }
21560
- logger.log("sipjsphone: sipPhoneLogger:" + level + " sipjslog: " + category + ": " + content);
21561
21679
  }
21562
- } catch (e) {
21563
- logger.error("sipjsphone:sipPhoneLogger ERROR", e);
21564
- }
21565
-
21566
- }
21567
-
21568
-
21569
- function onInvitationSessionAccepted(newSess) {
21570
- ctxSip.Stream = newSess.sessionDescriptionHandler.localMediaStream;
21571
- assignStream(newSess.sessionDescriptionHandler.remoteMediaStream, audioRemote);
21572
-
21573
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsSessionEvent('accepted');
21574
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("connected", "CALL");
21575
-
21576
- // If there is another active call, hold it
21577
- if (ctxSip.callActiveID && ctxSip.callActiveID !== newSess.ctxid) {
21578
- ctxSip.phoneHoldButtonPressed(ctxSip.callActiveID);
21579
- }
21580
-
21581
- ctxSip.stopRingbackTone();
21582
- ctxSip.stopRingTone();
21583
- ctxSip.setCallSessionStatus('Answered');
21584
- ctxSip.logCall(newSess, 'answered');
21585
- ctxSip.callActiveID = newSess.ctxid;
21586
-
21587
- webRTCStatus = "busy";
21588
- if (callBackHandler != null)
21589
- if (callBackHandler.onResponse)
21590
- callBackHandler.onResponse("connected");
21591
- }
21592
-
21593
- function onInvitationSessionTerminated() {
21594
- SIPJSPhone.stopStreamTracks(ctxSip.Stream);
21595
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].stopCallStat();
21596
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsSessionEvent('terminated');
21597
- ctxSip.stopRingTone();
21598
- ctxSip.stopRingbackTone();
21599
- ctxSip.setCallSessionStatus("");
21600
- ctxSip.callActiveID = null;
21601
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].playBeepTone();
21602
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("terminated", "CALL");
21603
-
21604
- uiCallTerminated();
21605
- if (register_flag == true) {
21606
- webRTCStatus = "ready";
21607
- } else {
21608
- destroySocketConnection();
21609
21680
  }
21610
- if (callBackHandler != null)
21611
- if (callBackHandler.onResponse)
21612
- callBackHandler.onResponse("disconnected");
21613
- }
21614
-
21615
-
21616
- function onUserAgentRegistered() {
21617
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("connected", "CONNECTION");
21618
- var bConnected = true;
21619
- uiOnConnectionEvent(bConnected, !bConnected);
21620
- register_flag = true;
21621
- webRTCStatus = "ready";
21622
- if (callBackHandler != null)
21623
- if (callBackHandler.onResponse)
21624
- callBackHandler.onResponse("ready");
21625
-
21626
-
21627
- var closePhone = function () {
21628
- // stop the phone on unload
21629
- localStorage.removeItem('ctxPhone');
21630
- ctxSip.phone.stop();
21631
- };
21632
-
21633
- window.onunload = closePhone;
21634
- localStorage.setItem('ctxPhone', 'true');
21635
- }
21636
21681
 
21637
- function onUserAgentRegistrationTerminated() {
21638
- uiOnConnectionEvent(false, false);
21639
- }
21682
+ onUserAgentTransportConnected() {
21683
+ logger.log("sipjsphone: onUserAgentTransportConnected: Transport connected");
21640
21684
 
21641
- function onUserAgentRegistrationFailed() {
21685
+ if (this.webrtcSIPPhoneEventDelegate && typeof this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent === 'function') {
21686
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent('connected');
21687
+ }
21642
21688
 
21689
+ this.webRTCStatus = "ready";
21643
21690
 
21644
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("terminated", "CONNECTION");
21645
- uiOnConnectionEvent(false, false);
21646
- register_flag = false;
21647
- if (callBackHandler != null) {
21648
- if (callBackHandler.onResponse) {
21649
- callBackHandler.onResponse("error");
21691
+ if (this.webrtcSIPPhoneEventDelegate && typeof this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM === 'function') {
21692
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("started", "CONNECTION");
21650
21693
  }
21651
- }
21652
- }
21653
21694
 
21695
+ // Update UI state to show connected
21696
+ this.uiOnConnectionEvent(true, false);
21654
21697
 
21655
- function onUserAgentTransportConnected() {
21656
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsTransportEvent('connected');
21657
- webRTCStatus = "ready";
21658
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("started", "CONNECTION");
21659
- if (callBackHandler != null) {
21660
- if (callBackHandler.onResponse) {
21661
- callBackHandler.onResponse("offline");
21698
+ if (this.ctxSip.registerer) {
21699
+ this.ctxSip.registerer.stateChange.addListener(this.registererStateEventListner.bind(this));
21700
+ this.ctxSip.registerer.waitingChange.addListener(this.registererWaitingChangeListener.bind(this));
21701
+ this.ctxSip.registerer.register();
21662
21702
  }
21663
21703
  }
21664
21704
 
21665
- registerer.stateChange.addListener(registererStateEventListner);
21666
- registerer.waitingChange.addListener(registererWaitingChangeListener);
21667
- registerer.register();
21668
-
21669
- }
21670
-
21705
+ cleanupRegistererTimer() {
21706
+ if (this.registerer) {
21671
21707
 
21672
- function cleanupRegistererTimer() {
21673
- if (registerer) {
21674
-
21675
- try {
21676
- registerer.clearTimers();
21677
- registerer.stateChange.removeListener(registererStateEventListner);
21678
- registerer.waitingChange.removeListener(registererWaitingChangeListener);
21708
+ try {
21709
+ this.registerer.clearTimers();
21710
+ this.registerer.stateChange.removeListener(this.registererStateEventListner);
21711
+ this.registerer.waitingChange.removeListener(this.registererWaitingChangeListener);
21679
21712
 
21680
21713
 
21681
21714
  } catch (e) {
21682
21715
  logger.log("sipjsphone: cleanupRegistererTimer: ERROR", e);
21683
21716
 
21684
21717
  }
21685
- registerer = null;
21718
+ this.registerer = null;
21719
+
21720
+ }
21686
21721
  }
21687
- }
21688
21722
 
21689
- function onUserAgentTransportDisconnected() {
21723
+ onUserAgentTransportDisconnected() {
21690
21724
 
21691
- webRTCStatus = "offline";
21692
- setRegisterFlag(false);
21725
+ this.webRTCStatus = "offline";
21726
+ this.setRegisterFlag(false);
21693
21727
 
21694
- cleanupRegistererTimer();
21728
+ this.cleanupRegistererTimer();
21695
21729
 
21696
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsTransportEvent('disconnected');
21697
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("failed_to_start", "CONNECTION");
21698
- if (callBackHandler != null) {
21699
- if (callBackHandler.onResponse) {
21700
- callBackHandler.onResponse("error");
21730
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsTransportEvent('disconnected');
21731
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("failed_to_start", "CONNECTION");
21732
+ if (this.callBackHandler != null) {
21733
+ if (this.callBackHandler.onResponse) {
21734
+ this.callBackHandler.onResponse("error");
21735
+ }
21701
21736
  }
21702
- }
21703
21737
 
21704
21738
 
21705
21739
 
21706
21740
 
21707
- }
21741
+ }
21708
21742
 
21709
21743
 
21710
- function parseSipMessage(message) {
21744
+ parseSipMessage(message) {
21711
21745
  var lines = message.split("\n");
21712
21746
  var firstLine = lines[0];
21713
21747
  lines.slice(0, 1);
@@ -21735,26 +21769,26 @@ function parseSipMessage(message) {
21735
21769
  return sipob;
21736
21770
  }
21737
21771
 
21738
- function handleWebSocketMessageContent(content, direction) {
21772
+ handleWebSocketMessageContent(content, direction) {
21739
21773
  var lines = content.split('\n');
21740
21774
  lines.splice(0, 2);
21741
21775
  var newtext = lines.join('\n');
21742
21776
 
21743
21777
 
21744
- var sipMessage = parseSipMessage(newtext);
21778
+ var sipMessage = this.parseSipMessage(newtext);
21745
21779
 
21746
21780
  switch (direction) {
21747
21781
  case "sent":
21748
21782
 
21749
21783
  if (sipMessage.method == "REGISTER")
21750
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("sent_request", "CONNECTION");
21784
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("sent_request", "CONNECTION");
21751
21785
 
21752
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipSendCallback(newtext, "sipjs");
21786
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipSendCallback(newtext, "sipjs");
21753
21787
 
21754
21788
 
21755
21789
  break;
21756
21790
  case "recv":
21757
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipRecvCallback(newtext, "sipjs");
21791
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipRecvCallback(newtext, "sipjs");
21758
21792
  break;
21759
21793
  default:
21760
21794
  break;
@@ -21766,68 +21800,74 @@ function handleWebSocketMessageContent(content, direction) {
21766
21800
 
21767
21801
 
21768
21802
 
21769
- function setRegisterFlag(b) {
21770
- register_flag = b;
21803
+ setRegisterFlag(b) {
21804
+ this.register_flag = b;
21771
21805
  }
21772
21806
 
21773
- function toggleMute(s, mute) {
21807
+ toggleMute(s, mute) {
21774
21808
  let pc = s.sessionDescriptionHandler.peerConnection;
21775
21809
  if (pc.getSenders) {
21776
- pc.getSenders().forEach(function (sender) {
21810
+ pc.getSenders().forEach((sender) => {
21777
21811
  if (sender.track) {
21778
21812
  sender.track.enabled = !mute;
21779
21813
  }
21780
21814
  });
21781
21815
  } else {
21782
- pc.getLocalStreams().forEach(function (stream) {
21783
- stream.getAudioTracks().forEach(function (track) {
21816
+ pc.getLocalStreams().forEach((stream) => {
21817
+ stream.getAudioTracks().forEach((track) => {
21784
21818
  track.enabled = !mute;
21785
21819
  });
21786
- stream.getVideoTracks().forEach(function (track) {
21820
+ stream.getVideoTracks().forEach((track) => {
21787
21821
  track.enabled = !mute;
21788
21822
  });
21789
21823
  });
21790
21824
  }
21791
21825
  if (mute) {
21792
- onMuted(s);
21826
+ this.onMuted(s);
21793
21827
  } else {
21794
- onUnmuted(s);
21828
+ this.onUnmuted(s);
21795
21829
  }
21796
21830
  }
21797
21831
 
21798
21832
 
21799
- function onMuted(s) {
21800
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsSessionEvent('muted');
21801
- s.isMuted = true;
21802
- ctxSip.setCallSessionStatus("Muted");
21803
- }
21833
+ onMuted(s) {
21834
+ logger.log(`[onMuted] Before: s.isMuted=${s && s.isMuted}, global isMuted=${this.isMuted}`);
21835
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('muted');
21836
+ if (s) s.isMuted = true;
21837
+ this.isMuted = true;
21838
+ logger.log(`[onMuted] After: s.isMuted=${s && s.isMuted}, global isMuted=${this.isMuted}`);
21839
+ this.ctxSip.setCallSessionStatus("Muted");
21840
+ }
21804
21841
 
21805
- function onUnmuted(s) {
21806
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsSessionEvent('unmuted');
21807
- s.isMuted = false;
21808
- ctxSip.setCallSessionStatus("Answered");
21809
- }
21842
+ onUnmuted(s) {
21843
+ logger.log(`[onUnmuted] Before: s.isMuted=${s && s.isMuted}, global isMuted=${this.isMuted}`);
21844
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('unmuted');
21845
+ if (s) s.isMuted = false;
21846
+ this.isMuted = false;
21847
+ logger.log(`[onUnmuted] After: s.isMuted=${s && s.isMuted}, global isMuted=${this.isMuted}`);
21848
+ this.ctxSip.setCallSessionStatus("Answered");
21849
+ }
21810
21850
 
21811
- function onHold(s) {
21851
+ onHold(s) {
21812
21852
  //webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('hold');
21813
21853
  logger.warn(`[${s.id}] re-invite request was accepted`);
21814
21854
  s.held = true;
21815
- enableSenderTracks(!s.held && !s.isMuted);
21816
- enableReceiverTracks(!s.held);
21817
- //ctxSip.setCallSessionStatus("Hold");
21818
- }
21855
+ this.enableSenderTracks(s, !s.held && !s.isMuted);
21856
+ this.enableReceiverTracks(s, !s.held);
21857
+ //this.ctxSip.setCallSessionStatus("Hold");
21858
+ }
21819
21859
 
21820
- function onUnhold(s) {
21860
+ onUnhold(s) {
21821
21861
  //webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('unhold');
21822
21862
  logger.warn(`[${s.id}] re-invite request was rejected`);
21823
21863
  s.held = false;
21824
- enableSenderTracks(!s.held && !s.isMuted);
21825
- enableReceiverTracks(!s.held);
21826
- //ctxSip.setCallSessionStatus("Unhold");
21864
+ this.enableSenderTracks(s, !s.held && !s.isMuted);
21865
+ this.enableReceiverTracks(s, !s.held);
21866
+ //this.ctxSip.setCallSessionStatus("Unhold");
21827
21867
  }
21828
21868
 
21829
21869
  /** Helper function to enable/disable media tracks. */
21830
- function enableReceiverTracks(s, enable) {
21870
+ enableReceiverTracks(s, enable) {
21831
21871
  try {
21832
21872
  const sessionDescriptionHandler = s.sessionDescriptionHandler;
21833
21873
  const peerConnection = sessionDescriptionHandler.peerConnection;
@@ -21847,7 +21887,7 @@ function enableReceiverTracks(s, enable) {
21847
21887
  }
21848
21888
 
21849
21889
  /** Helper function to enable/disable media tracks. */
21850
- function enableSenderTracks(s, enable) {
21890
+ enableSenderTracks(s, enable) {
21851
21891
  try {
21852
21892
  const sessionDescriptionHandler = s.sessionDescriptionHandler;
21853
21893
  const peerConnection = sessionDescriptionHandler.peerConnection;
@@ -21864,14 +21904,14 @@ function enableSenderTracks(s, enable) {
21864
21904
  }
21865
21905
  }
21866
21906
 
21867
- function toggleHold(s, hold) {
21907
+ toggleHold(s, hold) {
21868
21908
  const options = {
21869
21909
  requestDelegate: {
21870
21910
  onAccept: () => {
21871
- onHold(s)
21911
+ this.onHold(s)
21872
21912
  },
21873
21913
  onReject: () => {
21874
- onUnhold(s)
21914
+ this.onUnhold(s)
21875
21915
  }
21876
21916
  },
21877
21917
  sessionDescriptionHandlerOptions: {
@@ -21880,14 +21920,14 @@ function toggleHold(s, hold) {
21880
21920
  };
21881
21921
  s.invite(options).then(() => {
21882
21922
  // preemptively enable/disable tracks
21883
- enableReceiverTracks(s, !hold);
21884
- enableSenderTracks(s, !hold && !s.isMuted);
21923
+ this.enableReceiverTracks(s, !hold);
21924
+ this.enableSenderTracks(s, !hold && !s.isMuted);
21885
21925
  }).catch((error) => {
21886
21926
  logger.error(`Error in hold request [${s.id}]`);
21887
21927
  });
21888
21928
  }
21889
21929
 
21890
- function assignStream(stream, element) {
21930
+ assignStream(stream, element) {
21891
21931
  if (_audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioOutputDeviceId != "default")
21892
21932
  element.setSinkId(_audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioOutputDeviceId);
21893
21933
  // Set element source.
@@ -21920,267 +21960,317 @@ function assignStream(stream, element) {
21920
21960
  };
21921
21961
  }
21922
21962
 
21923
- function onUserSessionAcceptFailed(e) {
21963
+ onUserSessionAcceptFailed(e) {
21924
21964
  if (e.name == "NotAllowedError" || e.name == "NotFoundError") {
21925
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM("m_permission_refused", "CALL");
21926
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onCallStatSipJsSessionEvent('userMediaFailed');
21927
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onGetUserMediaErrorCallstatCallback();
21965
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("m_permission_refused", "CALL");
21966
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('userMediaFailed');
21967
+ this.webrtcSIPPhoneEventDelegate.onGetUserMediaErrorCallstatCallback();
21928
21968
  } else {
21929
21969
  logger.log("sipjsphone: onUserSessionAcceptFailed: user media failed due to error ", e);
21930
21970
  }
21931
- uiCallTerminated('Media stream permission denied');
21932
- }
21933
-
21934
- const SIPJSPhone = {
21971
+ this.uiCallTerminated('Media stream permission denied');
21972
+ }
21935
21973
 
21936
- init: (onInitDoneCallback) => {
21974
+ loadCredentials(sipAccountInfo) {
21975
+ this.txtDisplayName = sipAccountInfo['userName'];
21976
+ this.txtPrivateIdentity = sipAccountInfo['authUser'];
21977
+ this.txtHostNameWithPort = sipAccountInfo["domain"];
21978
+ this.txtHostName = this.txtHostNameWithPort.split(":")[0];
21979
+ this.txtWebSocketPort = this.txtHostNameWithPort.split(":")[1];
21980
+ this.txtAccountName = sipAccountInfo['accountName'];
21937
21981
 
21938
- var preInit = function () {
21939
- logger.log("sipjsphone: init:readyState, calling postInit")
21940
- postInit(onInitDoneCallback);
21982
+ // Use sipdomain for public identity if available, otherwise use hostname
21983
+ if (sipAccountInfo['sipdomain']) {
21984
+ this.txtSipDomain = sipAccountInfo["sipdomain"];
21985
+ this.txtPublicIdentity = "sip:" + this.txtPrivateIdentity + "@" + this.txtSipDomain;
21986
+ } else {
21987
+ this.txtSipDomain = this.txtHostName;
21988
+ this.txtPublicIdentity = "sip:" + this.txtPrivateIdentity + "@" + this.txtHostNameWithPort;
21941
21989
  }
21942
- var oReadyStateTimer = setInterval(function () {
21943
- if (document.readyState === "complete") {
21944
- clearInterval(oReadyStateTimer);
21945
- logger.log("sipjsphone: init:readyState, calling preinit")
21946
- preInit();
21947
- }
21948
- }, 100);
21949
21990
 
21950
- },
21951
-
21952
-
21953
- loadCredentials: (sipAccountInfo) => {
21954
- txtDisplayName = sipAccountInfo['userName'];
21955
- txtPrivateIdentity = sipAccountInfo['authUser'];
21956
- txtHostNameWithPort = sipAccountInfo["domain"];
21957
- txtHostName = txtHostNameWithPort.split(":")[0];
21958
- txtWebSocketPort = txtHostNameWithPort.split(":")[1];
21959
- txtAccountName = sipAccountInfo['accountName'];
21960
- txtPublicIdentity = "sip:" + txtPrivateIdentity + "@" + txtHostNameWithPort;
21961
- txtPassword = sipAccountInfo["secret"];
21962
- txtRealm = txtHostName;
21963
- txtTurnServer = "drishti@" + txtRealm + ":3478";
21964
- txtCredential = "jrp931";
21965
- txtTurnUri = "'turn:" + txtRealm + ":3478?transport=udp', credential: '" + txtCredential + "', username: 'drishti'";
21991
+ this.txtPassword = sipAccountInfo["secret"];
21992
+ this.txtRealm = this.txtSipDomain; // Use sipdomain as realm
21993
+ this.txtTurnServer = "drishti@" + this.txtRealm + ":3478";
21994
+ this.txtCredential = "jrp931";
21995
+ this.txtTurnUri = "'turn:" + this.txtRealm + ":3478?transport=udp', credential: '" + this.txtCredential + "', username: 'drishti'";
21966
21996
 
21967
21997
 
21968
21998
  var default_values = {
21969
21999
  'security': window.location.protocol == "http:" ? 'ws' : 'wss',
21970
- 'sipdomain': txtHostName,
21971
- 'contactHost': txtHostName,
22000
+ 'sipdomain': this.txtHostName,
22001
+ 'contactHost': this.txtHostName,
21972
22002
  'wsPort': window.location.protocol == "http:" ? 8088 : 8089,
21973
22003
  'sipPort': window.location.protocol == "http:" ? 5060 : 5061,
21974
22004
  'endpoint': 'ws'
21975
22005
  }
21976
22006
 
21977
- txtSecurity = sipAccountInfo['security'] ? sipAccountInfo['security'] : default_values['security'];
21978
- txtWSPort = txtWebSocketPort ? txtWebSocketPort : default_values['wsPort'];
22007
+ this.txtSecurity = sipAccountInfo['security'] ? sipAccountInfo['security'] : default_values['security'];
22008
+ this.txtWSPort = this.txtWebSocketPort ? this.txtWebSocketPort : default_values['wsPort'];
21979
22009
 
21980
22010
  if (sipAccountInfo['sipdomain']) {
21981
- txtSipDomain = sipAccountInfo["sipdomain"];
21982
- txtPublicIdentity = "sip:" + txtPrivateIdentity + "@" + txtSipDomain;
22011
+ this.txtSipDomain = sipAccountInfo["sipdomain"];
22012
+ this.txtPublicIdentity = "sip:" + this.txtPrivateIdentity + "@" + this.txtSipDomain;
21983
22013
  } else {
21984
- txtSipDomain = default_values["sipdomain"];
22014
+ this.txtSipDomain = default_values["sipdomain"];
21985
22015
  }
21986
22016
 
21987
22017
  if (sipAccountInfo['contactHost']) {
21988
- txtContactHost = sipAccountInfo["contactHost"];
22018
+ this.txtContactHost = sipAccountInfo["contactHost"];
21989
22019
  } else {
21990
- txtContactHost = default_values["contactHost"];
22020
+ this.txtContactHost = default_values["contactHost"];
21991
22021
  }
21992
22022
 
21993
- txtSipPort = sipAccountInfo['sipPort'] ? sipAccountInfo["sipPort"] : default_values["sipPort"];
21994
- endpoint = sipAccountInfo['endpoint'] ? sipAccountInfo['endpoint'] : default_values['endpoint'];
22023
+ this.txtSipPort = sipAccountInfo['sipPort'] ? sipAccountInfo["sipPort"] : default_values["sipPort"];
21995
22024
 
21996
- txtWebsocketURL = txtSecurity + "://" + txtHostName + ":" + txtWSPort + "/" + endpoint;
21997
- txtUDPURL = "udp://" + txtHostName + ":" + txtSipPort;
22025
+ // Fix: Handle endpoint value to avoid double 'wss' path
22026
+ this.endpoint = sipAccountInfo['endpoint'] ? sipAccountInfo['endpoint'] : default_values['endpoint'];
22027
+
22028
+ // Construct WebSocket URL
22029
+ this.txtWebsocketURL = this.txtSecurity + "://" + this.txtHostName + ":" + this.txtWSPort;
22030
+ // Always append endpoint if it exists, regardless of its value
22031
+ if (this.endpoint) {
22032
+ this.txtWebsocketURL += "/" + this.endpoint;
22033
+ }
22034
+ this.txtUDPURL = "udp://" + this.txtHostName + ":" + this.txtSipPort;
21998
22035
 
21999
22036
 
22000
- var oInitializeCompleteTimer = setTimeout(function () {
22001
- if (initializeComplete == true) {
22002
- sipRegister();
22037
+ var oInitializeCompleteTimer = setTimeout(() => {
22038
+ if (this.initializeComplete) {
22039
+ this.sipRegister()
22003
22040
  }
22004
22041
  }, 500);
22005
- },
22042
+ }
22006
22043
 
22007
- getStatus: () => {
22008
- return webRTCStatus;
22009
- },
22044
+ getStatus() {
22045
+ return this.webRTCStatus;
22046
+ }
22010
22047
 
22011
- registerCallBacks: (handler) => {
22012
- callBackHandler = handler;
22013
- },
22048
+ registerCallBacks(handler) {
22049
+ this.callBackHandler = handler;
22050
+ }
22014
22051
 
22015
- sipSendDTMF: (c) => {
22016
- ctxSip.sipSendDTMF(c);
22017
- },
22052
+ sipSendDTMF(c) {
22053
+ this.ctxSip.sipSendDTMF(c);
22054
+ }
22018
22055
 
22019
- sipToggleRegister: () => {
22020
- if (register_flag == false) {
22021
- register_flag = true;
22022
- sipRegister();
22056
+ sipToggleRegister() {
22057
+ if (this.register_flag == false) {
22058
+ this.register_flag = true;
22059
+ this.sipRegister();
22023
22060
 
22024
- } else if (register_flag == true) {
22025
- registerer.unregister({});
22026
- register_flag = false;
22027
- webRTCStatus = "offline";
22028
- if (callBackHandler != null)
22029
- if (callBackHandler.onResponse)
22030
- callBackHandler.onResponse("error");
22061
+ } else if (this.register_flag == true) {
22062
+ this.registerer.unregister({});
22063
+ this.register_flag = false;
22064
+ this.webRTCStatus = "offline";
22065
+ if (this.callBackHandler != null)
22066
+ if (this.callBackHandler.onResponse)
22067
+ this.callBackHandler.onResponse("error");
22031
22068
 
22032
22069
  }
22033
- },
22070
+ }
22034
22071
 
22035
- reRegister: () => {
22072
+ reRegister() {
22036
22073
  logger.log("sipjsphone: reRegister: registering in case of relogin");
22037
- if (ctxSip.phone && registerer) {
22038
- registerer.register({});
22074
+ if (this.ctxSip.phone && this.registerer) {
22075
+ this.registerer.register({});
22039
22076
  } else {
22040
22077
  logger.log("sipjsphone: reRegister: SIP Session does not exist for re registration");
22041
22078
  }
22042
22079
 
22043
- },
22080
+ }
22044
22081
 
22045
- sipToggleMic: () => {
22046
- ctxSip.phoneMuteButtonPressed(ctxSip.callActiveID);
22047
- },
22082
+ sipToggleMic() {
22083
+ this.ctxSip.phoneMuteButtonPressed(this.ctxSip.callActiveID);
22084
+ }
22048
22085
 
22049
- sipMute: (bMute) => {
22050
- ctxSip.phoneMute(ctxSip.callActiveID, bMute);
22051
- },
22086
+ sipMute(bMute) {
22087
+ this.ctxSip.phoneMute(this.ctxSip.callActiveID, bMute);
22088
+ }
22052
22089
 
22053
- holdCall: () => {
22054
- if (ctxSip.callActiveID) {
22055
- ctxSip.phoneHoldButtonPressed(ctxSip.callActiveID);
22090
+ holdCall() {
22091
+ if (this.ctxSip.callActiveID) {
22092
+ this.ctxSip.phoneHoldButtonPressed(this.ctxSip.callActiveID);
22056
22093
  }
22057
- },
22094
+ }
22058
22095
 
22059
- sipHold: (bHold) => {
22060
- if (ctxSip.callActiveID) {
22061
- ctxSip.phoneHold(ctxSip.callActiveID, bHold);
22096
+ sipHold(bHold) {
22097
+ if (this.ctxSip.callActiveID) {
22098
+ this.ctxSip.phoneHold(this.ctxSip.callActiveID, bHold);
22062
22099
  }
22063
- },
22100
+ }
22064
22101
 
22065
- getMicMuteStatus: () => {
22066
- return bMicEnable;
22067
- },
22102
+ getMicMuteStatus() {
22103
+ // Prefer session mute state if available
22104
+ let sessionMuted = undefined;
22105
+ if (this.ctxSip && this.ctxSip.callActiveID && this.ctxSip.Sessions && this.ctxSip.Sessions[this.ctxSip.callActiveID]) {
22106
+ sessionMuted = !!this.ctxSip.Sessions[this.ctxSip.callActiveID].isMuted;
22107
+ logger.log(`[getMicMuteStatus] sessionMuted: ${sessionMuted}, global isMuted: ${this.isMuted}`);
22108
+ return sessionMuted;
22109
+ }
22110
+ logger.log(`[getMicMuteStatus] No active session, global isMuted: ${this.isMuted}`);
22111
+ return this.isMuted;
22112
+ }
22068
22113
 
22069
- setPreferredCodec: (codecName) => {
22114
+ setPreferredCodec(codecName) {
22070
22115
  logger.log("sipjsphone:setPreferredCodec entry");
22071
22116
  const codecPayloadTypes = {
22072
22117
  opus: { payloadType: 111, rtpMap: "opus/48000/2", fmtp: "minptime=10;useinbandfec=1" },
22073
22118
  };
22074
22119
 
22075
- const preferredCodec = codecPayloadTypes[codecName.toLowerCase()];
22076
- if (!preferredCodec) {
22077
- logger.error("sipjsphone:setPreferredCodec: Unsupported code" + codecName + "specified.");
22078
- SIPJSPhone.preferredCodec = null; // Clear codec details if unsupported
22079
- return;
22120
+ let codec = "opus"; // Default to opus
22121
+ if (codecName && codecPayloadTypes[codecName.toLowerCase()]) {
22122
+ codec = codecName.toLowerCase();
22123
+ } else if (codecName) {
22124
+ logger.error("sipjsphone:setPreferredCodec: Unsupported codec " + codecName + " specified. Defaulting to opus.");
22080
22125
  }
22081
22126
 
22082
- SIPJSPhone.preferredCodec = preferredCodec;
22083
- logger.log("sipjsphone:setPreferredCodec: Preferred codec set to " + codecName);
22084
- },
22127
+ this.preferredCodec = codecPayloadTypes[codec];
22128
+
22129
+ logger.log("sipjsphone:setPreferredCodec: Preferred codec set to " + codec);
22130
+ }
22085
22131
 
22086
- pickPhoneCall: () => {
22087
- var newSess = ctxSip.Sessions[ctxSip.callActiveID];
22088
- logger.log("sipjsphone: pickphonecall: ", ctxSip.callActiveID);
22132
+ pickPhoneCall() {
22133
+ var newSess = this.ctxSip.Sessions[this.ctxSip.callActiveID];
22134
+ logger.log("sipjsphone: pickphonecall: ", this.ctxSip.callActiveID);
22089
22135
  if (newSess) {
22090
22136
  if (_audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId != "default") {
22091
22137
  newSess.accept({
22092
22138
  sessionDescriptionHandlerOptions: {
22093
22139
  constraints: { audio: { deviceId: _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId }, video: false }
22094
22140
  },
22095
- sessionDescriptionHandlerModifiers: [addPreferredCodec]
22141
+ sessionDescriptionHandlerModifiers: [this.addPreferredCodec]
22096
22142
  }).catch((e) => {
22097
- onUserSessionAcceptFailed(e);
22143
+ this.onUserSessionAcceptFailed(e);
22098
22144
  });
22099
22145
  } else {
22100
22146
 
22101
22147
  newSess.accept({
22102
- sessionDescriptionHandlerModifiers: [addPreferredCodec]
22148
+ sessionDescriptionHandlerModifiers: [this.addPreferredCodec]
22103
22149
  }).catch((e) => {
22104
- onUserSessionAcceptFailed(e);
22150
+ this.onUserSessionAcceptFailed(e);
22105
22151
  });
22106
22152
  }
22107
22153
  }
22108
22154
 
22109
- },
22155
+ }
22110
22156
 
22111
22157
 
22112
- sipHangUp: () => {
22113
- ctxSip.sipHangUp(ctxSip.callActiveID);
22114
- },
22158
+ sipHangUp() {
22159
+ this.ctxSip.sipHangUp(this.ctxSip.callActiveID);
22160
+ }
22115
22161
 
22116
22162
 
22117
- playBeep: () => {
22163
+ playBeep() {
22118
22164
  try {
22119
- ctxSip.beeptone.play();
22165
+ this.ctxSip.beeptone.play();
22120
22166
  } catch (e) {
22121
22167
  logger.log("sipjsphone: playBeep: Exception:", e);
22122
22168
  }
22123
- },
22169
+ }
22124
22170
 
22125
- sipUnRegister: () => {
22126
- if (ctxSip.phone && registerer) {
22127
- registerer.unregister({}).then(function () {
22128
- destroySocketConnection();
22171
+ sipUnRegister() {
22172
+ if (this.ctxSip.phone && this.registerer) {
22173
+ this.registerer.unregister({}).then(() => {
22174
+ this.destroySocketConnection();
22129
22175
  });
22130
22176
  } else {
22131
- if (ctxSip.phone) {
22132
- destroySocketConnection();
22177
+ if (this.ctxSip.phone) {
22178
+ this.destroySocketConnection();
22133
22179
  }
22134
22180
  }
22135
- },
22181
+ }
22136
22182
 
22137
- connect: () => {
22183
+ connect() {
22138
22184
  try {
22139
- sipRegister();
22185
+ this.sipRegister();
22140
22186
  } catch (e) {
22141
22187
  }
22142
- },
22188
+ }
22143
22189
 
22144
- disconnect: () => {
22145
- if (registerer) {
22146
- cleanupRegistererTimer();
22190
+ disconnect() {
22191
+ if (this.registerer) {
22192
+ this.cleanupRegistererTimer();
22147
22193
  }
22148
- if (ctxSip.phone && ctxSip.phone.transport) {
22149
- ctxSip.phone.transport.stateChange.removeListener(transportStateChangeListener);
22150
- if (ctxSip.phone && ctxSip.phone.transport.isConnected()) {
22151
- destroySocketConnection();
22194
+ if (this.ctxSip.phone && this.ctxSip.phone.transport) {
22195
+ this.ctxSip.phone.transport.stateChange.removeListener(this.transportStateChangeListener);
22196
+ if (this.ctxSip.phone && this.ctxSip.phone.transport.isConnected()) {
22197
+ this.destroySocketConnection();
22152
22198
  }
22153
22199
  }
22154
- },
22200
+ }
22155
22201
  /* NL Additions - Start */
22156
- getSpeakerTestTone: () => {
22157
- logger.log("sipjsphone: getSpeakerTestTone: Returning speaker test tone:", ringtone);
22158
- return ringtone;
22159
- },
22202
+ getSpeakerTestTone() {
22203
+ logger.log("sipjsphone: getSpeakerTestTone: Returning speaker test tone:", this.ringtone);
22204
+ return this.ringtone;
22205
+ }
22160
22206
 
22161
22207
 
22162
- getWSSUrl: () => {
22163
- logger.log("sipjsphone: getWSSUrl: Returning txtWebsocketURL:", txtWebsocketURL);
22164
- return txtWebsocketURL;
22165
- },
22166
- /* NL Additions - End */
22167
- getTransportState: () => {
22168
- logger.log("sipjsphone: getTransportState: Returning Transport State : ", lastTransportState);
22169
- return lastTransportState;
22170
- },
22171
- getRegistrationState: () => {
22172
- logger.log("sipjsphone: getRegistrationState: Returning Registration State : ", lastRegistererState);
22173
- return lastRegistererState;
22174
- },
22208
+ getWSSUrl() {
22209
+ logger.log("sipjsphone: getWSSUrl: Returning txtWebsocketURL:", this.txtWebsocketURL);
22210
+ return this.txtWebsocketURL;
22211
+ }
22212
+ /* NL Additions - End */
22213
+ getTransportState() {
22214
+ logger.log("sipjsphone: getTransportState: Returning Transport State : ", this.lastTransportState);
22215
+ return this.lastTransportState;
22216
+ }
22217
+ getRegistrationState() {
22218
+ logger.log("sipjsphone: getRegistrationState: Returning Registration State : ", this.lastRegistererState);
22219
+ return this.lastRegistererState;
22220
+ }
22175
22221
 
22176
22222
  changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange) {
22177
- logger.log(`SIPJSPhone: changeAudioInputDevice called with deviceId=${deviceId}, forceDeviceChange=${forceDeviceChange}, enableAutoAudioDeviceChangeHandling=${enableAutoAudioDeviceChangeHandling}`);
22178
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.changeAudioInputDevice(deviceId, function (stream) {
22179
- SIPJSPhone.replaceSenderTrack(stream, deviceId, onSuccess, onError);
22180
- }, onError, forceDeviceChange);
22181
- },
22223
+ logger.log("sipjsphone: changeAudioInputDevice : ", deviceId, onSuccess, onError, "forceDeviceChange = ", forceDeviceChange, "enableAutoAudioDeviceChangeHandling = ", this.enableAutoAudioDeviceChangeHandling);
22224
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.changeAudioInputDevice(deviceId, (stream) => {
22225
+ const trackChanged = this.replaceSenderTrack(stream, deviceId);
22226
+ if (trackChanged) {
22227
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId = deviceId;
22228
+ logger.log(`sipjsphone: changeAudioInputDevice: Input device changed to: ${deviceId}`);
22229
+ if (onSuccess) onSuccess();
22230
+ } else {
22231
+ logger.error("sipjsphone: changeAudioInputDevice: failed");
22232
+ if (onError) onError("replaceSenderTrack failed for webrtc");
22233
+ }
22234
+ }, (err) => {
22235
+ logger.error("sipjsphone: changeAudioInputDevice error:", err);
22236
+ if (onError) onError(err);
22237
+ },
22238
+ forceDeviceChange);
22239
+ }
22240
+
22241
+ async changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange) {
22242
+ logger.log("sipjsphone: changeAudioOutputDevice : ", deviceId, onSuccess, onError, "forceDeviceChange = ", forceDeviceChange, "enableAutoAudioDeviceChangeHandling = ", this.enableAutoAudioDeviceChangeHandling);
22243
+ try {
22244
+ // Ensure device list is up-to-date
22245
+ await _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.enumerateDevices();
22246
+ if (!this.audioRemote) {
22247
+ const errorMsg = 'SIPJSPhone:changeAudioOutputDevice audioRemote element is not set.';
22248
+ logger.error(errorMsg);
22249
+ if (onError) onError(errorMsg);
22250
+ return;
22251
+ }
22252
+ if (typeof this.audioRemote.sinkId === 'undefined') {
22253
+ const errorMsg = 'SIPJSPhone:changeAudioOutputDevice Browser does not support output device selection.';
22254
+ logger.error(errorMsg);
22255
+ if (onError) onError(errorMsg);
22256
+ return;
22257
+ }
22258
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.changeAudioOutputDevice(this.audioRemote, deviceId, () => {
22259
+ this.changeAudioOutputDeviceForAdditionalAudioElement(deviceId);
22260
+ if (onSuccess) onSuccess();
22261
+ }, (err) => {
22262
+ logger.error('SIPJSPhone:changeAudioOutputDevice error:', err);
22263
+ if (onError) onError(err);
22264
+ },
22265
+ forceDeviceChange);
22266
+ } catch (e) {
22267
+ logger.error('SIPJSPhone:changeAudioOutputDevice unexpected error:', e);
22268
+ if (onError) onError(e);
22269
+ }
22270
+ }
22271
+
22182
22272
  changeAudioOutputDeviceForAdditionalAudioElement(deviceId) {
22183
- const additionalAudioElements = [ringtone, beeptone, ringbacktone, dtmftone];
22273
+ const additionalAudioElements = [this.ringtone, this.beeptone, this.ringbacktone, this.dtmftone];
22184
22274
  let i = 0;
22185
22275
  let elem;
22186
22276
  try {
@@ -22192,17 +22282,7 @@ const SIPJSPhone = {
22192
22282
  } catch (e) {
22193
22283
  logger.error("sipjsphone:changeAudioOutputDeviceForAdditionalAudioElement failed to setSink for additonal AudioElements", e);
22194
22284
  }
22195
- },
22196
- changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange) {
22197
- logger.log(`SIPJSPhone: changeAudioOutputDevice called with deviceId=${deviceId}, forceDeviceChange=${forceDeviceChange}, enableAutoAudioDeviceChangeHandling=${enableAutoAudioDeviceChangeHandling}`);
22198
- if (!ctxSip.callActiveID) {
22199
- audioRemote = document.createElement("audio");
22200
- }
22201
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.changeAudioOutputDevice(audioRemote, deviceId, function () {
22202
- SIPJSPhone.changeAudioOutputDeviceForAdditionalAudioElement(deviceId);
22203
- onSuccess();
22204
- }, onError, forceDeviceChange);
22205
- },
22285
+ }
22206
22286
 
22207
22287
  stopStreamTracks(stream) {
22208
22288
  try {
@@ -22215,104 +22295,222 @@ const SIPJSPhone = {
22215
22295
  } catch (e) {
22216
22296
  logger.error("sipjsphone:stopStreamTracks failed to stop tracks");
22217
22297
  }
22218
- },
22219
- replaceSenderTrack(stream, deviceId, onSuccessCallback, onErrorCallback) {
22220
- logger.log(`sipjsphone:replaceSenderTrack: entry, deviceId=${deviceId}`);
22221
- let trackChanged = false;
22222
- let errorMessage = "";
22298
+ }
22299
+ replaceSenderTrack(stream, deviceId) {
22223
22300
  try {
22224
- if (ctxSip.callActiveID) {
22225
- ctxSip.Stream = stream;
22226
- const s = ctxSip.Sessions[ctxSip.callActiveID];
22301
+
22302
+ if (_audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId == deviceId) {
22303
+ this.stopStreamTracks(stream);
22304
+ return false;
22305
+ }
22306
+ if (this.ctxSip.callActiveID) {
22307
+ this.ctxSip.Stream = stream;
22308
+ const s = this.ctxSip.Sessions[this.ctxSip.callActiveID];
22227
22309
  const pc = s.sessionDescriptionHandler.peerConnection;
22228
22310
  if (pc.getSenders) {
22311
+ try {
22229
22312
  const [audioTrack] = stream.getAudioTracks();
22230
22313
  const sender = pc.getSenders().find((s) => s.track.kind === audioTrack.kind);
22231
22314
  sender.track.stop();
22232
22315
  sender.replaceTrack(audioTrack);
22233
- trackChanged = true;
22234
- } else {
22235
- logger.error("sipjsphone:replaceSenderTrack: no sender found");
22236
- errorMessage = "no sender found";
22316
+ } catch (e) {
22317
+ logger.error(`replaceSenderTrack unable to replace track for stream for device id ${deviceId} `, stream);
22318
+ }
22237
22319
  }
22238
22320
  } else {
22239
- logger.log("sipjsphone:replaceSenderTrack: no call active, stopping stream tracks");
22240
- errorMessage = "no call active";
22321
+ this.stopStreamTracks(stream);
22241
22322
  }
22323
+ return true;
22242
22324
  } catch (e) {
22243
- logger.error("sipjsphone:replaceSenderTrack: failed to replace track", e);
22244
- errorMessage = "failed to replace track";
22245
- }
22246
-
22247
- if(trackChanged) {
22248
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId = deviceId;
22249
- logger.info("sipjsphone:replaceSenderTrack: track replaced");
22250
- onSuccessCallback();
22251
- } else {
22252
- SIPJSPhone.stopStreamTracks(stream);
22253
- onErrorCallback(errorMessage);
22325
+ return false;
22254
22326
  }
22255
22327
 
22256
- },
22328
+ }
22257
22329
  registerLogger(customLogger) {
22258
22330
  logger = customLogger;
22259
- },
22260
- audioInputDeviceChangeCallback: null,
22261
- audioOutputDeviceChangeCallback: null,
22262
- onDeviceChangeCallback: null,
22331
+ }
22263
22332
  registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback) {
22264
22333
  logger.log(`sipjsphone: registerAudioDeviceChangeCallback: entry`);
22265
- SIPJSPhone.audioInputDeviceChangeCallback = audioInputDeviceChangeCallback;
22266
- SIPJSPhone.audioOutputDeviceChangeCallback = audioOutputDeviceChangeCallback;
22267
- SIPJSPhone.onDeviceChangeCallback = onDeviceChangeCallback;
22268
- },
22269
- attachGlobalDeviceChangeListener() {
22270
- logger.log("SIPJSPhone: Attaching global devicechange event listener (enableAutoAudioDeviceChangeHandling is true)");
22271
- navigator.mediaDevices.addEventListener('devicechange', (event) => {
22272
- try {
22273
- if (!ctxSip.callActiveID) {
22274
- audioRemote = document.createElement("audio");
22334
+ this.audioInputDeviceChangeCallback = audioInputDeviceChangeCallback;
22335
+ this.audioOutputDeviceChangeCallback = audioOutputDeviceChangeCallback;
22336
+ this.onDeviceChangeCallback = onDeviceChangeCallback;
22337
+ }
22338
+
22339
+ uiCallTerminated(s_description) {
22340
+ if (window.btnBFCP)
22341
+ window.btnBFCP.disabled = true;
22342
+ this.ctxSip.stopRingTone();
22343
+ this.ctxSip.stopRingbackTone();
22344
+ if (this.callBackHandler && this.callBackHandler.onResponse)
22345
+ this.callBackHandler.onResponse("disconnected");
22346
+ }
22347
+
22348
+ sipCall() {
22349
+ logger.log("sipjsphone: sipCall: testing emit accept_reject");
22350
+ if (this.webrtcSIPPhoneEventDelegate)
22351
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("accept_reject", "CALL");
22352
+ }
22353
+
22354
+ onInvitationSessionAccepted(newSess) {
22355
+ // Reset mute state at the start of every call
22356
+ logger.log(`[onInvitationSessionAccepted] Resetting mute state. Before: newSess.isMuted=${newSess && newSess.isMuted}, global isMuted=${this.isMuted}`);
22357
+ this.isMuted = false;
22358
+ if (newSess && newSess.isMuted !== undefined) {
22359
+ newSess.isMuted = false;
22360
+ }
22361
+ logger.log(`[onInvitationSessionAccepted] After reset: newSess.isMuted=${newSess && newSess.isMuted}, global isMuted=${this.isMuted}`);
22362
+ this.ctxSip.Stream = newSess.sessionDescriptionHandler.localMediaStream;
22363
+ logger.log('onInvitationSessionAccepted: assigning remote stream to audioRemote');
22364
+ this.assignStream(newSess.sessionDescriptionHandler.remoteMediaStream, this.audioRemote);
22365
+ logger.log('onInvitationSessionAccepted: assignStream called');
22366
+ if (this.webrtcSIPPhoneEventDelegate) {
22367
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('accepted');
22368
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("connected", "CALL");
22369
+ }
22370
+ // If there is another active call, hold it
22371
+ if (this.ctxSip.callActiveID && this.ctxSip.callActiveID !== newSess.ctxid) {
22372
+ this.ctxSip.phoneHoldButtonPressed(this.ctxSip.callActiveID);
22373
+ }
22374
+ this.ctxSip.stopRingbackTone();
22375
+ this.ctxSip.stopRingTone();
22376
+ this.ctxSip.setCallSessionStatus('Answered');
22377
+ this.ctxSip.logCall(newSess, 'answered');
22378
+ this.ctxSip.callActiveID = newSess.ctxid;
22379
+ this.webRTCStatus = "busy";
22380
+ if (this.callBackHandler && this.callBackHandler.onResponse)
22381
+ this.callBackHandler.onResponse("connected");
22382
+ }
22383
+
22384
+ onInvitationSessionTerminated() {
22385
+ this.stopStreamTracks(this.ctxSip.Stream);
22386
+ if (this.webrtcSIPPhoneEventDelegate) {
22387
+ this.webrtcSIPPhoneEventDelegate.stopCallStat();
22388
+ this.webrtcSIPPhoneEventDelegate.onCallStatSipJsSessionEvent('terminated');
22389
+ }
22390
+ this.ctxSip.stopRingTone();
22391
+ this.ctxSip.stopRingbackTone();
22392
+ this.ctxSip.setCallSessionStatus("");
22393
+ this.ctxSip.callActiveID = null;
22394
+ if (this.webrtcSIPPhoneEventDelegate) {
22395
+ this.webrtcSIPPhoneEventDelegate.playBeepTone();
22396
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("terminated", "CALL");
22397
+ }
22398
+ this.uiCallTerminated();
22399
+ this.webRTCStatus = "ready";
22400
+ if (this.callBackHandler && this.callBackHandler.onResponse)
22401
+ this.callBackHandler.onResponse("disconnected");
22402
+ }
22403
+
22404
+ onUserAgentRegistered() {
22405
+ if (this.webrtcSIPPhoneEventDelegate) {
22406
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("connected", "CONNECTION");
22407
+ }
22408
+ this.uiOnConnectionEvent(true, false);
22409
+ this.register_flag = true;
22410
+ this.webRTCStatus = "ready";
22411
+ if (this.callBackHandler && this.callBackHandler.onResponse)
22412
+ this.callBackHandler.onResponse("ready");
22413
+ window.onunload = () => {
22414
+ localStorage.removeItem('ctxPhone');
22415
+ if (this.ctxSip.phone) this.ctxSip.phone.stop();
22416
+ };
22417
+ localStorage.setItem('ctxPhone', 'true');
22418
+ }
22419
+
22420
+ onUserAgentRegistrationTerminated() {
22421
+ this.uiOnConnectionEvent(false, false);
22422
+ }
22423
+
22424
+ onUserAgentRegistrationFailed() {
22425
+ if (this.webrtcSIPPhoneEventDelegate) {
22426
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM("terminated", "CONNECTION");
22427
+ }
22428
+ this.uiOnConnectionEvent(false, false);
22429
+ this.register_flag = false;
22430
+ if (this.callBackHandler && this.callBackHandler.onResponse) {
22431
+ this.callBackHandler.onResponse("error");
22432
+ }
22433
+ }
22434
+
22435
+ sipPhoneLogger(level, category, label, content) {
22436
+ try {
22437
+ if (content) {
22438
+ if (content.startsWith("Sending WebSocket")) {
22439
+ this.handleWebSocketMessageContent(content, "sent");
22440
+ } else if (content.startsWith("Received WebSocket text message")) {
22441
+ this.handleWebSocketMessageContent(content, "recv");
22275
22442
  }
22276
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.enumerateDevices(() => {
22277
- if (SIPJSPhone.onDeviceChangeCallback) {
22278
- logger.info("SIPJSPhone:ondevicechange relaying event to callback");
22279
- SIPJSPhone.onDeviceChangeCallback(event);
22280
- }
22281
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.onAudioDeviceChange(
22282
- audioRemote,
22283
- (stream, deviceId) => {
22284
- SIPJSPhone.replaceSenderTrack(stream, deviceId, function (){
22285
- if (SIPJSPhone.audioInputDeviceChangeCallback) {
22286
- SIPJSPhone.audioInputDeviceChangeCallback(deviceId);
22287
- }
22288
- }, function(errorMessage) {
22289
- logger.error("sipjsphone:ondevicechange: failed to replace track", errorMessage);
22290
- });
22291
-
22292
-
22293
- },
22294
- (deviceId) => {
22295
- SIPJSPhone.changeAudioOutputDeviceForAdditionalAudioElement(deviceId);
22296
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioOutputDeviceId = deviceId;
22297
- if (SIPJSPhone.audioOutputDeviceChangeCallback) {
22298
- SIPJSPhone.audioOutputDeviceChangeCallback(deviceId);
22299
- }
22443
+ logger.log("sipjsphone: sipPhoneLogger:" + level + " sipjslog: " + category + ": " + content);
22444
+ }
22445
+ } catch (e) {
22446
+ logger.error("sipjsphone:sipPhoneLogger ERROR", e);
22447
+ }
22448
+ }
22449
+
22450
+ _onDeviceChange(event) {
22451
+ try {
22452
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.enumerateDevices(() => {
22453
+ if (this.onDeviceChangeCallback) {
22454
+ logger.info("SIPJSPhone:ondevicechange relaying event to callback");
22455
+ this.onDeviceChangeCallback(event);
22456
+ return;
22457
+ }
22458
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.onAudioDeviceChange(
22459
+ this.audioRemote,
22460
+ (stream, deviceId) => {
22461
+ const trackChanged = this.replaceSenderTrack(stream, deviceId);
22462
+ if (trackChanged) {
22463
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId = deviceId;
22464
+ if (this.audioInputDeviceChangeCallback) {
22465
+ this.audioInputDeviceChangeCallback(deviceId);
22300
22466
  }
22301
- );
22467
+ }
22468
+ },
22469
+ (deviceId) => {
22470
+ this.changeAudioOutputDeviceForAdditionalAudioElement(deviceId);
22471
+ _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioOutputDeviceId = deviceId;
22472
+ if (this.audioOutputDeviceChangeCallback) {
22473
+ this.audioOutputDeviceChangeCallback(deviceId);
22474
+ }
22475
+ }
22476
+ );
22302
22477
  });
22303
- } catch (e) {
22304
- logger.error("SIPJSPhone:ondevicechange something went wrong during device change", e);
22478
+ } catch (e) {
22479
+ logger.error("SIPJSPhone:ondevicechange something went wrong during device change", e);
22480
+ }
22481
+ }
22482
+
22483
+ _makeAudio(src) { const a = new Audio(src); return a; }
22484
+
22485
+ registerPhoneEventListeners() {
22486
+ this.ctxSip.phone.start();
22487
+ this.ctxSip.phone.transport.stateChange.addListener((s) => {
22488
+ if (s === SIP.TransportState.Connected && !this.registerer) {
22489
+ this.registerer = new SIP.Registerer(this.ctxSip.phone, {expires:300, refreshFrequency: 80 });
22490
+ this.registerer.register();
22305
22491
  }
22306
22492
  });
22307
- },
22308
- setEnableAutoAudioDeviceChangeHandling(flag) {
22309
- logger.log("sipjsphone: setEnableAutoAudioDeviceChangeHandling: entry, enableAutoAudioDeviceChangeHandling = ",flag);
22310
- enableAutoAudioDeviceChangeHandling = flag;
22311
- _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.setEnableAutoAudioDeviceChangeHandling(flag);
22312
- }
22313
- };
22493
+ }
22314
22494
 
22495
+ registerWebRTCClient(sipAccountInfo, webrtcSIPPhoneEventDelegate) {
22496
+ this.webrtcSIPPhoneEventDelegate = webrtcSIPPhoneEventDelegate;
22497
+ this.init(sipAccountInfo, () => {
22498
+ this.setPreferredCodec(sipAccountInfo.preferredCodec);
22499
+ this.registerPhoneEventListeners(this.ctxSip);
22500
+ });
22501
+ }
22315
22502
 
22503
+ muteAction(bMute) {
22504
+ logger.log("webrtcSIPPhone: muteAction: ", [bMute]);
22505
+ // Always operate on the current session
22506
+ if (this.ctxSip && this.ctxSip.callActiveID && this.ctxSip.Sessions && this.ctxSip.Sessions[this.ctxSip.callActiveID]) {
22507
+ this.phone.sipMute(bMute);
22508
+ } else {
22509
+ logger.warn("webrtcSIPPhone: muteAction: No active session to mute/unmute");
22510
+ }
22511
+ }
22512
+
22513
+ }
22316
22514
 
22317
22515
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (SIPJSPhone);
22318
22516
 
@@ -22373,54 +22571,105 @@ module.exports = __webpack_require__.p + "ringtone.wav";
22373
22571
  __webpack_require__.r(__webpack_exports__);
22374
22572
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
22375
22573
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
22376
- /* harmony export */ webrtcSIPPhone: () => (/* binding */ webrtcSIPPhone)
22574
+ /* harmony export */ getLogger: () => (/* binding */ getLogger)
22377
22575
  /* harmony export */ });
22378
22576
  /* harmony import */ var _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./coreSDKLogger */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/coreSDKLogger.js");
22379
22577
  /* harmony import */ var _sipjsphone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./sipjsphone */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/sipjsphone.js");
22380
22578
  /* harmony import */ var _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./webrtcSIPPhoneEventDelegate */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/webrtcSIPPhoneEventDelegate.js");
22381
- /**
22382
- * Communication from Webrtc flows and feature handling for web RTC as WebRTC Phone Interface
22383
- *
22384
- */
22385
22579
 
22386
22580
 
22387
22581
 
22388
22582
 
22389
- var phone = null;
22390
- let webrtcSIPEngine = null;
22391
22583
  const logger = _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__["default"];
22392
22584
 
22585
+ function getLogger() {
22586
+ return _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__["default"];
22587
+ }
22588
+
22393
22589
  function sendWebRTCEventsToFSM(eventType, sipMethod) {
22394
22590
  logger.log("webrtcSIPPhone: sendWebRTCEventsToFSM : ",eventType,sipMethod);
22395
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].sendWebRTCEventsToFSM(eventType, sipMethod);
22591
+ this.webrtcSIPPhoneEventDelegate = new _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"]();
22592
+ this.webrtcSIPPhoneEventDelegate.sendWebRTCEventsToFSM(eventType, sipMethod);
22396
22593
  }
22397
22594
 
22398
- let sipAccountInfoData = {};
22595
+ class WebrtcSIPPhone {
22399
22596
 
22400
- const webrtcSIPPhone = {
22597
+ constructor(username) {
22598
+ if (!username) {
22599
+ throw new Error("username is required for WebrtcSIPPhone");
22600
+ }
22601
+ this.username = username;
22602
+ this.webrtcSIPEngine = null;
22603
+ this.webrtcSIPPhoneEventDelegate = new _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"](username);
22604
+ this.phone = null;
22605
+ }
22606
+
22607
+ static getLogger() {
22608
+ return _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__["default"];
22609
+ }
22610
+
22611
+ registerPhone(engine, delegate, enableAutoAudioDeviceChangeHandling = false) {
22612
+ logger.log("webrtcSIPPhone: registerPhone : ", engine, "enableAutoAudioDeviceChangeHandling:", enableAutoAudioDeviceChangeHandling);
22613
+ this.webrtcSIPEngine = engine;
22614
+
22615
+ if (!this.webrtcSIPPhoneEventDelegate) {
22616
+ this.webrtcSIPPhoneEventDelegate = new _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"](this.username);
22617
+ }
22618
+
22619
+ this.webrtcSIPPhoneEventDelegate.registerDelegate(delegate);
22620
+
22621
+ switch (engine) {
22622
+ case "sipjs":
22623
+ this.phone = new _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"](
22624
+ this.webrtcSIPPhoneEventDelegate,
22625
+ this.username
22626
+ );
22627
+ break;
22628
+ default:
22629
+ logger.log("webrtcSIPPhone: Unsupported engine type:", engine);
22630
+ break;
22631
+ }
22632
+
22633
+ this.webrtcSIPPhoneEventDelegate.onRegisterWebRTCSIPEngine(engine);
22634
+ this.phone.setEnableAutoAudioDeviceChangeHandling(enableAutoAudioDeviceChangeHandling);
22635
+ if(enableAutoAudioDeviceChangeHandling) {
22636
+ this.phone.attachGlobalDeviceChangeListener();
22637
+ }
22638
+ }
22401
22639
 
22640
+ getWebRTCStatus() {
22641
+ logger.log("webrtcSIPPhone: getWebRTCStatus entry");
22642
+ if (!this.phone) {
22643
+ logger.log("webrtcSIPPhone: getWebRTCStatus: phone not initialized");
22644
+ return "offline";
22645
+ }
22646
+ const status = this.phone.getStatus();
22647
+ logger.log("webrtcSIPPhone: getWebRTCStatus: current status:", status);
22648
+ return status;
22649
+ }
22402
22650
 
22403
- isConnected: () => {
22651
+ isConnected() {
22404
22652
  logger.log("webrtcSIPPhone: isConnected entry");
22405
- var status = phone.getStatus();
22406
- if (status != "offline") {
22407
- return true;
22408
- } else {
22653
+ if (!this.phone) {
22654
+ logger.log("webrtcSIPPhone: isConnected: phone not initialized");
22409
22655
  return false;
22410
22656
  }
22411
- },
22657
+ const status = this.phone.getStatus();
22658
+ logger.log("webrtcSIPPhone: isConnected: current status:", status);
22659
+ return status !== "offline";
22660
+ }
22412
22661
 
22413
- sendDTMFWebRTC: (dtmfValue) => {
22662
+ sendDTMFWebRTC (dtmfValue){
22414
22663
  logger.log("webrtcSIPPhone: sendDTMFWebRTC : ",dtmfValue);
22415
- phone.sipSendDTMF(dtmfValue);
22416
- },
22664
+ this.phone.sipSendDTMF(dtmfValue);
22665
+ }
22417
22666
 
22418
- registerWebRTCClient: (sipAccountInfo, handler) => {
22667
+ registerWebRTCClient (sipAccountInfo, handler){
22419
22668
  logger.log("webrtcSIPPhone: registerWebRTCClient : ",sipAccountInfo,handler);
22420
- sipAccountInfoData = sipAccountInfo;
22421
- phone.init(() => {
22422
- phone.loadCredentials(sipAccountInfo);
22423
- if (webrtcSIPPhone.getWebRTCStatus() == "offline") {
22669
+ this.sipAccountInfoData = sipAccountInfo;
22670
+ this.phone.init(() => {
22671
+ this.phone.loadCredentials(sipAccountInfo);
22672
+ if (this.getWebRTCStatus() == "offline") {
22424
22673
  if (handler != null)
22425
22674
  if (handler.onFailure)
22426
22675
  handler.onFailure();
@@ -22430,206 +22679,171 @@ const webrtcSIPPhone = {
22430
22679
  handler.onResponse();
22431
22680
  }
22432
22681
  });
22682
+ }
22433
22683
 
22434
- },
22435
-
22436
-
22437
- configureWebRTCClientDevice: (handler) => {
22684
+ configureWebRTCClientDevice (handler){
22438
22685
  logger.log("webrtcSIPPhone: configureWebRTCClientDevice : ",handler);
22439
- phone.registerCallBacks(handler);
22440
- },
22686
+ this.phone.registerCallBacks(handler);
22687
+ }
22441
22688
 
22442
22689
  setAuthenticatorServerURL(serverURL) {
22443
22690
  logger.log("webrtcSIPPhone: setAuthenticatorServerURL : ",serverURL);
22444
- // Nothing to do here
22445
- },
22691
+ }
22446
22692
 
22447
- toggleSipRegister: () => {
22693
+ toggleSipRegister (){
22448
22694
  logger.log("webrtcSIPPhone: toggleSipRegister entry");
22449
- phone.resetRegisterAttempts();
22450
- phone.sipToggleRegister();
22451
- },
22695
+ this.phone.resetRegisterAttempts();
22696
+ this.phone.sipToggleRegister();
22697
+ }
22452
22698
 
22453
- webRTCMuteUnmute: () => {
22699
+ webRTCMuteUnmute (){
22454
22700
  logger.log("webrtcSIPPhone: webRTCMuteUnmute");
22455
- phone.sipToggleMic();
22456
- },
22701
+ this.phone.sipToggleMic();
22702
+ }
22457
22703
 
22458
- getMuteStatus: () => {
22704
+ getMuteStatus (){
22459
22705
  logger.log("webrtcSIPPhone: getMuteStatus entry");
22460
- return phone.getMicMuteStatus();
22461
- },
22706
+ return this.phone.getMicMuteStatus();
22707
+ }
22462
22708
 
22463
- muteAction: (bMute) => {
22709
+ muteAction (bMute){
22464
22710
  logger.log("webrtcSIPPhone: muteAction: ",bMute);
22465
- phone.sipMute(bMute);
22466
- },
22711
+ this.phone.sipMute(bMute);
22712
+ }
22467
22713
 
22468
- holdAction: (bHold) => {
22714
+ holdAction (bHold){
22469
22715
  logger.log("webrtcSIPPhone: holdAction: ",bHold);
22470
- phone.sipHold(bHold);
22471
- },
22716
+ this.phone.sipHold(bHold);
22717
+ }
22472
22718
 
22473
- holdCall: () => {
22719
+ holdCall (){
22474
22720
  logger.log("webrtcSIPPhone: holdCall entry");
22475
- phone.holdCall();
22476
- },
22721
+ this.phone.holdCall();
22722
+ }
22477
22723
 
22478
- pickCall: () => {
22724
+ pickCall (){
22479
22725
  logger.log("webrtcSIPPhone: pickCall entry");
22480
- phone.pickPhoneCall();
22726
+ this.phone.pickPhoneCall();
22481
22727
 
22482
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onPickCall();
22483
- },
22728
+ this.webrtcSIPPhoneEventDelegate.onPickCall();
22729
+ }
22484
22730
 
22485
- rejectCall: () => {
22731
+ rejectCall (){
22486
22732
  logger.log("webrtcSIPPhone: rejectCall entry");
22487
- phone.sipHangUp();
22733
+ this.phone.sipHangUp();
22488
22734
 
22489
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onRejectCall();
22490
- },
22735
+ this.webrtcSIPPhoneEventDelegate.onRejectCall();
22736
+ }
22491
22737
 
22492
- reRegisterWebRTCPhone: () => {
22738
+ reRegisterWebRTCPhone (){
22493
22739
  logger.log("webrtcSIPPhone: reRegisterWebRTCPhone entry");
22494
- phone.reRegister();
22495
- },
22496
-
22740
+ this.phone.reRegister();
22741
+ }
22497
22742
 
22498
- playBeepTone: () => {
22743
+ playBeepTone (){
22499
22744
  logger.log("webrtcSIPPhone: playBeepTone entry");
22500
- phone.playBeep();
22501
-
22502
- },
22745
+ this.phone.playBeep();
22746
+ }
22503
22747
 
22504
- sipUnRegisterWebRTC: () => {
22748
+ sipUnRegisterWebRTC (){
22505
22749
  logger.log("webrtcSIPPhone: sipUnRegisterWebRTC entry");
22506
- phone.sipUnRegister();
22507
- },
22750
+ this.phone.sipUnRegister();
22751
+ }
22508
22752
 
22509
- startWSNetworkTest: () => {
22753
+ startWSNetworkTest (){
22510
22754
  logger.log("webrtcSIPPhone: startWSNetworkTest entry");
22511
- undefined.testingMode = true;
22512
- phone.sipRegister();
22513
- },
22755
+ this.testingMode = true;
22756
+ this.phone.sipRegister();
22757
+ }
22514
22758
 
22515
- stopWSNetworkTest: () => {
22759
+ stopWSNetworkTest (){
22516
22760
  logger.log("webrtcSIPPhone stopWSNetworkTest entry");
22517
- phone.sipUnRegister();
22518
- },
22519
-
22520
-
22521
-
22522
- registerPhone: (engine, delegate, enableAutoAudioDeviceChangeHandling = false) => {
22523
- logger.log("webrtcSIPPhone: registerPhone : ",engine, "enableAutoAudioDeviceChangeHandling:", enableAutoAudioDeviceChangeHandling);
22524
- webrtcSIPEngine = engine;
22525
- switch (engine) {
22526
- case "sipjs":
22527
- phone = _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"];
22528
- break;
22529
- default:
22530
- break;
22531
- }
22532
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].registerDelegate(delegate);
22533
- _webrtcSIPPhoneEventDelegate__WEBPACK_IMPORTED_MODULE_2__["default"].onRegisterWebRTCSIPEngine(engine);
22534
- phone.setEnableAutoAudioDeviceChangeHandling(enableAutoAudioDeviceChangeHandling);
22535
- if (enableAutoAudioDeviceChangeHandling) {
22536
- phone.attachGlobalDeviceChangeListener();
22537
- }
22538
- },
22539
-
22540
- getWebRTCStatus: () => {
22541
- logger.log("webrtcSIPPhone: getWebRTCStatus entry");
22542
- var status = phone.getStatus();
22543
- return status;
22544
- },
22761
+ this.phone.sipUnRegister();
22762
+ }
22545
22763
 
22546
- disconnect: () => {
22764
+ disconnect (){
22547
22765
  logger.log("webrtcSIPPhone: disconnect entry");
22548
- if (phone) {
22549
- phone.disconnect();
22766
+ if (this.phone) {
22767
+ this.phone.disconnect();
22550
22768
  }
22551
- },
22769
+ }
22552
22770
 
22553
- connect: () => {
22771
+ connect (){
22554
22772
  logger.log("webrtcSIPPhone: connect entry");
22555
- phone.connect();
22556
- },
22773
+ this.phone.connect();
22774
+ }
22557
22775
 
22558
22776
  getSIPAccountInfo() {
22559
22777
  logger.log("webrtcSIPPhone: getSIPAccountInfo entry");
22560
- return sipAccountInfoData;
22561
- },
22778
+ return this.sipAccountInfoData;
22779
+ }
22780
+
22562
22781
  getWebRTCSIPEngine() {
22563
22782
  logger.log("webrtcSIPPhone: getWebRTCSIPEngine entry");
22564
- return webrtcSIPEngine;
22565
- },
22783
+ return this.webrtcSIPEngine;
22784
+ }
22566
22785
 
22567
22786
  /* NL Addition - Start */
22568
22787
  getSpeakerTestTone() {
22569
22788
  logger.log("webrtcSIPPhone: getSpeakerTestTone entry");
22570
22789
  try {
22571
- return _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].getSpeakerTestTone()
22790
+ return this.phone.getSpeakerTestTone()
22572
22791
  } catch (e) {
22573
22792
  logger.log("getSpeakerTestTone: Exception ", e)
22574
22793
  }
22575
- },
22794
+ }
22576
22795
 
22577
22796
  getWSSUrl() {
22578
22797
  logger.log("webrtcSIPPhone: getWSSUrl entry");
22579
22798
  try {
22580
- return _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].getWSSUrl()
22799
+ return this.phone.getWSSUrl()
22581
22800
  } catch (e) {
22582
22801
  logger.log("getWSSUrl: Exception ", e)
22583
22802
  }
22584
- },
22585
- /* NL Addition - End */
22803
+ }
22586
22804
 
22587
22805
  getTransportState() {
22588
22806
  logger.log("webrtcSIPPhone: getTransportState entry");
22589
22807
  try {
22590
- return _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].getTransportState();
22808
+ return this.phone.getTransportState();
22591
22809
  } catch (e) {
22592
22810
  logger.log("getTransportState: Exception ", e);
22593
22811
  return "unknown";
22594
22812
  }
22595
- },
22813
+ }
22596
22814
 
22597
22815
  getRegistrationState() {
22598
22816
  logger.log("webrtcSIPPhone: getRegistrationState entry");
22599
22817
  try {
22600
- return _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].getRegistrationState();
22818
+ return this.phone.getRegistrationState();
22601
22819
  } catch (e) {
22602
22820
  logger.log("getTransportState: Exception ", e);
22603
22821
  return "unknown";
22604
22822
  }
22605
- },
22823
+ }
22824
+
22825
+ changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange = false) {
22826
+ logger.log("webrtcSIPPhone: changeAudioInputDevice : ", deviceId, onSuccess, onError, "forceDeviceChange = ", forceDeviceChange);
22827
+ this.phone.changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange);
22828
+ }
22606
22829
 
22607
- changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange=false) {
22608
- logger.log("webrtcSIPPhone: changeAudioInputDevice : ", deviceId, onSuccess, onError);
22609
- _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange);
22610
- },
22830
+ changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange = false) {
22831
+ logger.log("webrtcSIPPhone: changeAudioOutputDevice : ", deviceId, onSuccess, onError, "forceDeviceChange = ", forceDeviceChange);
22832
+ this.phone.changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange);
22833
+ }
22611
22834
 
22612
- changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange=false) {
22613
- logger.log("webrtcSIPPhone: changeAudioOutputDevice : ", deviceId, onSuccess, onError);
22614
- _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange);
22615
- },
22616
22835
  setPreferredCodec(codecName) {
22617
22836
  logger.log("webrtcSIPPhone: setPreferredCodec : ", codecName);
22618
- _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].setPreferredCodec(codecName);
22619
- },
22837
+ this.phone.setPreferredCodec(codecName);
22838
+ }
22839
+
22620
22840
  registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback) {
22621
22841
  logger.log("webrtcSIPPhone: registerAudioDeviceChangeCallback entry");
22622
- _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback);
22623
- },
22624
- getLogger() {
22625
- return _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__["default"];
22842
+ this.phone.registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback);
22626
22843
  }
22844
+ }
22627
22845
 
22628
- };
22629
-
22630
-
22631
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (webrtcSIPPhone);
22632
-
22846
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (WebrtcSIPPhone);
22633
22847
 
22634
22848
  /***/ }),
22635
22849
 
@@ -22644,183 +22858,257 @@ __webpack_require__.r(__webpack_exports__);
22644
22858
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
22645
22859
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
22646
22860
  /* harmony export */ });
22647
- /*
22648
- * delegate listener , webrtc sip phone could invoke events to delegate and it will further send event to registered delegator
22649
- */
22650
- let testingMode = false;
22651
- let delegate = null;
22861
+ /* harmony import */ var _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./coreSDKLogger */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/src/coreSDKLogger.js");
22652
22862
 
22653
22863
 
22654
- const webrtcSIPPhoneEventDelegate = {
22655
-
22656
- registerDelegate : (webrtcDelegate) => {
22657
- delegate = webrtcDelegate;
22658
- },
22864
+ const logger = _coreSDKLogger__WEBPACK_IMPORTED_MODULE_0__["default"];
22659
22865
 
22660
- setTestingMode : (mode) => {
22661
- if(delegate) {
22662
- delegate.setTestingMode(mode);
22663
- }
22664
- },
22665
-
22666
- onCallStatSipJsSessionEvent : (ev) => {
22667
- if(delegate) {
22668
- delegate.onCallStatSipJsSessionEvent(ev);
22669
- }
22670
- },
22671
-
22672
- sendWebRTCEventsToFSM : (eventType, sipMethod) => {
22673
- if(delegate) {
22674
- delegate.sendWebRTCEventsToFSM(eventType, sipMethod);
22675
- }
22676
- },
22677
-
22678
- playBeepTone : () => {
22679
- if(delegate) {
22680
- delegate.playBeepTone();
22681
- }
22682
- },
22683
-
22684
- onStatPeerConnectionIceGatheringStateChange: (iceGatheringState) => {
22685
- if(delegate) {
22686
- delegate.onStatPeerConnectionIceGatheringStateChange(iceGatheringState);
22687
- }
22688
- },
22689
-
22690
- onCallStatIceCandidate: (ev, icestate) => {
22691
- if(delegate) {
22692
- delegate.onCallStatIceCandidate(ev,icestate);
22693
- }
22694
- },
22695
-
22696
-
22697
- onCallStatNegoNeeded: (icestate) => {
22698
- if(delegate) {
22699
- delegate.onCallStatNegoNeeded(icestate);
22700
- }
22701
- },
22866
+ class WebrtcSIPPhoneEventDelegate {
22702
22867
 
22703
- onCallStatSignalingStateChange: (cstate) => {
22704
- if(delegate) {
22705
- delegate.onCallStatSignalingStateChange(cstate);
22706
- }
22707
- },
22868
+ constructor(username) {
22869
+ this.username = username;
22870
+ this._listeners = new Map();
22871
+ this.delegates = new Set();
22872
+ }
22708
22873
 
22709
-
22710
- onStatPeerConnectionIceConnectionStateChange: (iceConnectionState) => {
22711
- if(delegate) {
22712
- delegate.onStatPeerConnectionIceConnectionStateChange(iceConnectionState);
22713
- }
22714
- },
22715
-
22716
-
22717
- onStatPeerConnectionConnectionStateChange: () => {
22718
- if(delegate) {
22719
- delegate.onStatPeerConnectionConnectionStateChange();
22720
- }
22721
- },
22722
-
22723
- onGetUserMediaSuccessCallstatCallback: () => {
22724
- if(delegate) {
22725
- delegate.onGetUserMediaSuccessCallstatCallback();
22726
- }
22727
- },
22874
+ /**
22875
+ * @param {string} event
22876
+ * @param {Function} handler
22877
+ * @returns {Function}
22878
+ */
22728
22879
 
22729
- onGetUserMediaErrorCallstatCallback: () => {
22730
- if(delegate) {
22731
- delegate.onGetUserMediaErrorCallstatCallback();
22732
- }
22733
- },
22734
-
22735
-
22736
- onCallStatAddStream: () => {
22737
- if(delegate) {
22738
- delegate.onCallStatAddStream();
22880
+ attach(event, handler) {
22881
+ if (!this._listeners.has(event)) {
22882
+ this._listeners.set(event, new Set());
22739
22883
  }
22740
- },
22884
+ this._listeners.get(event).add(handler);
22741
22885
 
22742
- onCallStatRemoveStream: () => {
22743
- if(delegate) {
22744
- delegate.onCallStatRemoveStream();
22745
- }
22746
- },
22747
-
22748
- setWebRTCFSMMapper : () => {
22749
- if(delegate) {
22750
- delegate.setWebRTCFSMMapper();
22751
- }
22752
- },
22753
-
22754
- onCallStatSipJsTransportEvent : () => {
22755
- if(delegate) {
22756
- delegate.onCallStatSipJsTransportEvent();
22757
- }
22758
- },
22759
-
22760
- onCallStatSipSendCallback: (tsipData, sipStack) => {
22761
- if(delegate) {
22762
- delegate.onCallStatSipSendCallback();
22763
- }
22764
- },
22886
+ return () => this._listeners.get(event)?.delete(handler);
22887
+ }
22765
22888
 
22766
- onCallStatSipRecvCallback: (tsipData, sipStack) => {
22767
- if(delegate) {
22768
- delegate.onCallStatSipRecvCallback();
22769
- }
22770
- },
22889
+ emit(event, ...args) {
22890
+ this._listeners.get(event)?.forEach((h) => {
22891
+ try {
22892
+ h(...args);
22893
+ } catch (e) {
22894
+ console.error(`[Delegate:${this.username}]`, e);
22895
+ }
22896
+ });
22897
+ }
22771
22898
 
22772
- stopCallStat: () => {
22773
- if(delegate) {
22774
- delegate.stopCallStat();
22775
- }
22776
- },
22777
-
22778
- onRecieveInvite: (incomingSession) => {
22779
- if(delegate) {
22780
- delegate.onRecieveInvite(incomingSession);
22781
- }
22782
- },
22783
-
22784
- onPickCall: () => {
22785
- if(delegate) {
22786
- delegate.onPickCall();
22787
- }
22788
- },
22899
+ registerDelegate(webrtcDelegate) {
22900
+ this.delegates.add(webrtcDelegate);
22901
+ }
22789
22902
 
22790
- onRejectCall : () => {
22791
- if(delegate) {
22792
- delegate.onRejectCall();
22793
- }
22794
- },
22795
-
22796
- onCreaterAnswer: () => {
22797
- if(delegate) {
22798
- delegate.onCreaterAnswer();
22799
- }
22800
- },
22903
+ unregisterDelegate(webrtcDelegate) {
22904
+ this.delegates.delete(webrtcDelegate);
22905
+ }
22801
22906
 
22802
- onSettingLocalDesc: () => {
22803
- if(delegate) {
22804
- delegate.onSettingLocalDesc();
22805
- }
22806
- },
22907
+ setTestingMode(mode) {
22908
+ this.delegates.forEach(delegate => {
22909
+ if (delegate && typeof delegate.setTestingMode === 'function') {
22910
+ delegate.setTestingMode(mode);
22911
+ }
22912
+ });
22913
+ }
22807
22914
 
22808
- initGetStats: (pc, callid, username) => {
22809
- if(delegate) {
22810
- delegate.initGetStats(pc, callid, username);
22811
- }
22812
- },
22813
-
22814
- onRegisterWebRTCSIPEngine : (engine) => {
22815
- if(delegate) {
22816
- delegate.onRegisterWebRTCSIPEngine(engine);
22817
- }
22915
+ onCallStatSipJsSessionEvent(ev) {
22916
+ this.delegates.forEach(delegate => {
22917
+ if (delegate && typeof delegate.onCallStatSipJsSessionEvent === 'function') {
22918
+ delegate.onCallStatSipJsSessionEvent(ev);
22919
+ }
22920
+ });
22921
+ }
22922
+
22923
+ sendWebRTCEventsToFSM(eventType, sipMethod) {
22924
+ logger.log("delegationHandler: sendWebRTCEventsToFSM");
22925
+ logger.log("delegationHandler: eventType", [eventType]);
22926
+ logger.log("delegationHandler: sipMethod", [sipMethod]);
22927
+ this.delegates.forEach(delegate => {
22928
+ if (delegate && typeof delegate.sendWebRTCEventsToFSM === 'function') {
22929
+ delegate.sendWebRTCEventsToFSM(eventType, sipMethod);
22930
+ }
22931
+ });
22932
+ }
22933
+
22934
+ playBeepTone() {
22935
+ this.delegates.forEach(delegate => {
22936
+ if (delegate && typeof delegate.playBeepTone === 'function') {
22937
+ delegate.playBeepTone();
22938
+ }
22939
+ });
22940
+ }
22941
+
22942
+ onStatPeerConnectionIceGatheringStateChange(iceGatheringState) {
22943
+ this.delegates.forEach(delegate => {
22944
+ if (delegate && typeof delegate.onStatPeerConnectionIceGatheringStateChange === 'function') {
22945
+ delegate.onStatPeerConnectionIceGatheringStateChange(iceGatheringState);
22946
+ }
22947
+ });
22948
+ }
22949
+
22950
+ onCallStatIceCandidate(ev, icestate) {
22951
+ this.delegates.forEach(delegate => {
22952
+ if (delegate && typeof delegate.onCallStatIceCandidate === 'function') {
22953
+ delegate.onCallStatIceCandidate(ev, icestate);
22954
+ }
22955
+ });
22956
+ }
22957
+
22958
+ onCallStatNegoNeeded(icestate) {
22959
+ this.delegates.forEach(delegate => {
22960
+ if (delegate && typeof delegate.onCallStatNegoNeeded === 'function') {
22961
+ delegate.onCallStatNegoNeeded(icestate);
22962
+ }
22963
+ });
22964
+ }
22965
+
22966
+ onCallStatSignalingStateChange(cstate) {
22967
+ this.delegates.forEach(delegate => {
22968
+ if (delegate && typeof delegate.onCallStatSignalingStateChange === 'function') {
22969
+ delegate.onCallStatSignalingStateChange(cstate);
22970
+ }
22971
+ });
22972
+ }
22973
+
22974
+ onStatPeerConnectionIceConnectionStateChange(iceConnectionState) {
22975
+ this.delegates.forEach(delegate => {
22976
+ if (delegate && typeof delegate.onStatPeerConnectionIceConnectionStateChange === 'function') {
22977
+ delegate.onStatPeerConnectionIceConnectionStateChange(iceConnectionState);
22978
+ }
22979
+ });
22980
+ }
22981
+
22982
+ onStatPeerConnectionConnectionStateChange() {
22983
+ this.delegates.forEach(delegate => {
22984
+ if (delegate && typeof delegate.onStatPeerConnectionConnectionStateChange === 'function') {
22985
+ delegate.onStatPeerConnectionConnectionStateChange();
22986
+ }
22987
+ });
22988
+ }
22989
+
22990
+ onGetUserMediaSuccessCallstatCallback() {
22991
+ this.delegates.forEach(delegate => {
22992
+ if (delegate && typeof delegate.onGetUserMediaSuccessCallstatCallback === 'function') {
22993
+ delegate.onGetUserMediaSuccessCallstatCallback();
22994
+ }
22995
+ });
22996
+ }
22997
+
22998
+ onGetUserMediaErrorCallstatCallback() {
22999
+ this.delegates.forEach(delegate => {
23000
+ if (delegate && typeof delegate.onGetUserMediaErrorCallstatCallback === 'function') {
23001
+ delegate.onGetUserMediaErrorCallstatCallback();
23002
+ }
23003
+ });
23004
+ }
23005
+
23006
+ onCallStatAddStream() {
23007
+ this.delegates.forEach(delegate => {
23008
+ if (delegate && typeof delegate.onCallStatAddStream === 'function') {
23009
+ delegate.onCallStatAddStream();
23010
+ }
23011
+ });
23012
+ }
23013
+
23014
+ onCallStatRemoveStream() {
23015
+ this.delegates.forEach(delegate => {
23016
+ if (delegate && typeof delegate.onCallStatRemoveStream === 'function') {
23017
+ delegate.onCallStatRemoveStream();
23018
+ }
23019
+ });
23020
+ }
23021
+
23022
+ setWebRTCFSMMapper(stack) {
23023
+ logger.log("webrtcSIPPhoneEventDelegate: setWebRTCFSMMapper: Initialisation complete");
23024
+ }
23025
+
23026
+ onCallStatSipJsTransportEvent(ev) {
23027
+ this.delegates.forEach(delegate => {
23028
+ if (delegate && typeof delegate.onCallStatSipJsTransportEvent === 'function') {
23029
+ delegate.onCallStatSipJsTransportEvent(ev);
23030
+ }
23031
+ });
23032
+ }
23033
+
23034
+ onCallStatSipSendCallback(tsipData, sipStack) {
23035
+ this.delegates.forEach(delegate => {
23036
+ if (delegate && typeof delegate.onCallStatSipSendCallback === 'function') {
23037
+ delegate.onCallStatSipSendCallback(tsipData, sipStack);
23038
+ }
23039
+ });
23040
+ }
23041
+
23042
+ onCallStatSipRecvCallback(tsipData, sipStack) {
23043
+ this.delegates.forEach(delegate => {
23044
+ if (delegate && typeof delegate.onCallStatSipRecvCallback === 'function') {
23045
+ delegate.onCallStatSipRecvCallback(tsipData, sipStack);
23046
+ }
23047
+ });
23048
+ }
23049
+
23050
+ stopCallStat() {
23051
+ this.delegates.forEach(delegate => {
23052
+ if (delegate && typeof delegate.stopCallStat === 'function') {
23053
+ delegate.stopCallStat();
23054
+ }
23055
+ });
23056
+ }
23057
+
23058
+ onRecieveInvite(incomingSession) {
23059
+ this.delegates.forEach(delegate => {
23060
+ if (delegate && typeof delegate.onRecieveInvite === 'function') {
23061
+ delegate.onRecieveInvite(incomingSession);
23062
+ }
23063
+ });
23064
+ }
23065
+
23066
+ onPickCall() {
23067
+ this.delegates.forEach(delegate => {
23068
+ if (delegate && typeof delegate.onPickCall === 'function') {
23069
+ delegate.onPickCall();
23070
+ }
23071
+ });
23072
+ }
23073
+
23074
+ onRejectCall() {
23075
+ this.delegates.forEach(delegate => {
23076
+ if (delegate && typeof delegate.onRejectCall === 'function') {
23077
+ delegate.onRejectCall();
23078
+ }
23079
+ });
23080
+ }
23081
+
23082
+ onCreaterAnswer() {
23083
+ this.delegates.forEach(delegate => {
23084
+ if (delegate && typeof delegate.onCreaterAnswer === 'function') {
23085
+ delegate.onCreaterAnswer();
23086
+ }
23087
+ });
23088
+ }
23089
+
23090
+ onSettingLocalDesc() {
23091
+ this.delegates.forEach(delegate => {
23092
+ if (delegate && typeof delegate.onSettingLocalDesc === 'function') {
23093
+ delegate.onSettingLocalDesc();
23094
+ }
23095
+ });
23096
+ }
23097
+
23098
+ initGetStats(pc, callid, username) {
23099
+ this.delegates.forEach(delegate => {
23100
+ if (delegate && typeof delegate.initGetStats === 'function') {
23101
+ delegate.initGetStats(pc, callid, username);
23102
+ }
23103
+ });
23104
+ }
23105
+
23106
+ onRegisterWebRTCSIPEngine(engine) {
23107
+ this.emit("engine-selected", engine);
22818
23108
  }
22819
-
22820
-
22821
23109
  }
22822
23110
 
22823
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (webrtcSIPPhoneEventDelegate);
23111
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (WebrtcSIPPhoneEventDelegate);
22824
23112
 
22825
23113
  /***/ }),
22826
23114
 
@@ -23069,51 +23357,54 @@ __webpack_require__.r(__webpack_exports__);
23069
23357
  /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
23070
23358
 
23071
23359
 
23072
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getLogger();
23073
- function Call() {
23360
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.getLogger)();
23361
+ function Call(webrtcSIPPhone) {
23362
+ if (!webrtcSIPPhone) {
23363
+ throw new Error("webrtcSIPPhone is required for Call");
23364
+ }
23074
23365
  this.Answer = function () {
23075
23366
  /**
23076
23367
  * When agent accepts phone, add appropriate msg to be sent to webclient
23077
23368
  */
23078
23369
  logger.log('Call answered');
23079
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.pickCall();
23370
+ webrtcSIPPhone.pickCall();
23080
23371
  };
23081
23372
  this.Hangup = function () {
23082
23373
  /**
23083
23374
  * When call is terminated
23084
23375
  */
23085
23376
  logger.log('call ended');
23086
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.rejectCall();
23377
+ webrtcSIPPhone.rejectCall();
23087
23378
  };
23088
23379
  this.MuteToggle = function () {
23089
23380
  /**
23090
23381
  * When agent clicks on mute
23091
23382
  */
23092
23383
  logger.log('Call: MuteToggle');
23093
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.webRTCMuteUnmute();
23384
+ webrtcSIPPhone.webRTCMuteUnmute();
23094
23385
  };
23095
23386
  this.Mute = function () {
23096
23387
  /**
23097
23388
  * When agent clicks on mute
23098
23389
  */
23099
- var isMicEnabled = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getMuteStatus();
23100
- logger.log('Call: Mute: isMicEnabled: ', isMicEnabled);
23101
- if (isMicEnabled) {
23102
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.muteAction(true);
23390
+ var isMuted = webrtcSIPPhone.getMuteStatus();
23391
+ logger.log('Call: Mute: isMuted: ', isMuted);
23392
+ if (!isMuted) {
23393
+ webrtcSIPPhone.muteAction(true);
23103
23394
  } else {
23104
- logger.log('Call: Mute: Already muted');
23395
+ logger.log('Call: Mute: Already muted');
23105
23396
  }
23106
23397
  };
23107
23398
  this.UnMute = function () {
23108
23399
  /**
23109
- * When agent clicks on mute
23400
+ * When agent clicks on unmute
23110
23401
  */
23111
- var isMicEnabled = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getMuteStatus();
23112
- logger.log('Call: UnMute: isMicEnabled: ', isMicEnabled);
23113
- if (isMicEnabled) {
23114
- logger.log('Call: Unmute: Already unmuted');
23402
+ var isMuted = webrtcSIPPhone.getMuteStatus();
23403
+ logger.log('Call: UnMute: isMuted: ', isMuted);
23404
+ if (isMuted) {
23405
+ webrtcSIPPhone.muteAction(false);
23115
23406
  } else {
23116
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.muteAction(false);
23407
+ logger.log('Call: UnMute: Already unmuted');
23117
23408
  }
23118
23409
  };
23119
23410
  this.HoldToggle = function () {
@@ -23121,7 +23412,7 @@ function Call() {
23121
23412
  * When user clicks on hold
23122
23413
  */
23123
23414
  logger.log('Hold toggle clicked');
23124
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.holdCall();
23415
+ webrtcSIPPhone.holdCall();
23125
23416
  };
23126
23417
  this.Hold = function () {
23127
23418
  /**
@@ -23129,7 +23420,7 @@ function Call() {
23129
23420
  */
23130
23421
  logger.log('hold clicked');
23131
23422
  let dummyFlag = true;
23132
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.holdCall();
23423
+ webrtcSIPPhone.holdCall();
23133
23424
  };
23134
23425
  this.UnHold = function () {
23135
23426
  /**
@@ -23137,7 +23428,7 @@ function Call() {
23137
23428
  */
23138
23429
  logger.log('unhold clicked');
23139
23430
  let dummyFlag = true;
23140
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.holdCall();
23431
+ webrtcSIPPhone.holdCall();
23141
23432
  };
23142
23433
  this.callDetails = function () {
23143
23434
  /**
@@ -23150,7 +23441,7 @@ function Call() {
23150
23441
  * sends dtmf digit as SIP info over websocket
23151
23442
  */
23152
23443
  logger.log("trying to send dtmf " + digit);
23153
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.sendDTMFWebRTC(digit);
23444
+ webrtcSIPPhone.sendDTMFWebRTC(digit);
23154
23445
  };
23155
23446
  }
23156
23447
 
@@ -23255,13 +23546,14 @@ var CallDetails = {
23255
23546
  "use strict";
23256
23547
  __webpack_require__.r(__webpack_exports__);
23257
23548
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23549
+ /* harmony export */ Diagnostics: () => (/* binding */ Diagnostics),
23258
23550
  /* harmony export */ ameyoWebRTCTroubleshooter: () => (/* binding */ ameyoWebRTCTroubleshooter)
23259
23551
  /* harmony export */ });
23260
- /* harmony import */ var _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../listeners/Callback */ "./src/listeners/Callback.js");
23261
- /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
23552
+ /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
23553
+ /* harmony import */ var _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../listeners/Callback */ "./src/listeners/Callback.js");
23262
23554
 
23263
23555
 
23264
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getLogger();
23556
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.getLogger)();
23265
23557
  var speakerNode;
23266
23558
  var micNode;
23267
23559
  var audioTrack;
@@ -23283,6 +23575,18 @@ eventMapper.sipml5.transport_error = "WS_TEST_FAIL";
23283
23575
  eventMapper.sipml5.connected_REGISTER = "USER_REG_TEST_PASS";
23284
23576
  eventMapper.sipml5.terminated_REGISTER = "USER_REG_TEST_FAIL";
23285
23577
  var candidateProcessData = {};
23578
+ class Diagnostics {
23579
+ constructor() {
23580
+ this.report = {};
23581
+ }
23582
+ setReport(key, value) {
23583
+ this.report[key] = value;
23584
+ logger.log("Diagnostics: setReport", key, value);
23585
+ }
23586
+ getReport() {
23587
+ return this.report;
23588
+ }
23589
+ }
23286
23590
  var ameyoWebRTCTroubleshooter = {
23287
23591
  js_yyyy_mm_dd_hh_mm_ss: function () {
23288
23592
  var now = new Date();
@@ -23321,7 +23625,7 @@ var ameyoWebRTCTroubleshooter = {
23321
23625
  msg = oldMsg + msg;
23322
23626
  }
23323
23627
  window.localStorage.setItem('troubleShootReport', msg);
23324
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerDiagnosticsSaveCallback('troubleShootReport', msg);
23628
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerDiagnosticsSaveCallback('troubleShootReport', msg);
23325
23629
  //}
23326
23630
  },
23327
23631
  getBrowserData: function () {
@@ -23373,29 +23677,40 @@ var ameyoWebRTCTroubleshooter = {
23373
23677
  }
23374
23678
  return browserName + "/" + version;
23375
23679
  },
23376
- stopSpeakerTesttone: function () {
23377
- speakerTestTone = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getSpeakerTestTone();
23680
+ stopSpeakerTesttone: function (webrtcSIPPhone) {
23681
+ if (!webrtcSIPPhone) {
23682
+ logger.log("stopSpeakerTesttone: webrtcSIPPhone not provided");
23683
+ return;
23684
+ }
23685
+ speakerTestTone = webrtcSIPPhone.getSpeakerTestTone();
23378
23686
  speakerTestTone.pause();
23379
23687
  },
23380
- stopSpeakerTesttoneWithSuccess: function () {
23381
- this.stopSpeakerTest();
23688
+ stopSpeakerTesttoneWithSuccess: function (webrtcSIPPhone) {
23689
+ this.stopSpeakerTest(webrtcSIPPhone);
23382
23690
  this.sendDeviceTestingEvent("SPEAKER_TEST_PASS");
23383
23691
  this.addToTrobuleshootReport("INFO", "Speaker device testing is successfull");
23384
23692
  this.addToTrobuleshootReport("INFO", "Speaker device testing is completed");
23385
23693
  },
23386
- stopSpeakerTesttoneWithFailure: function () {
23387
- this.stopSpeakerTest();
23694
+ stopSpeakerTesttoneWithFailure: function (webrtcSIPPhone) {
23695
+ this.stopSpeakerTest(webrtcSIPPhone);
23388
23696
  this.sendDeviceTestingEvent("SPEAKER_TEST_FAIL");
23389
23697
  this.addToTrobuleshootReport("INFO", "Speaker device testing is failed");
23390
23698
  this.addToTrobuleshootReport("INFO", "Speaker device testing is completed");
23391
23699
  },
23392
- startSpeakerTest: function () {
23700
+ startSpeakerTest: function (webrtcSIPPhone) {
23393
23701
  var parent = this;
23702
+ if (!webrtcSIPPhone) {
23703
+ logger.log("startSpeakerTest: webrtcSIPPhone not provided");
23704
+ return;
23705
+ }
23706
+ if (intervalID) {
23707
+ logger.log("startSpeakerTest: already running");
23708
+ return;
23709
+ }
23394
23710
  try {
23395
23711
  intervalID = setInterval(function () {
23396
23712
  try {
23397
- speakerTestTone = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getSpeakerTestTone();
23398
- /* Close last pending tracks.. */
23713
+ speakerTestTone = webrtcSIPPhone.getSpeakerTestTone();
23399
23714
  logger.log("close last track");
23400
23715
  speakerTestTone.pause();
23401
23716
  parent.closeAudioTrack();
@@ -23441,14 +23756,18 @@ var ameyoWebRTCTroubleshooter = {
23441
23756
  }
23442
23757
  //Enable this for tone loop - End
23443
23758
  },
23444
- stopSpeakerTest: function () {
23759
+ stopSpeakerTest: function (webrtcSIPPhone) {
23445
23760
  var parent = this;
23446
- speakerTestTone = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getSpeakerTestTone();
23447
- //Enable this for tone loop - Start
23761
+ if (!webrtcSIPPhone) {
23762
+ logger.log("stopSpeakerTest: webrtcSIPPhone not provided");
23763
+ return;
23764
+ }
23765
+ speakerTestTone = webrtcSIPPhone.getSpeakerTestTone();
23448
23766
  try {
23449
- clearInterval(intervalID);
23450
- intervalID = 0;
23451
- //Enable this for tone loop - End
23767
+ if (intervalID) {
23768
+ clearInterval(intervalID);
23769
+ intervalID = 0;
23770
+ }
23452
23771
  speakerTestTone.pause();
23453
23772
  parent.closeAudioTrack();
23454
23773
  parent.addToTrobuleshootReport("INFO", "Speaker device testing is stopped");
@@ -23514,10 +23833,10 @@ var ameyoWebRTCTroubleshooter = {
23514
23833
  if (deviceInfos[i].deviceId == "default") {
23515
23834
  if (deviceInfos[i].kind == "audiooutput") {
23516
23835
  var speakerName = deviceInfos[i].label;
23517
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("speakerInfo", deviceInfos[i].label, "speakerInfo");
23836
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("speakerInfo", deviceInfos[i].label, "speakerInfo");
23518
23837
  } else if (deviceInfos[i].kind == "audioinput") {
23519
23838
  var micName = deviceInfos[i].label;
23520
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("micInfo", deviceInfos[i].label, "micInfo");
23839
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("micInfo", deviceInfos[i].label, "micInfo");
23521
23840
  }
23522
23841
  }
23523
23842
  }
@@ -23561,7 +23880,7 @@ var ameyoWebRTCTroubleshooter = {
23561
23880
  }
23562
23881
  var average = values / length;
23563
23882
  //diagnosticsCallback.triggerDiagnosticsMicStatusCallback(average, "mic ok");
23564
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("mic", average, "mic ok");
23883
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("mic", average, "mic ok");
23565
23884
  if (average > 9) {
23566
23885
  //fillMicColors(Math.round(average));
23567
23886
  }
@@ -23570,7 +23889,7 @@ var ameyoWebRTCTroubleshooter = {
23570
23889
  logger.log("Media source not available for mic test ..");
23571
23890
  average = 0;
23572
23891
  //diagnosticsCallback.triggerDiagnosticsMicStatusCallback(average, "mic error");
23573
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("mic", average, "mic error");
23892
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("mic", average, "mic error");
23574
23893
  }
23575
23894
  },
23576
23895
  fillStreamSpeaker: function (stream, outDevice) {
@@ -23593,21 +23912,20 @@ var ameyoWebRTCTroubleshooter = {
23593
23912
  values += array[i];
23594
23913
  }
23595
23914
  var average = values / length;
23596
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("speaker", average, "speaker ok");
23915
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("speaker", average, "speaker ok");
23597
23916
  };
23598
23917
  } catch (e) {
23599
23918
  logger.log("Media source not available for speaker test ..");
23600
23919
  average = 0;
23601
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("speaker", average, "speaker error");
23920
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("speaker", average, "speaker error");
23602
23921
  }
23603
23922
  },
23604
23923
  setUserRegTroubleshootData: function (txtUser) {
23605
23924
  logger.log("No explicit registration sent during testing...");
23606
23925
  },
23607
- setWSTroubleshootData: function (txtWsStatus) {
23608
- //Already done during init, no need to do again.
23609
- let txtWSSUrl = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getWSSUrl();
23610
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("wss", txtWsStatus, txtWSSUrl);
23926
+ setWSTroubleshootData: function (txtWsStatus, webrtcSIPPhone) {
23927
+ let txtWSSUrl = webrtcSIPPhone && webrtcSIPPhone.getWSSUrl ? webrtcSIPPhone.getWSSUrl() : '';
23928
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback("wss", txtWsStatus, txtWSSUrl);
23611
23929
  },
23612
23930
  startWSAndUserRegistrationTest: function () {
23613
23931
  try {
@@ -23638,7 +23956,7 @@ var ameyoWebRTCTroubleshooter = {
23638
23956
  },
23639
23957
  setTroubleshootCandidateData: function (key, status, value) {
23640
23958
  logger.log("Candidate Data \n\t key = " + key + " status = " + status + "\n\tValue = " + value + "\n\n");
23641
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback(key, status, value);
23959
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.triggerKeyValueSetCallback(key, status, value);
23642
23960
  },
23643
23961
  startCandidatesForTroubleshoot: function () {
23644
23962
  var keys = ["udp", "tcp", "ipv6", "host", "srflx"];
@@ -23785,6 +24103,7 @@ var ameyoWebRTCTroubleshooter = {
23785
24103
  "use strict";
23786
24104
  __webpack_require__.r(__webpack_exports__);
23787
24105
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
24106
+ /* harmony export */ DiagnosticsListener: () => (/* binding */ DiagnosticsListener),
23788
24107
  /* harmony export */ closeDiagnostics: () => (/* binding */ closeDiagnostics),
23789
24108
  /* harmony export */ initDiagnostics: () => (/* binding */ initDiagnostics),
23790
24109
  /* harmony export */ startMicDiagnosticsTest: () => (/* binding */ startMicDiagnosticsTest),
@@ -23794,49 +24113,49 @@ __webpack_require__.r(__webpack_exports__);
23794
24113
  /* harmony export */ stopNetworkDiagnostics: () => (/* binding */ stopNetworkDiagnostics),
23795
24114
  /* harmony export */ stopSpeakerDiagnosticsTest: () => (/* binding */ stopSpeakerDiagnosticsTest)
23796
24115
  /* harmony export */ });
23797
- /* harmony import */ var _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../listeners/Callback */ "./src/listeners/Callback.js");
23798
- /* harmony import */ var _Diagnostics__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Diagnostics */ "./src/api/omAPI/Diagnostics.js");
23799
- /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24116
+ /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24117
+ /* harmony import */ var _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../listeners/Callback */ "./src/listeners/Callback.js");
24118
+ /* harmony import */ var _Diagnostics__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Diagnostics */ "./src/api/omAPI/Diagnostics.js");
23800
24119
 
23801
24120
 
23802
24121
 
23803
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_2__.webrtcSIPPhone.getLogger();
24122
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.getLogger)();
23804
24123
  function initDiagnostics(setDiagnosticsReportCallback, keyValueSetCallback) {
23805
24124
  if (!keyValueSetCallback || !setDiagnosticsReportCallback) {
23806
24125
  logger.log("Callbacks are not set");
23807
24126
  return;
23808
24127
  }
23809
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.setKeyValueCallback(keyValueSetCallback);
23810
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.setDiagnosticsReportCallback(setDiagnosticsReportCallback);
23811
- let version = _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.getBrowserData();
23812
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.keyValueSetCallback('browserVersion', 'ready', version);
24128
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.setKeyValueCallback(keyValueSetCallback);
24129
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.setDiagnosticsReportCallback(setDiagnosticsReportCallback);
24130
+ let version = _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.getBrowserData();
24131
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.keyValueSetCallback('browserVersion', 'ready', version);
23813
24132
  return;
23814
24133
  }
23815
24134
  function closeDiagnostics() {
23816
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.setKeyValueCallback(null);
23817
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.setDiagnosticsReportCallback(null);
24135
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.setKeyValueCallback(null);
24136
+ _listeners_Callback__WEBPACK_IMPORTED_MODULE_1__.diagnosticsCallback.setDiagnosticsReportCallback(null);
23818
24137
  return;
23819
24138
  }
23820
- function startSpeakerDiagnosticsTest() {
24139
+ function startSpeakerDiagnosticsTest(webrtcSIPPhone) {
23821
24140
  /**
23822
24141
  * When user registers the agent phone for the first time, register your callback onto webrtc client
23823
24142
  */
23824
24143
  logger.log("Request to startSpeakerTest:\n");
23825
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.startSpeakerTest();
24144
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.startSpeakerTest(webrtcSIPPhone);
23826
24145
  return;
23827
24146
  }
23828
- function stopSpeakerDiagnosticsTest(speakerTestResponse) {
24147
+ function stopSpeakerDiagnosticsTest(speakerTestResponse, webrtcSIPPhone) {
23829
24148
  /**
23830
24149
  * When user registers the agent phone for the first time, register your callback onto webrtc client
23831
24150
  */
23832
24151
 
23833
24152
  logger.log("Request to stopSpeakerTest - Suuccessful Test:\n");
23834
24153
  if (speakerTestResponse == 'yes') {
23835
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.stopSpeakerTesttoneWithSuccess();
24154
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.stopSpeakerTesttoneWithSuccess(webrtcSIPPhone);
23836
24155
  } else if (speakerTestResponse == 'no') {
23837
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.stopSpeakerTesttoneWithFailure();
24156
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.stopSpeakerTesttoneWithFailure(webrtcSIPPhone);
23838
24157
  } else {
23839
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.stopSpeakerTest();
24158
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.stopSpeakerTest(webrtcSIPPhone);
23840
24159
  }
23841
24160
  return;
23842
24161
  }
@@ -23845,7 +24164,7 @@ function startMicDiagnosticsTest() {
23845
24164
  * When user registers the agent phone for the first time, register your callback onto webrtc client
23846
24165
  */
23847
24166
  logger.log("Request to startMicTest:\n");
23848
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.startMicTest();
24167
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.startMicTest();
23849
24168
  return;
23850
24169
  }
23851
24170
  function stopMicDiagnosticsTest(micTestResponse) {
@@ -23854,11 +24173,11 @@ function stopMicDiagnosticsTest(micTestResponse) {
23854
24173
  */
23855
24174
  logger.log("Request to stopMicTest - Successful Test:\n");
23856
24175
  if (micTestResponse == 'yes') {
23857
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.stopMicTestSuccess();
24176
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.stopMicTestSuccess();
23858
24177
  } else if (micTestResponse == 'no') {
23859
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.stopMicTestFailure();
24178
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.stopMicTestFailure();
23860
24179
  } else {
23861
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.stopMicTest();
24180
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.stopMicTest();
23862
24181
  }
23863
24182
  return;
23864
24183
  }
@@ -23871,7 +24190,7 @@ function startNetworkDiagnostics() {
23871
24190
  * When user registers the agent phone for the first time, register your callback onto webrtc client
23872
24191
  */
23873
24192
  logger.log("Request to start network diagnostics:\n");
23874
- _Diagnostics__WEBPACK_IMPORTED_MODULE_1__.ameyoWebRTCTroubleshooter.startWSAndUserRegistrationTest();
24193
+ _Diagnostics__WEBPACK_IMPORTED_MODULE_2__.ameyoWebRTCTroubleshooter.startWSAndUserRegistrationTest();
23875
24194
  return;
23876
24195
  }
23877
24196
 
@@ -23885,6 +24204,15 @@ function stopNetworkDiagnostics() {
23885
24204
  logger.log("Request to stop network diagnostics:\n");
23886
24205
  return;
23887
24206
  }
24207
+ class DiagnosticsListener {
24208
+ constructor(diagnosticsCallback) {
24209
+ this.diagnosticsCallback = diagnosticsCallback;
24210
+ }
24211
+ onDiagnosticsEvent(event) {
24212
+ logger.log("DiagnosticsListener: onDiagnosticsEvent", event);
24213
+ this.diagnosticsCallback.triggerCallback(event);
24214
+ }
24215
+ }
23888
24216
 
23889
24217
  /***/ }),
23890
24218
 
@@ -23902,7 +24230,7 @@ __webpack_require__.r(__webpack_exports__);
23902
24230
  /* harmony export */ });
23903
24231
  /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
23904
24232
 
23905
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.webrtcSIPPhone.getLogger();
24233
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.getLogger)();
23906
24234
 
23907
24235
  /**
23908
24236
  * Function to register the phone onto a webRTC client
@@ -23935,42 +24263,16 @@ function DoRegister(sipAccountInfo, exWebClient, delay = 500) {
23935
24263
  }
23936
24264
 
23937
24265
  /**
23938
- * Function to UnRegister the phone from a webRTC client
23939
- * @param {*} sipAccountInfo
23940
- * @param {*} exWebClient
23941
- */
23942
- function UnRegister(sipAccountInfo, exWebClient) {
23943
- try {
23944
- exWebClient.unregister(sipAccountInfo);
23945
- } catch (e) {
23946
- logger.log("Unregister failed ", e);
23947
- }
23948
- }
23949
-
23950
- /***/ }),
23951
-
23952
- /***/ "./src/constants/common.js":
23953
- /*!*********************************!*\
23954
- !*** ./src/constants/common.js ***!
23955
- \*********************************/
23956
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
23957
-
23958
- "use strict";
23959
- __webpack_require__.r(__webpack_exports__);
23960
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23961
- /* harmony export */ FetchTabInfo: () => (/* binding */ FetchTabInfo)
23962
- /* harmony export */ });
23963
- /**
23964
- * Function to fetch the tab details from tabID
24266
+ * Function to UnRegister the phone from a webRTC client
24267
+ * @param {*} sipAccountInfo
24268
+ * @param {*} exWebClient
23965
24269
  */
23966
- function FetchTabInfo(tabID) {
23967
- const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
23968
- for (var x = 0; x < tabArr.length; x++) {
23969
- if (tabArr[x].tabID == tabID) {
23970
- return tabArr[x];
23971
- }
24270
+ function UnRegister(sipAccountInfo, exWebClient) {
24271
+ try {
24272
+ exWebClient.unregister(sipAccountInfo);
24273
+ } catch (e) {
24274
+ logger.log("Unregister failed ", e);
23972
24275
  }
23973
- return null;
23974
24276
  }
23975
24277
 
23976
24278
  /***/ }),
@@ -24008,43 +24310,34 @@ __webpack_require__.r(__webpack_exports__);
24008
24310
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
24009
24311
  /* harmony export */ CallListener: () => (/* binding */ CallListener)
24010
24312
  /* harmony export */ });
24011
- /* harmony import */ var _Callback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Callback */ "./src/listeners/Callback.js");
24012
- /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24013
-
24014
-
24015
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.webrtcSIPPhone.getLogger();
24016
- function CallListener() {
24017
- this.onIncomingCall = function (call, phone) {
24018
- /**
24019
- * When there is an incoming call, [INVITE is received on SIP] send a call back to the
24020
- */
24021
- logger.log("CallListener:Initialise call");
24022
- _Callback__WEBPACK_IMPORTED_MODULE_0__.callbacks.initializeCall(call, phone);
24313
+ /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24023
24314
 
24024
- /** Triggers the callback on the UI end with message indicating it to be an incoming call */
24025
- logger.log("CallListener:Trigger Incoming");
24026
- _Callback__WEBPACK_IMPORTED_MODULE_0__.callbacks.triggerCallback("incoming");
24027
- };
24028
- this.onCallEstablished = function (call, phone) {
24029
- /**
24030
- * When connection is established [ACK is sent by other party on SIP]
24031
- */
24032
- logger.log("CallListener:Initialise call");
24033
- _Callback__WEBPACK_IMPORTED_MODULE_0__.callbacks.initializeCall(call, phone);
24034
- /** Triggers the callback on the UI end with message indicating call has been established*/
24035
- logger.log("CallListener:Trigger Connected");
24036
- _Callback__WEBPACK_IMPORTED_MODULE_0__.callbacks.triggerCallback("connected");
24037
- };
24038
- this.onCallEnded = function (call, phone) {
24039
- /**
24040
- * When other party ends the call [BYE is received and sent by SIP]
24041
- */
24042
- logger.log("CallListener:Initialise call");
24043
- _Callback__WEBPACK_IMPORTED_MODULE_0__.callbacks.initializeCall(call, phone);
24044
- /** Triggers the callback on the UI end with message indicating call has ended */
24045
- logger.log("CallListener:Trigger Call Ended");
24046
- _Callback__WEBPACK_IMPORTED_MODULE_0__.callbacks.triggerCallback("callEnded");
24047
- };
24315
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.getLogger)();
24316
+ class CallListener {
24317
+ constructor(callCallback) {
24318
+ this.callCallback = callCallback;
24319
+ }
24320
+ onIncomingCall(call, phone) {
24321
+ logger.log("CallListener: onIncomingCall", call, phone);
24322
+ this.callCallback.initializeCall(call, phone);
24323
+ this.callCallback.triggerCallback("call", call, "incoming", phone);
24324
+ }
24325
+ onCallEstablished(call, phone) {
24326
+ logger.log("CallListener: onCallEstablished", call, phone);
24327
+ this.callCallback.triggerCallback("call", call, "connected", phone);
24328
+ }
24329
+ onCallEnded(call, phone) {
24330
+ logger.log("CallListener: onCallEnded", call, phone);
24331
+ this.callCallback.triggerCallback("call", call, "callEnded", phone);
24332
+ }
24333
+ onCallEvent(event) {
24334
+ logger.log("CallListener: onCallEvent", event);
24335
+ this.callCallback.triggerCallback(event);
24336
+ }
24337
+ onRinging(call, phone) {
24338
+ logger.log("CallListener: onRinging", call, phone);
24339
+ this.callCallback.triggerCallback("call", call, "ringing", phone);
24340
+ }
24048
24341
  }
24049
24342
 
24050
24343
  /***/ }),
@@ -24058,17 +24351,17 @@ function CallListener() {
24058
24351
  "use strict";
24059
24352
  __webpack_require__.r(__webpack_exports__);
24060
24353
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
24061
- /* harmony export */ callbacks: () => (/* binding */ callbacks),
24354
+ /* harmony export */ Callback: () => (/* binding */ Callback),
24355
+ /* harmony export */ RegisterCallback: () => (/* binding */ RegisterCallback),
24356
+ /* harmony export */ SessionCallback: () => (/* binding */ SessionCallback),
24062
24357
  /* harmony export */ diagnosticsCallback: () => (/* binding */ diagnosticsCallback),
24063
24358
  /* harmony export */ phoneInstance: () => (/* binding */ phoneInstance),
24064
- /* harmony export */ registerCallback: () => (/* binding */ registerCallback),
24065
- /* harmony export */ sessionCallback: () => (/* binding */ sessionCallback),
24066
24359
  /* harmony export */ timerSession: () => (/* binding */ timerSession),
24067
24360
  /* harmony export */ webrtcTroubleshooterEventBus: () => (/* binding */ webrtcTroubleshooterEventBus)
24068
24361
  /* harmony export */ });
24069
24362
  /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24070
24363
 
24071
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.webrtcSIPPhone.getLogger();
24364
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.getLogger)();
24072
24365
 
24073
24366
  /**
24074
24367
  * The call backs are called through this function. First initiates the call object and then
@@ -24078,43 +24371,49 @@ var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_0__.webrtc
24078
24371
  /**
24079
24372
  * Initializes call event callbacks and also sends to which phone callback was received
24080
24373
  */
24081
- var callbacks = {
24082
- callback: null,
24083
- call: null,
24084
- phone: '',
24085
- initializeCallback: function (CallListenerCallback) {
24086
- this.callback = CallListenerCallback;
24087
- },
24088
- initializeCall: function (call, phone) {
24374
+ class Callback {
24375
+ constructor() {
24376
+ this.callbacks = {};
24377
+ this.call = null;
24378
+ this.phone = '';
24379
+ }
24380
+ registerCallback(event, callback) {
24381
+ this.callbacks[event] = callback;
24382
+ }
24383
+ initializeCall(call, phone) {
24089
24384
  this.call = call;
24090
24385
  this.phone = phone;
24091
- },
24092
- triggerCallback: function (eventType) {
24093
- const callbackFunc = this.callback;
24094
- const call = this.call;
24095
- return callbackFunc(call, eventType, this.phone);
24096
24386
  }
24097
- };
24387
+ triggerCallback(event, ...args) {
24388
+ if (this.callbacks[event]) {
24389
+ this.callbacks[event](...args);
24390
+ } else {
24391
+ logger.log("No callback registered for event:", event);
24392
+ }
24393
+ }
24394
+ }
24395
+
24098
24396
  /**
24099
24397
  * Initializes register callback and also sets to which phone registration was renewed
24100
24398
  */
24101
- var registerCallback = {
24102
- registerCallbackHandler: null,
24103
- registerState: null,
24104
- phone: '',
24105
- initializeRegisterCallback: function (RegisterEventCallBack) {
24106
- registerCallback.registerCallbackHandler = RegisterEventCallBack;
24107
- },
24108
- initializeRegister: function (state, phone) {
24109
- registerCallback.registerState = state;
24110
- registerCallback.phone = phone;
24111
- },
24112
- triggerRegisterCallback: function () {
24113
- const callbackFunc = registerCallback.registerCallbackHandler;
24114
- const state = registerCallback.registerState;
24115
- return callbackFunc(state, registerCallback.phone);
24116
- }
24117
- };
24399
+
24400
+ class RegisterCallback {
24401
+ registerCallbackHandler = null;
24402
+ registerState = null;
24403
+ phone = '';
24404
+ initializeRegisterCallback = function (RegisterEventCallBack) {
24405
+ this.registerCallbackHandler = RegisterEventCallBack;
24406
+ };
24407
+ initializeRegister = function (state, phone) {
24408
+ this.registerState = state;
24409
+ this.phone = phone;
24410
+ };
24411
+ triggerRegisterCallback = function () {
24412
+ const callbackFunc = this.registerCallbackHandler;
24413
+ const state = this.registerState;
24414
+ return callbackFunc(state, this.phone);
24415
+ };
24416
+ }
24118
24417
  /**
24119
24418
  * Sets all the phone instances
24120
24419
  */
@@ -24147,30 +24446,30 @@ var phoneInstance = {
24147
24446
  }
24148
24447
  }
24149
24448
  };
24150
- var sessionCallback = {
24151
- sessioncallback: null,
24152
- callState: null,
24153
- document: null,
24154
- documentCallback: null,
24155
- phone: '',
24156
- initializeSessionCallback: function (SessionCallback) {
24449
+ class SessionCallback {
24450
+ sessioncallback = null;
24451
+ callState = null;
24452
+ document = null;
24453
+ documentCallback = null;
24454
+ phone = '';
24455
+ initializeSessionCallback = function (SessionCallback) {
24157
24456
  this.sessioncallback = SessionCallback;
24158
- },
24159
- intializeDocumentCallback: function (DocumentCallback) {
24457
+ };
24458
+ intializeDocumentCallback = function (DocumentCallback) {
24160
24459
  this.documentCallback = DocumentCallback;
24161
- },
24162
- initializeSession: function (state, phone) {
24460
+ };
24461
+ initializeSession = function (state, phone) {
24163
24462
  this.callState = state;
24164
24463
  this.phone = phone;
24165
- },
24166
- initializeDocument: function (calldocument) {
24464
+ };
24465
+ initializeDocument = function (calldocument) {
24167
24466
  this.document = calldocument;
24168
- },
24169
- triggerDocumentCallback: function () {
24467
+ };
24468
+ triggerDocumentCallback = function () {
24170
24469
  const documentCallbackFunc = this.documentCallback;
24171
24470
  return documentCallbackFunc(this.document);
24172
- },
24173
- triggerSessionCallback: function () {
24471
+ };
24472
+ triggerSessionCallback = function () {
24174
24473
  const sessionCallBackFunc = this.sessioncallback;
24175
24474
  if (sessionCallBackFunc) {
24176
24475
  return sessionCallBackFunc(this.callState, this.phone);
@@ -24178,8 +24477,8 @@ var sessionCallback = {
24178
24477
  logger.log("Session callback is null");
24179
24478
  return;
24180
24479
  }
24181
- }
24182
- };
24480
+ };
24481
+ }
24183
24482
  var diagnosticsCallback = {
24184
24483
  saveDiagnosticsCallback: null,
24185
24484
  keyValueSetCallback: null,
@@ -24305,9 +24604,10 @@ __webpack_require__.r(__webpack_exports__);
24305
24604
 
24306
24605
 
24307
24606
 
24607
+ const phonePool = new Map();
24308
24608
  var intervalId;
24309
24609
  var intervalIDMap = new Map();
24310
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.getLogger();
24610
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.getLogger)();
24311
24611
  function sleep(ms) {
24312
24612
  return new Promise(resolve => setTimeout(resolve, ms));
24313
24613
  }
@@ -24316,119 +24616,124 @@ function sleep(ms) {
24316
24616
  * FQDN for fetching IP
24317
24617
  */
24318
24618
  function fetchPublicIP(sipAccountInfo) {
24319
- var publicIp = "";
24320
- const pc = new RTCPeerConnection({
24321
- iceServers: [{
24322
- urls: 'stun:stun.l.google.com:19302'
24323
- }]
24324
- });
24325
- pc.createDataChannel('');
24326
- pc.createOffer().then(offer => pc.setLocalDescription(offer));
24327
- pc.onicecandidate = ice => {
24328
- if (!ice || !ice.candidate || !ice.candidate.candidate) {
24329
- logger.log("all done.");
24330
- pc.close();
24331
- return "";
24332
- }
24333
- logger.log("iceCandidate =" + ice.candidate.candidate);
24334
- let split = ice.candidate.candidate.split(" ");
24335
- if (split[7] === "host") {
24336
- logger.log(`fetchPublicIP:Local IP : ${split[4]}`);
24337
- } else {
24338
- logger.log(`fetchPublicIP:External IP : ${split[4]}`);
24339
- publicIp = `${split[4]}`;
24340
- logger.log("fetchPublicIP:Public IP :" + publicIp);
24341
- localStorage.setItem("contactHost", publicIp);
24342
- pc.close();
24343
- }
24344
- };
24345
- sleep(500).then(function () {
24346
- logger.log("fetchPublicIP: public ip = ", publicIp);
24347
- if (publicIp == "") {
24348
- sipAccountInfo.contactHost = window.localStorage.getItem('contactHost');
24349
- } else {
24350
- sipAccountInfo.contactHost = publicIp;
24351
- }
24619
+ return new Promise(resolve => {
24620
+ var publicIp = "";
24621
+ const pc = new RTCPeerConnection({
24622
+ iceServers: [{
24623
+ urls: 'stun:stun.l.google.com:19302'
24624
+ }]
24625
+ });
24626
+ pc.createDataChannel('');
24627
+ pc.createOffer().then(offer => pc.setLocalDescription(offer));
24628
+ pc.onicecandidate = ice => {
24629
+ if (!ice || !ice.candidate || !ice.candidate.candidate) {
24630
+ pc.close();
24631
+ resolve();
24632
+ return;
24633
+ }
24634
+ logger.log("iceCandidate =" + ice.candidate.candidate);
24635
+ let split = ice.candidate.candidate.split(" ");
24636
+ if (split[7] === "host") {
24637
+ logger.log(`fetchPublicIP:Local IP : ${split[4]}`);
24638
+ } else {
24639
+ logger.log(`fetchPublicIP:External IP : ${split[4]}`);
24640
+ publicIp = `${split[4]}`;
24641
+ logger.log("fetchPublicIP:Public IP :" + publicIp);
24642
+ localStorage.setItem("contactHost", publicIp);
24643
+ pc.close();
24644
+ resolve();
24645
+ }
24646
+ };
24647
+ setTimeout(() => {
24648
+ logger.log("fetchPublicIP: public ip = ", publicIp);
24649
+ if (publicIp == "") {
24650
+ sipAccountInfo.contactHost = window.localStorage.getItem('contactHost');
24651
+ } else {
24652
+ sipAccountInfo.contactHost = publicIp;
24653
+ }
24654
+ resolve();
24655
+ }, 1000);
24352
24656
  });
24353
- return;
24354
24657
  }
24355
- ;
24356
- function ExDelegationHandler(exClient_) {
24357
- var exClient = exClient_;
24358
- this.setTestingMode = function (mode) {
24658
+ class ExDelegationHandler {
24659
+ constructor(exClient) {
24660
+ this.exClient = exClient;
24661
+ this.sessionCallback = exClient.sessionCallback;
24662
+ }
24663
+ setTestingMode(mode) {
24359
24664
  logger.log("delegationHandler: setTestingMode\n");
24360
- };
24361
- this.onCallStatSipJsSessionEvent = function (ev) {
24665
+ }
24666
+ onCallStatSipJsSessionEvent(ev) {
24362
24667
  logger.log("delegationHandler: onCallStatSipJsSessionEvent", ev);
24363
- };
24364
- this.sendWebRTCEventsToFSM = function (eventType, sipMethod) {
24668
+ }
24669
+ sendWebRTCEventsToFSM(eventType, sipMethod) {
24365
24670
  logger.log("delegationHandler: sendWebRTCEventsToFSM\n");
24366
24671
  logger.log("delegationHandler: eventType\n", eventType);
24367
24672
  logger.log("delegationHandler: sipMethod\n", sipMethod);
24368
24673
  if (sipMethod == "CONNECTION") {
24369
- exClient.registerEventCallback(eventType, exClient.userName);
24674
+ this.exClient.registerEventCallback(eventType, this.exClient.userName);
24370
24675
  } else if (sipMethod == "CALL") {
24371
- exClient.callEventCallback(eventType, exClient.callFromNumber, exClient.call);
24676
+ this.exClient.callEventCallback(eventType, this.exClient.callFromNumber, this.exClient.call);
24372
24677
  }
24373
- };
24374
- this.playBeepTone = function () {
24678
+ }
24679
+ playBeepTone() {
24375
24680
  logger.log("delegationHandler: playBeepTone\n");
24376
- };
24377
- this.onStatPeerConnectionIceGatheringStateChange = function (iceGatheringState) {
24681
+ }
24682
+ onStatPeerConnectionIceGatheringStateChange(iceGatheringState) {
24378
24683
  logger.log("delegationHandler: onStatPeerConnectionIceGatheringStateChange\n");
24379
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.initializeSession(`ice_gathering_state_${iceGatheringState}`, exClient.callFromNumber);
24380
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.triggerSessionCallback();
24381
- };
24382
- this.onCallStatIceCandidate = function (ev, icestate) {
24684
+ this.sessionCallback.initializeSession(`ice_gathering_state_${iceGatheringState}`, this.exClient.callFromNumber);
24685
+ this.sessionCallback.triggerSessionCallback();
24686
+ }
24687
+ onCallStatIceCandidate(ev, icestate) {
24383
24688
  logger.log("delegationHandler: onCallStatIceCandidate\n");
24384
- };
24385
- this.onCallStatNegoNeeded = function (icestate) {
24689
+ }
24690
+ onCallStatNegoNeeded(icestate) {
24386
24691
  logger.log("delegationHandler: onCallStatNegoNeeded\n");
24387
- };
24388
- this.onCallStatSignalingStateChange = function (cstate) {
24692
+ }
24693
+ onCallStatSignalingStateChange(cstate) {
24389
24694
  logger.log("delegationHandler: onCallStatSignalingStateChange\n");
24390
- };
24391
- this.onStatPeerConnectionIceConnectionStateChange = function (iceConnectionState) {
24695
+ }
24696
+ onStatPeerConnectionIceConnectionStateChange(iceConnectionState) {
24392
24697
  logger.log("delegationHandler: onStatPeerConnectionIceConnectionStateChange\n");
24393
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.initializeSession(`ice_connection_state_${iceConnectionState}`, exClient.callFromNumber);
24394
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.triggerSessionCallback();
24395
- };
24396
- this.onStatPeerConnectionConnectionStateChange = function () {
24698
+ this.sessionCallback.initializeSession(`ice_connection_state_${iceConnectionState}`, this.exClient.callFromNumber);
24699
+ this.sessionCallback.triggerSessionCallback();
24700
+ }
24701
+ onStatPeerConnectionConnectionStateChange() {
24397
24702
  logger.log("delegationHandler: onStatPeerConnectionConnectionStateChange\n");
24398
- };
24399
- this.onGetUserMediaSuccessCallstatCallback = function () {
24703
+ }
24704
+ onGetUserMediaSuccessCallstatCallback() {
24400
24705
  logger.log("delegationHandler: onGetUserMediaSuccessCallstatCallback\n");
24401
- };
24402
- this.onGetUserMediaErrorCallstatCallback = function () {
24706
+ }
24707
+ onGetUserMediaErrorCallstatCallback() {
24403
24708
  logger.log("delegationHandler: onGetUserMediaErrorCallstatCallback\n");
24404
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.initializeSession(`media_permission_denied`, exClient.callFromNumber);
24405
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.triggerSessionCallback();
24406
- };
24407
- this.onCallStatAddStream = function () {
24709
+ this.sessionCallback.initializeSession(`media_permission_denied`, this.exClient.callFromNumber);
24710
+ this.sessionCallback.triggerSessionCallback();
24711
+ }
24712
+ onCallStatAddStream() {
24408
24713
  logger.log("delegationHandler: onCallStatAddStream\n");
24409
- };
24410
- this.onCallStatRemoveStream = function () {
24714
+ }
24715
+ onCallStatRemoveStream() {
24411
24716
  logger.log("delegationHandler: onCallStatRemoveStream\n");
24412
- };
24413
- this.setWebRTCFSMMapper = function (stack) {
24717
+ }
24718
+ setWebRTCFSMMapper(stack) {
24414
24719
  logger.log("delegationHandler: setWebRTCFSMMapper : Initialisation complete \n");
24415
- };
24416
- this.onCallStatSipJsTransportEvent = function () {
24720
+ }
24721
+ onCallStatSipJsTransportEvent() {
24417
24722
  logger.log("delegationHandler: onCallStatSipJsTransportEvent\n");
24418
- };
24419
- this.onCallStatSipSendCallback = function () {
24723
+ }
24724
+ onCallStatSipSendCallback() {
24420
24725
  logger.log("delegationHandler: onCallStatSipSendCallback\n");
24421
- };
24422
- this.onCallStatSipRecvCallback = function () {
24726
+ }
24727
+ onCallStatSipRecvCallback() {
24423
24728
  logger.log("delegationHandler: onCallStatSipRecvCallback\n");
24424
- };
24425
- this.stopCallStat = function () {
24729
+ }
24730
+ stopCallStat() {
24426
24731
  logger.log("delegationHandler: stopCallStat\n");
24427
- };
24428
- this.onRecieveInvite = function (incomingSession) {
24732
+ }
24733
+ onRecieveInvite(incomingSession) {
24429
24734
  logger.log("delegationHandler: onRecieveInvite\n");
24430
24735
  const obj = incomingSession.incomingInviteRequest.message.headers;
24431
- exClient.callFromNumber = incomingSession.incomingInviteRequest.message.from.displayName;
24736
+ this.exClient.callFromNumber = incomingSession.incomingInviteRequest.message.from.displayName;
24432
24737
  if (obj.hasOwnProperty("X-Exotel-Callsid")) {
24433
24738
  _api_callAPI_CallDetails__WEBPACK_IMPORTED_MODULE_9__.CallDetails.callSid = obj['X-Exotel-Callsid'][0].raw;
24434
24739
  }
@@ -24449,35 +24754,40 @@ function ExDelegationHandler(exClient_) {
24449
24754
  }
24450
24755
  }
24451
24756
  _api_callAPI_CallDetails__WEBPACK_IMPORTED_MODULE_9__.CallDetails.sipHeaders = result;
24452
- };
24453
- this.onPickCall = function () {
24757
+ }
24758
+ onPickCall() {
24454
24759
  logger.log("delegationHandler: onPickCall\n");
24455
- };
24456
- this.onRejectCall = function () {
24760
+ }
24761
+ onRejectCall() {
24457
24762
  logger.log("delegationHandler: onRejectCall\n");
24458
- };
24459
- this.onCreaterAnswer = function () {
24763
+ }
24764
+ onCreaterAnswer() {
24460
24765
  logger.log("delegationHandler: onCreaterAnswer\n");
24461
- };
24462
- this.onSettingLocalDesc = function () {
24766
+ }
24767
+ onSettingLocalDesc() {
24463
24768
  logger.log("delegationHandler: onSettingLocalDesc\n");
24464
- };
24465
- this.initGetStats = function (pc, callid, username) {
24769
+ }
24770
+ initGetStats(pc, callid, username) {
24466
24771
  logger.log("delegationHandler: initGetStats\n");
24467
- };
24468
- this.onRegisterWebRTCSIPEngine = function (engine) {
24772
+ }
24773
+ onRegisterWebRTCSIPEngine(engine) {
24469
24774
  logger.log("delegationHandler: onRegisterWebRTCSIPEngine, engine=\n", engine);
24470
- };
24775
+ }
24471
24776
  }
24472
- function ExSynchronousHandler() {
24473
- this.onFailure = function () {
24777
+ class ExSynchronousHandler {
24778
+ onFailure() {
24474
24779
  logger.log("synchronousHandler: onFailure, phone is offline.\n");
24475
- };
24476
- this.onResponse = function () {
24780
+ }
24781
+ onResponse() {
24477
24782
  logger.log("synchronousHandler: onResponse, phone is connected.\n");
24478
- };
24783
+ }
24479
24784
  }
24785
+
24480
24786
  class ExotelWebClient {
24787
+ /**
24788
+ * @param {Object} sipAccntInfo
24789
+ */
24790
+
24481
24791
  ctrlr = null;
24482
24792
  call;
24483
24793
  eventListener = null;
@@ -24487,35 +24797,65 @@ class ExotelWebClient {
24487
24797
  unregisterInitiated = false;
24488
24798
  registrationInProgress = false;
24489
24799
  isReadyToRegister = true;
24490
- /* OLD-Way to be revisited for multile phone support */
24491
- //this.webRTCPhones = {};
24492
-
24493
24800
  sipAccountInfo = null;
24494
24801
  clientSDKLoggerCallback = null;
24802
+ callbacks = null;
24803
+ registerCallback = null;
24804
+ sessionCallback = null;
24805
+ logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.getLogger)();
24495
24806
  constructor() {
24496
- /*
24497
- Register the logger callback and emit the onLog event
24498
- */
24499
-
24807
+ // Initialize properties
24808
+ this.ctrlr = null;
24809
+ this.call = null;
24810
+ this.eventListener = null;
24811
+ this.callListener = null;
24812
+ this.callFromNumber = null;
24813
+ this.shouldAutoRetry = false;
24814
+ this.unregisterInitiated = false;
24815
+ this.registrationInProgress = false;
24816
+ this.currentSIPUserName = "";
24817
+ this.isReadyToRegister = true;
24818
+ this.sipAccountInfo = null;
24819
+ this.clientSDKLoggerCallback = null;
24820
+ this.callbacks = new _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.Callback();
24821
+ this.registerCallback = new _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.RegisterCallback();
24822
+ this.sessionCallback = new _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.SessionCallback();
24823
+ this.logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.getLogger)();
24824
+
24825
+ // Register logger callback
24500
24826
  let exwebClientOb = this;
24501
- logger.registerLoggerCallback(function (type, message, args) {
24827
+ this.logger.registerLoggerCallback((type, message, args) => {
24502
24828
  _api_LogManager_js__WEBPACK_IMPORTED_MODULE_10__["default"].onLog(type, message, args);
24503
- if (exwebClientOb.clientSDKLoggerCallback) exwebClientOb.clientSDKLoggerCallback("log", message, args);
24829
+ if (exwebClientOb.clientSDKLoggerCallback) {
24830
+ exwebClientOb.clientSDKLoggerCallback("log", message, args);
24831
+ }
24504
24832
  });
24505
24833
  }
24506
- initWebrtc = (sipAccountInfo_, RegisterEventCallBack, CallListenerCallback, SessionCallback, enableAutoAudioDeviceChangeHandling = false) => {
24834
+ initWebrtc = async (sipAccountInfo_, RegisterEventCallBack, CallListenerCallback, SessionCallback, enableAutoAudioDeviceChangeHandling = false) => {
24835
+ const userName = sipAccountInfo_?.userName;
24836
+ if (!userName) return false;
24837
+
24838
+ // --- Duplicate registration guard ---
24839
+ if (phonePool.has(userName)) {
24840
+ if (this.currentSIPUserName == "" || this.currentSIPUserName !== userName) {
24841
+ logger.warn(`ExWebClient: initWebrtc: [Dup‑Reg] ${userName} already in use – init rejected`);
24842
+ return false;
24843
+ }
24844
+ }
24845
+ this.currentSIPUserName = userName;
24846
+ phonePool.set(userName, null);
24507
24847
  if (!this.eventListener) {
24508
- this.eventListener = new _listeners_ExotelVoiceClientListener__WEBPACK_IMPORTED_MODULE_3__.ExotelVoiceClientListener();
24848
+ this.eventListener = new _listeners_ExotelVoiceClientListener__WEBPACK_IMPORTED_MODULE_3__.ExotelVoiceClientListener(this.registerCallback);
24509
24849
  }
24510
24850
  if (!this.callListener) {
24511
- this.callListener = new _listeners_CallListener__WEBPACK_IMPORTED_MODULE_2__.CallListener();
24851
+ this.callListener = new _listeners_CallListener__WEBPACK_IMPORTED_MODULE_2__.CallListener(this.callbacks);
24852
+ }
24853
+ if (!this.sessionListener) {
24854
+ this.sessionListener = new _listeners_SessionListeners__WEBPACK_IMPORTED_MODULE_4__.SessionListener(this.sessionCallback);
24512
24855
  }
24513
24856
  if (!this.ctrlr) {
24514
24857
  this.ctrlr = new _CallCtrlerDummy__WEBPACK_IMPORTED_MODULE_5__.CallController();
24515
24858
  }
24516
- if (!this.call) {
24517
- this.call = new _api_callAPI_Call__WEBPACK_IMPORTED_MODULE_0__.Call();
24518
- }
24519
24859
  sipAccountInfo_.enableAutoAudioDeviceChangeHandling = enableAutoAudioDeviceChangeHandling;
24520
24860
  logger.log("ExWebClient: initWebrtc: Exotel Client Initialised with " + JSON.stringify(sipAccountInfo_));
24521
24861
  this.sipAccountInfo = sipAccountInfo_;
@@ -24523,11 +24863,36 @@ class ExotelWebClient {
24523
24863
  return false;
24524
24864
  }
24525
24865
  this.sipAccountInfo["sipUri"] = "wss://" + this.sipAccountInfo["userName"] + "@" + this.sipAccountInfo["sipdomain"] + ":" + this.sipAccountInfo["port"];
24526
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.callbacks.initializeCallback(CallListenerCallback);
24527
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.registerCallback.initializeRegisterCallback(RegisterEventCallBack);
24866
+
24867
+ // Register callbacks using the correct methods
24868
+ this.callbacks.registerCallback('call', CallListenerCallback);
24869
+ this.registerCallback.initializeRegisterCallback(RegisterEventCallBack);
24528
24870
  logger.log("ExWebClient: initWebrtc: Initializing session callback");
24529
- _listeners_Callback__WEBPACK_IMPORTED_MODULE_7__.sessionCallback.initializeSessionCallback(SessionCallback);
24871
+ this.sessionCallback.initializeSessionCallback(SessionCallback);
24530
24872
  this.setEventListener(this.eventListener);
24873
+
24874
+ // Wait for public IP before registering
24875
+ await fetchPublicIP(this.sipAccountInfo);
24876
+
24877
+ // Create phone instance if it wasn't created in constructor
24878
+ if (!this.phone) {
24879
+ this.userName = this.sipAccountInfo.userName;
24880
+ let phone = phonePool.get(this.userName);
24881
+ if (!phone) {
24882
+ phone = new _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.WebrtcSIPPhone(this.userName);
24883
+ phonePool.set(this.userName, phone);
24884
+ }
24885
+ this.phone = phone;
24886
+ this.webrtcSIPPhone = this.phone;
24887
+ }
24888
+
24889
+ // Initialize the phone with SIP engine
24890
+ this.webrtcSIPPhone.registerPhone("sipjs", new ExDelegationHandler(this), this.sipAccountInfo.enableAutoAudioDeviceChangeHandling);
24891
+
24892
+ // Create call instance after phone is initialized
24893
+ if (!this.call) {
24894
+ this.call = new _api_callAPI_Call__WEBPACK_IMPORTED_MODULE_0__.Call(this.webrtcSIPPhone);
24895
+ }
24531
24896
  return true;
24532
24897
  };
24533
24898
  DoRegister = () => {
@@ -24550,10 +24915,10 @@ class ExotelWebClient {
24550
24915
  (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.closeDiagnostics)();
24551
24916
  };
24552
24917
  startSpeakerDiagnosticsTest = () => {
24553
- (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.startSpeakerDiagnosticsTest)();
24918
+ (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.startSpeakerDiagnosticsTest)(this.webrtcSIPPhone);
24554
24919
  };
24555
24920
  stopSpeakerDiagnosticsTest = (speakerTestResponse = 'none') => {
24556
- (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.stopSpeakerDiagnosticsTest)(speakerTestResponse);
24921
+ (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.stopSpeakerDiagnosticsTest)(speakerTestResponse, this.webrtcSIPPhone);
24557
24922
  };
24558
24923
  startMicDiagnosticsTest = () => {
24559
24924
  (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.startMicDiagnosticsTest)();
@@ -24568,27 +24933,16 @@ class ExotelWebClient {
24568
24933
  stopNetworkDiagnostics = () => {
24569
24934
  (0,_api_omAPI_DiagnosticsListener__WEBPACK_IMPORTED_MODULE_6__.stopNetworkDiagnostics)();
24570
24935
  };
24571
- SessionListener = () => {
24572
- (0,_listeners_SessionListeners__WEBPACK_IMPORTED_MODULE_4__.SessionListener)();
24573
- };
24574
-
24575
- /**
24576
- * function that returns the instance of the call controller object object
24577
- */
24578
-
24936
+ SessionListenerMethod = () => {};
24579
24937
  getCallController = () => {
24580
24938
  return this.ctrlr;
24581
24939
  };
24582
24940
  getCall = () => {
24583
24941
  if (!this.call) {
24584
- this.call = call = new _api_callAPI_Call__WEBPACK_IMPORTED_MODULE_0__.Call();
24942
+ this.call = new _api_callAPI_Call__WEBPACK_IMPORTED_MODULE_0__.Call(this.webrtcSIPPhone);
24585
24943
  }
24586
24944
  return this.call;
24587
24945
  };
24588
-
24589
- /**
24590
- * Dummy function to set the event listener object
24591
- */
24592
24946
  setEventListener = eventListener => {
24593
24947
  this.eventListener = eventListener;
24594
24948
  };
@@ -24601,37 +24955,18 @@ class ExotelWebClient {
24601
24955
  */
24602
24956
 
24603
24957
  registerEventCallback = (event, phone, param) => {
24604
- logger.log("ExWebClient: registerEventCallback: Received ---> " + event + 'phone....', phone + 'param....', param);
24605
- if (event === "connected") {
24606
- /**
24607
- * When registration is successful then send the phone number of the same to UI
24608
- */
24609
- this.eventListener.onInitializationSuccess(phone);
24958
+ logger.log("ExWebClient: registerEventCallback: Received ---> " + event, [phone, param]);
24959
+ const lowerCaseEvent = event.toLowerCase();
24960
+ if (lowerCaseEvent === "registered") {
24610
24961
  this.registrationInProgress = false;
24611
- if (this.unregisterInitiated) {
24612
- logger.log("ExWebClient: registerEventCallback: unregistering due to unregisterInitiated");
24613
- this.unregisterInitiated = false;
24614
- this.unregister();
24615
- }
24616
- } else if (event === "failed_to_start" || event === "transport_error") {
24617
- /**
24618
- * If registration fails
24619
- */
24620
- this.eventListener.onInitializationFailure(phone);
24621
- if (this.unregisterInitiated) {
24622
- this.shouldAutoRetry = false;
24623
- this.unregisterInitiated = false;
24624
- this.isReadyToRegister = true;
24625
- }
24626
- if (this.shouldAutoRetry) {
24627
- logger.log("ExWebClient: registerEventCallback: Autoretrying");
24628
- (0,_api_registerAPI_RegisterListener__WEBPACK_IMPORTED_MODULE_1__.DoRegister)(this.sipAccountInfo, this, 5000);
24629
- }
24630
- } else if (event === "sent_request") {
24631
- /**
24632
- * If registration request waiting...
24633
- */
24634
- this.eventListener.onInitializationWaiting(phone);
24962
+ this.unregisterInitiated = false;
24963
+ this.isReadyToRegister = false;
24964
+ this.eventListener.onRegistrationStateChanged("registered", phone);
24965
+ } else if (lowerCaseEvent === "unregistered" || lowerCaseEvent === "terminated") {
24966
+ this.registrationInProgress = false;
24967
+ this.unregisterInitiated = false;
24968
+ this.isReadyToRegister = true;
24969
+ this.eventListener.onRegistrationStateChanged("unregistered", phone);
24635
24970
  }
24636
24971
  };
24637
24972
  /**
@@ -24643,7 +24978,12 @@ class ExotelWebClient {
24643
24978
  callEventCallback = (event, phone, param) => {
24644
24979
  logger.log("ExWebClient: callEventCallback: Received ---> " + event + 'param sent....' + param + 'for phone....' + phone);
24645
24980
  if (event === "i_new_call") {
24981
+ if (!this.call) {
24982
+ this.call = new _api_callAPI_Call__WEBPACK_IMPORTED_MODULE_0__.Call(param); // param is the session
24983
+ }
24646
24984
  this.callListener.onIncomingCall(param, phone);
24985
+ } else if (event === "ringing" || event === "accept_reject") {
24986
+ this.callListener.onRinging(param, phone);
24647
24987
  } else if (event === "connected") {
24648
24988
  this.callListener.onCallEstablished(param, phone);
24649
24989
  } else if (event === "terminated") {
@@ -24670,18 +25010,18 @@ class ExotelWebClient {
24670
25010
  this.shouldAutoRetry = false;
24671
25011
  this.unregisterInitiated = true;
24672
25012
  if (!this.registrationInProgress) {
24673
- setTimeout(function () {
24674
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.sipUnRegisterWebRTC();
25013
+ setTimeout(() => {
25014
+ const phone = phonePool[this.userName] || this.webrtcSIPPhone;
25015
+ if (phone) {
25016
+ phone.sipUnRegisterWebRTC();
25017
+ phone.disconnect?.();
25018
+ }
24675
25019
  }, 500);
24676
25020
  }
24677
25021
  };
24678
25022
  webRTCStatusCallbackHandler = (msg1, arg1) => {
24679
25023
  logger.log("ExWebClient: webRTCStatusCallbackHandler: " + msg1 + " " + arg1);
24680
25024
  };
24681
-
24682
- /**
24683
- * initialize function called when user wants to register client
24684
- */
24685
25025
  initialize = (uiContext, hostName, subscriberName, displayName, accountSid, subscriberToken, sipAccountInfo) => {
24686
25026
  let wssPort = sipAccountInfo.port;
24687
25027
  let wsPort = 4442;
@@ -24704,8 +25044,6 @@ class ExotelWebClient {
24704
25044
  };
24705
25045
  logger.log('ExWebClient: initialize: Sending register for the number..', subscriberName);
24706
25046
  fetchPublicIP(sipAccountInfo);
24707
-
24708
- /* Temporary till we figure out the arguments - Start */
24709
25047
  this.domain = hostName = sipAccountInfo.domain;
24710
25048
  this.sipdomain = sipAccountInfo.sipdomain;
24711
25049
  this.accountName = this.userName = sipAccountInfo.userName;
@@ -24721,9 +25059,6 @@ class ExotelWebClient {
24721
25059
  this.sipWsPort = 5061;
24722
25060
  this.sipPort = 5061;
24723
25061
  this.sipSecurePort = 5062;
24724
- /* Temporary till we figure out the arguments - End */
24725
-
24726
- /* This is permanent -Start */
24727
25062
  let webrtcPort = wssPort;
24728
25063
  if (this.security === 'ws') {
24729
25064
  webrtcPort = wsPort;
@@ -24740,37 +25075,21 @@ class ExotelWebClient {
24740
25075
  this.sipAccntInfo['port'] = webrtcPort;
24741
25076
  this.sipAccntInfo['contactHost'] = this.contactHost;
24742
25077
  localStorage.setItem('contactHost', this.contactHost);
24743
- /* This is permanent -End */
24744
-
24745
- /**
24746
- * Call the webclient function inside this and pass register and call callbacks as arg
24747
- */
24748
- var synchronousHandler = new ExSynchronousHandler(this);
25078
+ var synchronousHandler = new ExSynchronousHandler();
24749
25079
  var delegationHandler = new ExDelegationHandler(this);
24750
25080
  var userName = this.userName;
24751
- /* OLD-Way to be revisited for multile phone support */
24752
- //webRTCPhones[userName] = webRTC;
24753
-
24754
- /* New-Way */
24755
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.registerPhone("sipjs", delegationHandler, sipAccountInfo.enableAutoAudioDeviceChangeHandling);
24756
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.registerWebRTCClient(this.sipAccntInfo, synchronousHandler);
24757
-
24758
- /**
24759
- * Store the intervalID against a map
24760
- */
25081
+ this.webrtcSIPPhone.registerPhone("sipjs", delegationHandler, this.sipAccountInfo.enableAutoAudioDeviceChangeHandling);
25082
+ this.webrtcSIPPhone.registerWebRTCClient(this.sipAccntInfo, synchronousHandler);
25083
+ phonePool[this.userName] = this.webrtcSIPPhone;
24761
25084
  intervalIDMap.set(userName, intervalId);
24762
25085
  };
24763
25086
  checkClientStatus = callback => {
24764
- // using this function , first it will check mic permission is given or not
24765
- // then it will check if transport is intialize or not
24766
- // then it will check if user is registered or not
24767
- // based on this we can evaludate SDK is ready for call
24768
25087
  var constraints = {
24769
25088
  audio: true,
24770
25089
  video: false
24771
25090
  };
24772
25091
  navigator.mediaDevices.getUserMedia(constraints).then(function (mediaStream) {
24773
- var transportState = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.getTransportState();
25092
+ var transportState = this.webrtcSIPPhone.getTransportState();
24774
25093
  transportState = transportState.toLowerCase();
24775
25094
  switch (transportState) {
24776
25095
  case "":
@@ -24781,7 +25100,7 @@ class ExotelWebClient {
24781
25100
  callback(transportState);
24782
25101
  break;
24783
25102
  default:
24784
- var registerationState = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.getRegistrationState();
25103
+ var registerationState = this.webrtcSIPPhone.getRegistrationState();
24785
25104
  registerationState = registerationState.toLowerCase();
24786
25105
  switch (registerationState) {
24787
25106
  case "":
@@ -24805,11 +25124,11 @@ class ExotelWebClient {
24805
25124
  };
24806
25125
  changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange = false) {
24807
25126
  logger.log(`ExWebClient: changeAudioInputDevice: Entry`);
24808
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange);
25127
+ this.webrtcSIPPhone.changeAudioInputDevice(deviceId, onSuccess, onError, forceDeviceChange);
24809
25128
  }
24810
25129
  changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange = false) {
24811
25130
  logger.log(`ExWebClient: changeAudioOutputDevice: Entry`);
24812
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange);
25131
+ this.webrtcSIPPhone.changeAudioOutputDevice(deviceId, onSuccess, onError, forceDeviceChange);
24813
25132
  }
24814
25133
  downloadLogs() {
24815
25134
  logger.log(`ExWebClient: downloadLogs: Entry`);
@@ -24817,13 +25136,22 @@ class ExotelWebClient {
24817
25136
  }
24818
25137
  setPreferredCodec(codecName) {
24819
25138
  logger.log("ExWebClient: setPreferredCodec: Entry");
24820
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.setPreferredCodec(codecName);
25139
+ if (!this.webrtcSIPPhone || !this.webrtcSIPPhone.phone) {
25140
+ logger.warn("ExWebClient: setPreferredCodec: Phone not initialized");
25141
+ return;
25142
+ }
25143
+ this.webrtcSIPPhone.setPreferredCodec(codecName);
24821
25144
  }
24822
25145
  registerLoggerCallback(callback) {
24823
25146
  this.clientSDKLoggerCallback = callback;
24824
25147
  }
24825
25148
  registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback) {
24826
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback);
25149
+ logger.log("ExWebClient: registerAudioDeviceChangeCallback: Entry");
25150
+ if (!this.webrtcSIPPhone) {
25151
+ logger.warn("ExWebClient: registerAudioDeviceChangeCallback: webrtcSIPPhone not initialized");
25152
+ return;
25153
+ }
25154
+ this.webrtcSIPPhone.registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback);
24827
25155
  }
24828
25156
  setEnableConsoleLogging(enable) {
24829
25157
  if (enable) {
@@ -24849,35 +25177,43 @@ __webpack_require__.r(__webpack_exports__);
24849
25177
  /* harmony export */ });
24850
25178
  /* harmony import */ var _Callback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Callback */ "./src/listeners/Callback.js");
24851
25179
 
24852
-
24853
25180
  class ExotelVoiceClientListener {
25181
+ registerCallback = null;
25182
+ constructor(registerCallback) {
25183
+ this.registerCallback = registerCallback;
25184
+ }
24854
25185
  onInitializationSuccess(phone) {
24855
25186
  /**
24856
25187
  * Abstract class for Initialization Success
24857
25188
  */
24858
- _Callback__WEBPACK_IMPORTED_MODULE_0__.registerCallback.initializeRegister("registered", phone);
25189
+ this.registerCallback.initializeRegister("registered", phone);
24859
25190
  /**
24860
25191
  * Triggers UI callback to indicate the status of the registered phone
24861
25192
  */
24862
- _Callback__WEBPACK_IMPORTED_MODULE_0__.registerCallback.triggerRegisterCallback();
25193
+ this.registerCallback.triggerRegisterCallback();
24863
25194
  _Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("userReg", "registered", phone);
24864
25195
  }
24865
25196
  onInitializationFailure(phone) {
24866
25197
  /**
24867
25198
  * If register fails send error message to Callback function
24868
25199
  */
24869
- _Callback__WEBPACK_IMPORTED_MODULE_0__.registerCallback.initializeRegister("unregistered", phone);
24870
- _Callback__WEBPACK_IMPORTED_MODULE_0__.registerCallback.triggerRegisterCallback();
25200
+ this.registerCallback.initializeRegister("unregistered", phone);
25201
+ this.registerCallback.triggerRegisterCallback();
24871
25202
  _Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("userReg", "unregistered", phone);
24872
25203
  }
24873
25204
  onInitializationWaiting(phone) {
24874
25205
  /**
24875
25206
  * If register fails send error message to Callback function
24876
25207
  */
24877
- _Callback__WEBPACK_IMPORTED_MODULE_0__.registerCallback.initializeRegister("sent_request", phone);
24878
- _Callback__WEBPACK_IMPORTED_MODULE_0__.registerCallback.triggerRegisterCallback();
25208
+ this.registerCallback.initializeRegister("sent_request", phone);
25209
+ this.registerCallback.triggerRegisterCallback();
24879
25210
  _Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("userReg", "sent_request", phone);
24880
25211
  }
25212
+ onRegistrationStateChanged(state, phone) {
25213
+ this.registerCallback.initializeRegister(state, phone);
25214
+ this.registerCallback.triggerRegisterCallback();
25215
+ _Callback__WEBPACK_IMPORTED_MODULE_0__.diagnosticsCallback.triggerKeyValueSetCallback("userReg", state, phone);
25216
+ }
24881
25217
  onLog(LogLevel, tag, message) {
24882
25218
  /**
24883
25219
  * To get SDK logs
@@ -24903,125 +25239,137 @@ __webpack_require__.r(__webpack_exports__);
24903
25239
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
24904
25240
  /* harmony export */ SessionListener: () => (/* binding */ SessionListener)
24905
25241
  /* harmony export */ });
24906
- /* harmony import */ var _Callback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Callback */ "./src/listeners/Callback.js");
24907
- /* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! uuid */ "./node_modules/uuid/dist/esm-browser/v4.js");
24908
- /* harmony import */ var _constants_common__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/common */ "./src/constants/common.js");
24909
- /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24910
-
24911
-
25242
+ /* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! uuid */ "./node_modules/uuid/dist/esm-browser/v4.js");
25243
+ /* harmony import */ var _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @exotel-npm-dev/webrtc-core-sdk */ "./node_modules/@exotel-npm-dev/webrtc-core-sdk/index.js");
24912
25244
 
24913
25245
 
24914
- var logger = _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_3__.webrtcSIPPhone.getLogger();
25246
+ const logger = (0,_exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_1__.getLogger)();
24915
25247
  /**
24916
25248
  * Session listeners is invoked when user opens two tabs, the data in tab 1 is
24917
25249
  * copied into tab 2
24918
25250
  */
24919
- function SessionListener() {
24920
- const channel = new BroadcastChannel('app-data');
24921
- channel.addEventListener('message', event => {
24922
- if (event.data.message == "re-register-needed") {
24923
- /** Send the hash to app seeking for reregistration */
24924
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.initializeSession('re-register', event.data.hashMsg);
24925
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.triggerSessionCallback();
24926
- } else if (event.data.message == 'logout') {
24927
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.initializeSession('logout', '');
24928
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.triggerSessionCallback();
24929
- } else if (event.data.message == 'login-successful') {
24930
- const loginObj = {
24931
- phone: window.localStorage.getItem('currentUser'),
24932
- tabHash: event.data.tabHash
24933
- };
24934
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.initializeSession('login-successful', JSON.stringify(loginObj));
24935
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.triggerSessionCallback();
24936
- } else if (window.sessionStorage.getItem("activeSessionTab") !== null) {
24937
- if (event.data.callState !== null && event.data.callState !== undefined) {
24938
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.initializeSession(event.data.callState, event.data.callNumber);
24939
- }
24940
- _Callback__WEBPACK_IMPORTED_MODULE_0__.sessionCallback.triggerSessionCallback();
24941
- }
24942
- });
24943
- /**
24944
- * Add listeners for all storage events
24945
- */
24946
- window.localStorage.setItem('REQUESTING_SHARED_CREDENTIALS', Date.now().toString());
24947
- window.localStorage.removeItem('REQUESTING_SHARED_CREDENTIALS');
24948
- const credentials = {
24949
- user: window.sessionStorage.getItem('user'),
24950
- selectedPhone: window.localStorage.getItem('selectedPhone')
25251
+ class SessionListener {
25252
+ sessionCallback = null;
25253
+ constructor(sessionCallback) {
25254
+ this.sessionCallback = sessionCallback;
25255
+ }
25256
+ onSessionEstablished = function (session) {
25257
+ logger.log("SessionListener: onSessionEstablished");
25258
+ this.sessionCallback.triggerCallback("established", session);
24951
25259
  };
24952
- window.addEventListener('storage', event => {
25260
+ onSessionTerminated = function (session) {
25261
+ logger.log("SessionListener: onSessionTerminated");
25262
+ this.sessionCallback.triggerCallback("terminated", session);
25263
+ };
25264
+ onSessionEvent(event) {
25265
+ this.sessionCallback.triggerSessionCallback(event);
25266
+ }
25267
+ onTBD() {
25268
+ const channel = new BroadcastChannel('app-data');
25269
+ channel.addEventListener('message', event => {
25270
+ if (event.data.message == "re-register-needed") {
25271
+ /** Send the hash to app seeking for reregistration */
25272
+ this.sessionCallback.initializeSession('re-register', event.data.hashMsg);
25273
+ this.sessionCallback.triggerSessionCallback();
25274
+ } else if (event.data.message == 'logout') {
25275
+ this.sessionCallback.initializeSession('logout', '');
25276
+ this.sessionCallback.triggerSessionCallback();
25277
+ } else if (event.data.message == 'login-successful') {
25278
+ const loginObj = {
25279
+ phone: window.localStorage.getItem('currentUser'),
25280
+ tabHash: event.data.tabHash
25281
+ };
25282
+ this.sessionCallback.initializeSession('login-successful', JSON.stringify(loginObj));
25283
+ this.sessionCallback.triggerSessionCallback();
25284
+ } else if (window.sessionStorage.getItem("activeSessionTab") !== null) {
25285
+ if (event.data.callState !== null && event.data.callState !== undefined) {
25286
+ this.sessionCallback.initializeSession(event.data.callState, event.data.callNumber);
25287
+ }
25288
+ this.sessionCallback.triggerSessionCallback();
25289
+ }
25290
+ });
24953
25291
  /**
24954
- * When user tries to duplicate tab, this gets called in Tab1
24955
- */
24956
- if (event.key === 'REQUESTING_SHARED_CREDENTIALS' && credentials) {
24957
- window.localStorage.setItem('CREDENTIALS_SHARING', JSON.stringify(credentials));
24958
- window.localStorage.removeItem('CREDENTIALS_SHARING');
25292
+ * Add listeners for all storage events
25293
+ */
25294
+ window.localStorage.setItem('REQUESTING_SHARED_CREDENTIALS', Date.now().toString());
25295
+ window.localStorage.removeItem('REQUESTING_SHARED_CREDENTIALS');
25296
+ const credentials = {
25297
+ user: window.sessionStorage.getItem('user'),
25298
+ selectedPhone: window.localStorage.getItem('selectedPhone')
25299
+ };
25300
+ window.addEventListener('storage', event => {
24959
25301
  /**
24960
- * When the data is to be shared between two tabs then add the current state onto that session storage
24961
- */
24962
- //sessionCallback.triggerSessionCallback();
24963
- }
24964
- if (event.key === 'CREDENTIALS_SHARING' && credentials !== null) {
24965
- const newData = JSON.parse(event.newValue);
24966
- if (event.newValue !== null) {
24967
- window.sessionStorage.setItem('user', newData.user);
24968
- window.sessionStorage.setItem('isAuthenticated', true);
25302
+ * When user tries to duplicate tab, this gets called in Tab1
25303
+ */
25304
+ if (event.key === 'REQUESTING_SHARED_CREDENTIALS' && credentials) {
25305
+ window.localStorage.setItem('CREDENTIALS_SHARING', JSON.stringify(credentials));
25306
+ window.localStorage.removeItem('CREDENTIALS_SHARING');
25307
+ /**
25308
+ * When the data is to be shared between two tabs then add the current state onto that session storage
25309
+ */
25310
+ //sessionCallback.triggerSessionCallback();
24969
25311
  }
24970
- /**
24971
- * Fetch the array of tabs and add the tab, put it on session also
24972
- */
24973
- const currentTab = {
24974
- tabID: (0,uuid__WEBPACK_IMPORTED_MODULE_1__["default"])(),
24975
- tabType: 'child',
24976
- tabStatus: 'active'
24977
- };
24978
- const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
24979
- /** Based on activeSessionTab id fetch the type */
25312
+ if (event.key === 'CREDENTIALS_SHARING' && credentials !== null) {
25313
+ const newData = JSON.parse(event.newValue);
25314
+ if (event.newValue !== null) {
25315
+ window.sessionStorage.setItem('user', newData.user);
25316
+ window.sessionStorage.setItem('isAuthenticated', true);
25317
+ }
25318
+ /**
25319
+ * Fetch the array of tabs and add the tab, put it on session also
25320
+ */
25321
+ const currentTab = {
25322
+ tabID: (0,uuid__WEBPACK_IMPORTED_MODULE_0__["default"])(),
25323
+ tabType: 'child',
25324
+ tabStatus: 'active'
25325
+ };
25326
+ const tabArr = JSON.parse(window.localStorage.getItem('tabs'));
25327
+ /** Based on activeSessionTab id fetch the type */
24980
25328
 
24981
- if (window.sessionStorage.getItem('activeSessionTab') !== null && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
24982
- logger.log('Adding a child tab spawned from parent....');
24983
- /** In order to keep tabID same for all the child ones, we are using below IF to distinguish */
25329
+ if (window.sessionStorage.getItem('activeSessionTab') !== null && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
25330
+ logger.log('Adding a child tab spawned from parent....');
25331
+ /** In order to keep tabID same for all the child ones, we are using below IF to distinguish */
24984
25332
 
24985
- if (tabArr.length > 1 && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
24986
- if (!document.hidden) {
25333
+ if (tabArr.length > 1 && window.sessionStorage.getItem('activeSessionTab') == "parent0") {
25334
+ if (!document.hidden) {
25335
+ const lastIndex = tabArr.length - 1;
25336
+ window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
25337
+ }
25338
+ } else {
25339
+ tabArr.push(currentTab);
25340
+ window.localStorage.removeItem('tabs');
25341
+ window.localStorage.setItem('tabs', JSON.stringify(tabArr));
24987
25342
  const lastIndex = tabArr.length - 1;
24988
25343
  window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
24989
25344
  }
24990
25345
  } else {
24991
- tabArr.push(currentTab);
24992
- window.localStorage.removeItem('tabs');
24993
- window.localStorage.setItem('tabs', JSON.stringify(tabArr));
25346
+ /** pull from the tabarray and then add it to the session storage */
25347
+
24994
25348
  const lastIndex = tabArr.length - 1;
24995
25349
  window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
24996
25350
  }
24997
- } else {
24998
- /** pull from the tabarray and then add it to the session storage */
24999
-
25000
- const lastIndex = tabArr.length - 1;
25001
- window.sessionStorage.setItem('activeSessionTab', tabArr[lastIndex].tabID);
25351
+ //window.localStorage.setItem('selectedPhone', newData.selectedPhone);
25352
+ return;
25353
+ //}
25002
25354
  }
25003
- //window.localStorage.setItem('selectedPhone', newData.selectedPhone);
25004
- return;
25005
- //}
25006
- }
25007
- /**
25008
- * When a tab is closed
25009
- */
25010
- if (event.key === 'CREDENTIALS_FLUSH' && credentials) {
25011
- window.sessionStorage.removeItem('user');
25012
- window.sessionStorage.removeItem('selectedPhone');
25013
- window.sessionStorage.removeItem('isAuthenticated');
25014
- window.sessionStorage.removeItem('activeSession');
25015
- }
25016
- /**
25017
- * When any tab is closed, active call gets terminated
25018
- */
25019
- if (event.key === 'CALL_FLUSH') {
25020
- window.sessionStorage.removeItem('activeSession');
25021
- }
25022
- });
25355
+ /**
25356
+ * When a tab is closed
25357
+ */
25358
+ if (event.key === 'CREDENTIALS_FLUSH' && credentials) {
25359
+ window.sessionStorage.removeItem('user');
25360
+ window.sessionStorage.removeItem('selectedPhone');
25361
+ window.sessionStorage.removeItem('isAuthenticated');
25362
+ window.sessionStorage.removeItem('activeSession');
25363
+ }
25364
+ /**
25365
+ * When any tab is closed, active call gets terminated
25366
+ */
25367
+ if (event.key === 'CALL_FLUSH') {
25368
+ window.sessionStorage.removeItem('activeSession');
25369
+ }
25370
+ });
25371
+ }
25023
25372
  }
25024
- ;
25025
25373
 
25026
25374
  /***/ })
25027
25375
 
@@ -25125,12 +25473,11 @@ var __webpack_exports__ = {};
25125
25473
  \******************/
25126
25474
  __webpack_require__.r(__webpack_exports__);
25127
25475
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
25128
- /* harmony export */ ExDelegationHandler: () => (/* reexport safe */ _src_listeners_ExWebClient__WEBPACK_IMPORTED_MODULE_0__.ExDelegationHandler),
25129
- /* harmony export */ ExSynchronousHandler: () => (/* reexport safe */ _src_listeners_ExWebClient__WEBPACK_IMPORTED_MODULE_0__.ExSynchronousHandler),
25130
25476
  /* harmony export */ ExotelWebClient: () => (/* reexport safe */ _src_listeners_ExWebClient__WEBPACK_IMPORTED_MODULE_0__.ExotelWebClient)
25131
25477
  /* harmony export */ });
25132
25478
  /* harmony import */ var _src_listeners_ExWebClient__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/listeners/ExWebClient */ "./src/listeners/ExWebClient.js");
25133
25479
 
25480
+
25134
25481
  })();
25135
25482
 
25136
25483
  /******/ return __webpack_exports__;