@exotel-npm-dev/webrtc-client-sdk 1.0.16 → 1.0.18

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/Changelog CHANGED
@@ -1,8 +1,15 @@
1
1
  Change Log
2
2
 
3
- ## v1.0.15 21 November, 2024
3
+ ## v1.0.18 08 January, 2025
4
+ -[VST-865] Added option in websdk to select the codec preference
5
+
6
+ ## v1.0.16 21 November, 2024
4
7
  -[VST-885] Retry Support for SDK Websocket Connection
5
8
 
9
+ ## v1.0.15 25 October, 2024
10
+ -[VST-863] Added option provide ondevice change callback
11
+
12
+
6
13
  ## v1.0.14 12 September, 2024
7
14
  -[VST-807] Added call details with callsid and sip headers
8
15
 
package/Makefile CHANGED
@@ -14,3 +14,5 @@ dep:
14
14
  npm uninstall @exotel-npm-dev/webrtc-core-sdk
15
15
  npm install @exotel-npm-dev/webrtc-core-sdk@latest
16
16
 
17
+ publish: build
18
+ npm publish
package/dist/exotelsdk.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * WebRTC CLient SIP version 1.0.16
3
+ * WebRTC CLient SIP version 1.0.18
4
4
  *
5
5
  */
6
6
  (function webpackUniversalModuleDefinition(root, factory) {
@@ -21233,6 +21233,90 @@ function postInit(onInitDoneCallback) {
21233
21233
  onInitDoneCallback();
21234
21234
  }
21235
21235
 
21236
+ const addPreferredCodec = (description) => {
21237
+ logger.log("sipjsphone:addPreferredCodec entry");
21238
+ // Ensure a preferred codec is set
21239
+ if (!SIPJSPhone.preferredCodec) {
21240
+ logger.info("sipjsphone:addPreferredCodec: No preferred codec set. Using default.");
21241
+ return Promise.resolve(description);
21242
+ }
21243
+
21244
+ const { payloadType, rtpMap, fmtp } = SIPJSPhone.preferredCodec;
21245
+ const codecRtpMap = `a=rtpmap:${payloadType} ${rtpMap}`;
21246
+ const codecFmtp = fmtp ? `a=fmtp:${payloadType} ${fmtp}` : "";
21247
+
21248
+ logger.log("sipjsphone:addPreferredCodec: Original SDP:", description.sdp);
21249
+
21250
+ // Parse SDP into lines
21251
+ let sdpLines = description.sdp.split("\r\n");
21252
+
21253
+ // Check if Opus is already in the SDP
21254
+ const existingOpusIndex = sdpLines.findIndex((line) => line.includes(`a=rtpmap`) && line.includes("opus/48000/2"));
21255
+ const audioMLineIndex = sdpLines.findIndex((line) => line.startsWith("m=audio"));
21256
+
21257
+ if (existingOpusIndex !== -1 && audioMLineIndex !== -1) {
21258
+ logger.log("sipjsphone:addPreferredCodec: Opus codec already exists. Prioritizing it.");
21259
+
21260
+ // Extract and modify the audio m-line
21261
+ let audioMLine = sdpLines[audioMLineIndex];
21262
+ audioMLine = audioMLine.replace("RTP/SAVP", "RTP/AVP");
21263
+
21264
+ const codecs = audioMLine.split(" ");
21265
+ const mLineStart = codecs.slice(0, 3); // "m=audio <port> <protocol>"
21266
+ const mLineCodecs = codecs.slice(3);
21267
+
21268
+ // Move existing Opus payload type to the top
21269
+ const opusPayloadType = sdpLines[existingOpusIndex].match(/a=rtpmap:(\d+)/)[1];
21270
+ const opusIndex = mLineCodecs.indexOf(opusPayloadType);
21271
+
21272
+ if (opusIndex !== -1) {
21273
+ // Remove Opus from its current position
21274
+ mLineCodecs.splice(opusIndex, 1);
21275
+ }
21276
+ // Add Opus to the beginning of the codec list
21277
+ mLineCodecs.unshift(opusPayloadType);
21278
+
21279
+ // Update the audio m-line
21280
+ sdpLines[audioMLineIndex] = `${mLineStart.join(" ")} ${mLineCodecs.join(" ")}`;
21281
+ } else if (audioMLineIndex !== -1) {
21282
+ logger.log("sipjsphone:addPreferredCodec: Opus codec not found. Adding it to SDP.");
21283
+
21284
+ // Extract and modify the audio m-line
21285
+ let audioMLine = sdpLines[audioMLineIndex];
21286
+ audioMLine = audioMLine.replace("RTP/SAVP", "RTP/AVP");
21287
+
21288
+ const codecs = audioMLine.split(" ");
21289
+ const mLineStart = codecs.slice(0, 3); // "m=audio <port> <protocol>"
21290
+ const mLineCodecs = codecs.slice(3);
21291
+
21292
+ // Add Opus payload type to the top
21293
+ mLineCodecs.unshift(payloadType.toString());
21294
+
21295
+ // Update the audio m-line
21296
+ sdpLines[audioMLineIndex] = `${mLineStart.join(" ")} ${mLineCodecs.join(" ")}`;
21297
+
21298
+ // Add Opus-specific attributes to the SDP
21299
+ if (!sdpLines.includes(codecRtpMap)) {
21300
+ sdpLines.splice(audioMLineIndex + 1, 0, codecRtpMap); // Add rtpmap after m=audio
21301
+ }
21302
+ if (fmtp && !sdpLines.includes(codecFmtp)) {
21303
+ sdpLines.splice(audioMLineIndex + 2, 0, codecFmtp); // Add fmtp after rtpmap
21304
+ }
21305
+ } else {
21306
+ logger.error("sipjsphone:addPreferredCodec: No audio m-line found in SDP. Cannot modify.");
21307
+ return Promise.resolve(description);
21308
+ }
21309
+
21310
+ // Remove any duplicate lines
21311
+ sdpLines = [...new Set(sdpLines)];
21312
+
21313
+ // Combine back into SDP
21314
+ description.sdp = sdpLines.join("\r\n");
21315
+ logger.log("sipjsphone:addPreferredCodec: Modified SDP:", description.sdp);
21316
+
21317
+ return Promise.resolve(description);
21318
+ };
21319
+
21236
21320
  function sipRegister() {
21237
21321
 
21238
21322
  lastRegistererState = "";
@@ -21951,6 +22035,23 @@ const SIPJSPhone = {
21951
22035
  return bMicEnable;
21952
22036
  },
21953
22037
 
22038
+ setPreferredCodec: (codecName) => {
22039
+ logger.log("sipjsphone:setPreferredCodec entry");
22040
+ const codecPayloadTypes = {
22041
+ opus: { payloadType: 111, rtpMap: "opus/48000/2", fmtp: "minptime=10;useinbandfec=1" },
22042
+ };
22043
+
22044
+ const preferredCodec = codecPayloadTypes[codecName.toLowerCase()];
22045
+ if (!preferredCodec) {
22046
+ logger.error("sipjsphone:setPreferredCodec: Unsupported code" + codecName + "specified.");
22047
+ SIPJSPhone.preferredCodec = null; // Clear codec details if unsupported
22048
+ return;
22049
+ }
22050
+
22051
+ SIPJSPhone.preferredCodec = preferredCodec;
22052
+ logger.log("sipjsphone:setPreferredCodec: Preferred codec set to " + codecName);
22053
+ },
22054
+
21954
22055
  pickPhoneCall: () => {
21955
22056
  var newSess = ctxSip.Sessions[ctxSip.callActiveID];
21956
22057
  logger.log("pickphonecall ", ctxSip.callActiveID);
@@ -21959,13 +22060,16 @@ const SIPJSPhone = {
21959
22060
  newSess.accept({
21960
22061
  sessionDescriptionHandlerOptions: {
21961
22062
  constraints: { audio: { deviceId: _audioDeviceManager_js__WEBPACK_IMPORTED_MODULE_0__.audioDeviceManager.currentAudioInputDeviceId }, video: false }
21962
- }
22063
+ },
22064
+ sessionDescriptionHandlerModifiers: [addPreferredCodec]
21963
22065
  }).catch((e) => {
21964
22066
  onUserSessionAcceptFailed(e);
21965
22067
  });
21966
22068
  } else {
21967
22069
 
21968
- newSess.accept().catch((e) => {
22070
+ newSess.accept({
22071
+ sessionDescriptionHandlerModifiers: [addPreferredCodec]
22072
+ }).catch((e) => {
21969
22073
  onUserSessionAcceptFailed(e);
21970
22074
  });
21971
22075
  }
@@ -22394,6 +22498,10 @@ const webrtcSIPPhone = {
22394
22498
  logger.log(`webrtcSIPPhone:changeAudioOutputDevice entry`);
22395
22499
  _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].changeAudioOutputDevice(deviceId, onSuccess, onError);
22396
22500
  },
22501
+ setPreferredCodec(codecName) {
22502
+ logger.log("webrtcSIPPhone:setPreferredCodec entry");
22503
+ _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].setPreferredCodec(codecName);
22504
+ },
22397
22505
  registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback) {
22398
22506
  logger.log(`webrtcSIPPhone:registerAudioDeviceChangeCallback entry`);
22399
22507
  _sipjsphone__WEBPACK_IMPORTED_MODULE_1__["default"].registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback);
@@ -24326,11 +24434,15 @@ class ExotelWebClient {
24326
24434
  logger.log(`in changeAudioOutputDevice() of ExWebClient.js`);
24327
24435
  _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.changeAudioOutputDevice(deviceId, onSuccess, onError);
24328
24436
  }
24437
+ setPreferredCodec(codecName) {
24438
+ logger.log("ExWebClient:setPreferredCodec entry");
24439
+ _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.setPreferredCodec(codecName);
24440
+ }
24329
24441
  registerLoggerCallback(callback) {
24330
24442
  logger.registerLoggerCallback(callback);
24331
24443
  }
24332
- registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback) {
24333
- _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback);
24444
+ registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback) {
24445
+ _exotel_npm_dev_webrtc_core_sdk__WEBPACK_IMPORTED_MODULE_8__.webrtcSIPPhone.registerAudioDeviceChangeCallback(audioInputDeviceChangeCallback, audioOutputDeviceChangeCallback, onDeviceChangeCallback);
24334
24446
  }
24335
24447
  }
24336
24448
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ExotelWebClient);