@wazo/sdk 0.37.0-rc.5 → 0.37.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.
Files changed (149) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +93 -16
  3. package/esm/__tests__/web-rtc-client.test.js +153 -54
  4. package/esm/api/agentd.js +24 -3
  5. package/esm/api/amid.js +7 -1
  6. package/esm/api/application.js +24 -3
  7. package/esm/api/auth.js +24 -3
  8. package/esm/api/call-logd.js +78 -20
  9. package/esm/api/calld.js +24 -20
  10. package/esm/api/chatd.js +24 -3
  11. package/esm/api/confd.js +24 -3
  12. package/esm/api/ctid-ng.js +24 -3
  13. package/esm/api/dird.js +27 -6
  14. package/esm/api/webhookd.js +7 -1
  15. package/esm/api-client.js +93 -16
  16. package/esm/checker/Checker.js +156 -54
  17. package/esm/checker/checks/aor.js +95 -16
  18. package/esm/checker/checks/api.js +94 -16
  19. package/esm/checker/checks/index.js +156 -54
  20. package/esm/checker/checks/wazo-websocket.js +7 -1
  21. package/esm/checker/checks/webrtc-transport.js +153 -54
  22. package/esm/checker/checks/webrtc.js +153 -54
  23. package/esm/domain/AdHocAPIConference.js +1717 -1640
  24. package/esm/domain/CallLog.js +71 -19
  25. package/esm/domain/CallSession.js +1 -18
  26. package/esm/domain/Contact.js +3 -3
  27. package/esm/domain/Features.js +93 -16
  28. package/esm/domain/IndirectTransfer.js +0 -17
  29. package/esm/domain/Phone/CTIPhone.js +100 -19
  30. package/esm/domain/Phone/Phone.js +0 -17
  31. package/esm/domain/Phone/WebRTCPhone.js +51 -36
  32. package/esm/domain/Recording.js +51 -0
  33. package/esm/domain/Room.js +0 -17
  34. package/esm/domain/SwitchboardCall.js +0 -17
  35. package/esm/domain/__tests__/CallLog.test.js +89 -19
  36. package/esm/domain/__tests__/CallSession.test.js +1 -18
  37. package/esm/domain/__tests__/Contact.test.js +3 -3
  38. package/esm/domain/__tests__/IndirectTransfer.test.js +1 -18
  39. package/esm/domain/__tests__/Room.test.js +1 -18
  40. package/esm/domain/__tests__/Session.test.js +7 -0
  41. package/esm/index.js +3436 -2911
  42. package/esm/lib/WazoSessionDescriptionHandler.js +28 -10
  43. package/esm/service/CallApi.js +93 -16
  44. package/esm/service/IssueReporter.js +7 -1
  45. package/esm/service/__tests__/IssueReporter.test.js +26 -2
  46. package/esm/service/getApiClient.js +93 -16
  47. package/esm/simple/Auth.js +619 -97
  48. package/esm/simple/Configuration.js +619 -97
  49. package/esm/simple/Directory.js +93 -16
  50. package/esm/simple/Phone.js +3261 -2739
  51. package/esm/simple/Websocket.js +7 -1
  52. package/esm/simple/index.js +619 -97
  53. package/esm/simple/room/LocalParticipant.js +619 -97
  54. package/esm/simple/room/Participant.js +619 -97
  55. package/esm/simple/room/RemoteParticipant.js +619 -97
  56. package/esm/simple/room/Room.js +619 -97
  57. package/esm/simple/room/Stream.js +619 -97
  58. package/esm/simple/room/__tests__/RemoteParticipant.test.js +619 -97
  59. package/esm/simple/utils.js +619 -97
  60. package/esm/utils/__tests__/api-requester.test.js +32 -6
  61. package/esm/utils/api-requester.js +24 -3
  62. package/esm/web-rtc-client.js +153 -54
  63. package/esm/websocket-client.js +7 -1
  64. package/lib/__tests__/api-client.test.js +93 -16
  65. package/lib/__tests__/web-rtc-client.test.js +154 -55
  66. package/lib/api/agentd.js +24 -3
  67. package/lib/api/amid.js +7 -1
  68. package/lib/api/application.js +24 -3
  69. package/lib/api/auth.js +24 -3
  70. package/lib/api/call-logd.js +78 -20
  71. package/lib/api/calld.js +24 -20
  72. package/lib/api/chatd.js +24 -3
  73. package/lib/api/confd.js +24 -3
  74. package/lib/api/ctid-ng.js +24 -3
  75. package/lib/api/dird.js +27 -6
  76. package/lib/api/webhookd.js +7 -1
  77. package/lib/api-client.js +93 -16
  78. package/lib/checker/Checker.js +157 -55
  79. package/lib/checker/checks/aor.js +95 -16
  80. package/lib/checker/checks/api.js +94 -16
  81. package/lib/checker/checks/index.js +157 -55
  82. package/lib/checker/checks/wazo-websocket.js +7 -1
  83. package/lib/checker/checks/webrtc-transport.js +154 -55
  84. package/lib/checker/checks/webrtc.js +154 -55
  85. package/lib/domain/AdHocAPIConference.js +1717 -1640
  86. package/lib/domain/CallLog.js +71 -19
  87. package/lib/domain/CallSession.js +1 -18
  88. package/lib/domain/Contact.js +3 -3
  89. package/lib/domain/Features.js +93 -16
  90. package/lib/domain/IndirectTransfer.js +0 -17
  91. package/lib/domain/Phone/CTIPhone.js +100 -19
  92. package/lib/domain/Phone/Phone.js +0 -16
  93. package/lib/domain/Phone/WebRTCPhone.js +51 -36
  94. package/lib/domain/Recording.js +57 -0
  95. package/lib/domain/Room.js +0 -17
  96. package/lib/domain/SwitchboardCall.js +0 -17
  97. package/lib/domain/__tests__/CallLog.test.js +89 -19
  98. package/lib/domain/__tests__/CallSession.test.js +1 -18
  99. package/lib/domain/__tests__/Contact.test.js +3 -3
  100. package/lib/domain/__tests__/IndirectTransfer.test.js +1 -18
  101. package/lib/domain/__tests__/Room.test.js +1 -18
  102. package/lib/domain/__tests__/Session.test.js +7 -0
  103. package/lib/index.js +3437 -2912
  104. package/lib/lib/WazoSessionDescriptionHandler.js +28 -10
  105. package/lib/service/CallApi.js +93 -16
  106. package/lib/service/IssueReporter.js +7 -1
  107. package/lib/service/__tests__/IssueReporter.test.js +26 -2
  108. package/lib/service/getApiClient.js +93 -16
  109. package/lib/simple/Auth.js +620 -98
  110. package/lib/simple/Configuration.js +620 -98
  111. package/lib/simple/Directory.js +93 -16
  112. package/lib/simple/Phone.js +3262 -2740
  113. package/lib/simple/Websocket.js +7 -1
  114. package/lib/simple/index.js +620 -98
  115. package/lib/simple/room/LocalParticipant.js +620 -98
  116. package/lib/simple/room/Participant.js +620 -98
  117. package/lib/simple/room/RemoteParticipant.js +620 -98
  118. package/lib/simple/room/Room.js +620 -98
  119. package/lib/simple/room/Stream.js +620 -98
  120. package/lib/simple/room/__tests__/RemoteParticipant.test.js +620 -98
  121. package/lib/simple/utils.js +620 -98
  122. package/lib/utils/__tests__/api-requester.test.js +32 -6
  123. package/lib/utils/api-requester.js +24 -3
  124. package/lib/web-rtc-client.js +154 -55
  125. package/lib/websocket-client.js +7 -1
  126. package/package.json +1 -1
  127. package/src/api-client.js +4 -0
  128. package/src/checker/checks/aor.js +2 -0
  129. package/src/checker/checks/api.js +1 -0
  130. package/src/domain/CallLog.js +18 -11
  131. package/src/domain/CallSession.js +1 -2
  132. package/src/domain/Contact.js +3 -3
  133. package/src/domain/Phone/CTIPhone.js +6 -2
  134. package/src/domain/Phone/Phone.js +2 -0
  135. package/src/domain/Phone/WebRTCPhone.js +26 -16
  136. package/src/domain/Recording.js +48 -0
  137. package/src/domain/__tests__/CallLog.test.js +19 -0
  138. package/src/domain/__tests__/Session.test.js +7 -0
  139. package/src/index.js +6 -0
  140. package/src/lib/WazoSessionDescriptionHandler.js +21 -9
  141. package/src/service/IssueReporter.js +7 -1
  142. package/src/service/__tests__/IssueReporter.test.js +20 -1
  143. package/src/simple/Phone.js +5 -1
  144. package/src/simple/index.js +6 -0
  145. package/src/simple/room/Room.js +18 -15
  146. package/src/simple/room/Stream.js +1 -4
  147. package/src/utils/__tests__/api-requester.test.js +9 -4
  148. package/src/utils/api-requester.js +17 -2
  149. package/src/web-rtc-client.js +40 -13
@@ -9,7 +9,6 @@ var jsonToGraphQLQuery = require('json-to-graphql-query/lib/jsonToGraphQLQuery')
9
9
  var ReconnectingWebSocket = require('reconnecting-websocket');
10
10
  require('webrtc-adapter');
11
11
  var userAgentState = require('sip.js/lib/api/user-agent-state');
12
- require('sip.js/lib/api/message');
13
12
  var parser = require('sip.js/lib/core/messages/parser');
14
13
  var constants = require('sip.js/lib/core/messages/methods/constants');
15
14
  var uri = require('sip.js/lib/grammar/uri');
@@ -338,7 +337,13 @@ class IssueReporter {
338
337
  }
339
338
 
340
339
  _isLevelAbove(level1 , level2 ) {
341
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
340
+ const index1 = LOG_LEVELS.indexOf(level1);
341
+ const index2 = LOG_LEVELS.indexOf(level2);
342
+ if (index1 === -1 || index2 === -1) {
343
+ return false;
344
+ }
345
+
346
+ return index1 > index2;
342
347
  }
343
348
 
344
349
  _makeCategory(category ) {
@@ -396,6 +401,7 @@ class ApiRequester {
396
401
 
397
402
 
398
403
 
404
+
399
405
 
400
406
 
401
407
 
@@ -435,6 +441,8 @@ class ApiRequester {
435
441
  this.token = token;
436
442
  }
437
443
 
444
+ this.shouldLogErrors = true;
445
+
438
446
  methods.forEach(method => {
439
447
  // $FlowFixMe
440
448
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -458,6 +466,14 @@ class ApiRequester {
458
466
  this.fetchOptions = options;
459
467
  }
460
468
 
469
+ disableErrorLogging() {
470
+ this.shouldLogErrors = false;
471
+ }
472
+
473
+ enableErrorLogging() {
474
+ this.shouldLogErrors = true;
475
+ }
476
+
461
477
  async call(
462
478
  path ,
463
479
  method = 'get',
@@ -518,7 +534,9 @@ class ApiRequester {
518
534
  ? exceptionClass.fromText(err, response.status)
519
535
  : exceptionClass.fromResponse(err, response.status);
520
536
 
521
- logger$3.error('API error', error);
537
+ if (this.shouldLogErrors) {
538
+ logger$3.error('API error', error);
539
+ }
522
540
 
523
541
  throw error;
524
542
  });
@@ -526,7 +544,9 @@ class ApiRequester {
526
544
 
527
545
  return newParse(response, isJson);
528
546
  }).catch(error => {
529
- logger$3.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
547
+ if (this.shouldLogErrors) {
548
+ logger$3.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
549
+ }
530
550
 
531
551
  throw error;
532
552
  });
@@ -1576,7 +1596,7 @@ class Contact {
1576
1596
 
1577
1597
  return new Contact({
1578
1598
  sourceId: single.id || '',
1579
- name: single.displayName,
1599
+ name: single.displayName || '',
1580
1600
  number: numbers.length ? numbers[0].number : '',
1581
1601
  numbers,
1582
1602
  emails,
@@ -1607,7 +1627,7 @@ class Contact {
1607
1627
 
1608
1628
  return new Contact({
1609
1629
  sourceId: single.id || '',
1610
- name: single.name,
1630
+ name: single.name || '',
1611
1631
  number: numbers.length ? numbers[0].number : '',
1612
1632
  numbers,
1613
1633
  emails,
@@ -1708,7 +1728,7 @@ class Contact {
1708
1728
  } = {}) {
1709
1729
  this.id = id;
1710
1730
  this.uuid = uuid;
1711
- this.name = name;
1731
+ this.name = name || '';
1712
1732
  this.number = number;
1713
1733
  this.numbers = numbers;
1714
1734
  this.email = email;
@@ -3043,17 +3063,66 @@ class Emitter {
3043
3063
 
3044
3064
  //
3045
3065
 
3066
+
3067
+
3068
+
3069
+
3070
+
3071
+
3072
+
3073
+
3074
+
3075
+
3076
+
3077
+
3078
+
3079
+
3080
+
3081
+
3082
+ class Recording {
3083
+
3084
+
3085
+
3086
+
3087
+
3088
+
3089
+ static parseMany(recordings ) {
3090
+ return recordings.map(item => Recording.parse(item));
3091
+ }
3092
+
3093
+ static parse(plain ) {
3094
+ return new Recording({
3095
+ deleted: plain.deleted,
3096
+ fileName: plain.filename,
3097
+ end: plain.end_time ? moment__default['default'](plain.end_time).toDate() : null,
3098
+ start: moment__default['default'](plain.start_time).toDate(),
3099
+ uuid: plain.uuid,
3100
+ });
3101
+ }
3102
+
3103
+ constructor({ deleted, end, fileName, start, uuid } ) {
3104
+ this.deleted = deleted;
3105
+ this.end = end;
3106
+ this.fileName = fileName;
3107
+ this.start = start;
3108
+ this.uuid = uuid;
3109
+ }
3110
+ }
3111
+
3112
+ //
3113
+
3046
3114
 
3047
-
3115
+
3048
3116
 
3049
3117
 
3050
3118
 
3051
3119
 
3052
3120
 
3053
-
3121
+
3054
3122
 
3055
3123
 
3056
3124
 
3125
+
3057
3126
 
3058
3127
 
3059
3128
 
@@ -3066,7 +3135,7 @@ class Emitter {
3066
3135
 
3067
3136
 
3068
3137
 
3069
-
3138
+
3070
3139
 
3071
3140
 
3072
3141
 
@@ -3081,13 +3150,14 @@ class Emitter {
3081
3150
 
3082
3151
 
3083
3152
 
3084
-
3153
+
3154
+
3085
3155
 
3086
3156
 
3087
3157
  class CallLog {
3088
3158
 
3089
3159
 
3090
-
3160
+
3091
3161
 
3092
3162
 
3093
3163
 
@@ -3104,7 +3174,7 @@ class CallLog {
3104
3174
 
3105
3175
 
3106
3176
 
3107
-
3177
+
3108
3178
 
3109
3179
  static merge(current , toMerge ) {
3110
3180
  const onlyUnique = (value, index, self) => self.indexOf(value) === index;
@@ -3121,7 +3191,7 @@ class CallLog {
3121
3191
 
3122
3192
  static parse(plain ) {
3123
3193
  return new CallLog({
3124
- answer: moment__default['default'](plain.answer).toDate(),
3194
+ answer: plain.answer ? moment__default['default'](plain.answer).toDate() : null,
3125
3195
  answered: plain.answered,
3126
3196
  callDirection: plain.call_direction,
3127
3197
  destination: {
@@ -3135,13 +3205,14 @@ class CallLog {
3135
3205
  id: plain.id,
3136
3206
  duration: (plain.duration || 0) * 1000, // duration is in seconds
3137
3207
  start: moment__default['default'](plain.start).toDate(),
3138
- end: moment__default['default'](plain.end).toDate(),
3208
+ end: plain.end ? moment__default['default'](plain.end).toDate() : null,
3209
+ recordings: Recording.parseMany(plain.recordings),
3139
3210
  });
3140
3211
  }
3141
3212
 
3142
3213
  static parseNew(plain , session ) {
3143
3214
  return new CallLog({
3144
- answer: moment__default['default'](plain.answer).toDate(),
3215
+ answer: plain.answer ? moment__default['default'](plain.answer).toDate() : null,
3145
3216
  answered: plain.answered,
3146
3217
  callDirection: plain.call_direction,
3147
3218
  destination: {
@@ -3155,7 +3226,8 @@ class CallLog {
3155
3226
  id: plain.id,
3156
3227
  duration: (plain.duration || 0) * 1000, // duration is in seconds
3157
3228
  start: moment__default['default'](plain.start).toDate(),
3158
- end: moment__default['default'](plain.end).toDate(),
3229
+ end: plain.end ? moment__default['default'](plain.end).toDate() : null,
3230
+ recordings: Recording.parseMany(plain.recordings),
3159
3231
  // @TODO: FIXME add verification declined vs missed call
3160
3232
  newMissedCall: session
3161
3233
  && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered,
@@ -4391,6 +4463,10 @@ class ApiClient {
4391
4463
  this.fetchOptions = fetchOptions;
4392
4464
  this.client.setFetchOptions(fetchOptions);
4393
4465
  }
4466
+
4467
+ disableErrorLogging() {
4468
+ this.client.disableErrorLogging();
4469
+ }
4394
4470
  }
4395
4471
 
4396
4472
  var api = {
@@ -4398,6 +4474,7 @@ var api = {
4398
4474
  check: async (server, session) => {
4399
4475
  const client = new ApiClient({ server });
4400
4476
  client.setToken(session.token);
4477
+ client.disableErrorLogging();
4401
4478
 
4402
4479
  const handleApiError = (apiName, error) => {
4403
4480
  const statusText = error instanceof ServerError ? 'server error' : 'api error';
@@ -4472,6 +4549,8 @@ var aor = {
4472
4549
  check: async (server, session) => {
4473
4550
  const apiClient = new ApiClient({ server });
4474
4551
  apiClient.setToken(session.token);
4552
+ apiClient.disableErrorLogging();
4553
+
4475
4554
  const line = session.primaryWebRtcLine();
4476
4555
  if (!line) {
4477
4556
  return 'No WebRTC line for this user';
@@ -5082,23 +5161,6 @@ const areCandidateValid = (candidates ) =>
5082
5161
  getSrflxOrRelay(candidates)
5083
5162
  .length > 0;
5084
5163
 
5085
- const toggleVideoDirection = (sdp , direction ) => {
5086
- const parsedSdp = sdpParser__default['default'].parse(sdp);
5087
- parsedSdp.media = parsedSdp.media.map(media => ({
5088
- ...media,
5089
- ...(media.type === 'video' ? { direction } : {}),
5090
- }));
5091
-
5092
- return sdpParser__default['default'].write(parsedSdp);
5093
- };
5094
-
5095
- const deactivateVideoModifier = (rawDescription ) => {
5096
- const description = rawDescription;
5097
- description.sdp = toggleVideoDirection(description.sdp, 'inactive');
5098
-
5099
- return Promise.resolve(description);
5100
- };
5101
-
5102
5164
  const hasAnActiveVideo = (sdp ) => {
5103
5165
  if (!sdp) {
5104
5166
  return false;
@@ -5210,6 +5272,7 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5210
5272
  const iceRestart = options.offerOptions ? options.offerOptions.iceRestart : false;
5211
5273
 
5212
5274
  const isConference = options ? !!options.conference : false;
5275
+ const audioOnly = options ? !!options.audioOnly : false;
5213
5276
 
5214
5277
  // We should wait for ice when iceRestart (reinvite) or for the first invite
5215
5278
  // We shouldn't wait for ice when holding or resuming the call
@@ -5236,16 +5299,16 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5236
5299
  };
5237
5300
 
5238
5301
  return this.getLocalMediaStream(options)
5239
- .then(() => this.updateDirection(options, isConference))
5302
+ .then(() => this.updateDirection(options, isConference, audioOnly))
5240
5303
  .then(() => this.createDataChannel(options))
5241
5304
  .then(() => {
5242
- if (isConference && (options.constraints && !options.constraints.video) && !('hold' in options)) {
5305
+ if (isConference && (options.constraints && !options.constraints.video) && !('hold' in options) && !audioOnly) {
5243
5306
  // Add a video an empty bundle to be able to replaceTrack when joining a conference without video
5244
5307
  this.peerConnection.addTransceiver('video', { streams: [this._localMediaStream], direction: 'sendrecv' });
5245
5308
  }
5246
5309
  })
5247
5310
  .then(() => this.createLocalOfferOrAnswer(options))
5248
- .then((sessionDescription) => this.setLocalSessionDescription(sessionDescription))
5311
+ .then(sessionDescription => this.setLocalSessionDescription(sessionDescription))
5249
5312
  .then(() => this.waitForIceGatheringComplete(iceRestart, iceTimeout))
5250
5313
  .then(() => this.getLocalSessionDescription())
5251
5314
  .then(description => {
@@ -5368,7 +5431,8 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5368
5431
  }
5369
5432
 
5370
5433
  // Overridden to send `inactive` in conference
5371
- updateDirection(options , isConference = false) {
5434
+ updateDirection(options , isConference = false,
5435
+ audioOnly = false) {
5372
5436
  if (this._peerConnection === undefined) {
5373
5437
  return Promise.reject(new Error('Peer connection closed.'));
5374
5438
  }
@@ -5383,14 +5447,17 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5383
5447
  // if we are stable, assume we are creating a local offer
5384
5448
  this.logger.debug('SessionDescriptionHandler.updateDirection - setting offer direction');
5385
5449
  // determine the direction to offer given the current direction and hold state
5386
- const directionToOffer = (currentDirection ) => {
5450
+ const directionToOffer = (currentDirection , transceiver /* RTCRtpTransceiver */) => {
5387
5451
  if (isConference) {
5452
+ if (audioOnly && transceiver.receiver.track && transceiver.receiver.track.kind === 'video') {
5453
+ return 'sendonly';
5454
+ }
5388
5455
  return options && options.hold ? 'sendonly' : 'sendrecv';
5389
5456
  }
5390
5457
 
5391
5458
  switch (currentDirection) {
5392
5459
  case 'inactive':
5393
- return options && options.hold ? 'inactive' : 'recvonly';
5460
+ return options && options.hold ? 'inactive' : (isConference && !audioOnly ? 'sendrecv' : 'recvonly');
5394
5461
  case 'recvonly':
5395
5462
  return options && options.hold ? 'inactive' : 'recvonly';
5396
5463
  case 'sendonly':
@@ -5406,7 +5473,7 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5406
5473
  // set the transceiver direction to the offer direction
5407
5474
  this._peerConnection.getTransceivers().forEach((transceiver) => {
5408
5475
  if (transceiver.direction /* guarding, but should always be true */) {
5409
- const offerDirection = directionToOffer(transceiver.direction);
5476
+ const offerDirection = directionToOffer(transceiver.direction, transceiver);
5410
5477
  if (transceiver.direction !== offerDirection) {
5411
5478
  // eslint-disable-next-line no-param-reassign
5412
5479
  transceiver.direction = offerDirection;
@@ -5465,6 +5532,13 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5465
5532
  // set the transceiver direction to the answer direction
5466
5533
  this._peerConnection.getTransceivers().forEach((transceiver) => {
5467
5534
  if (transceiver.direction /* guarding, but should always be true */) {
5535
+ const { receiver } = transceiver;
5536
+ if (isConference && audioOnly && receiver.track && receiver.track.kind === 'video') {
5537
+ // eslint-disable-next-line no-param-reassign
5538
+ transceiver.direction = 'inactive';
5539
+ return;
5540
+ }
5541
+
5468
5542
  if (transceiver.direction !== 'stopped' && transceiver.direction !== answerDirection) {
5469
5543
  // eslint-disable-next-line no-param-reassign
5470
5544
  transceiver.direction = answerDirection;
@@ -5503,8 +5577,8 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5503
5577
  }
5504
5578
  const sender = pc.getSenders().find((otherSender) => otherSender.track && otherSender.track.kind === kind);
5505
5579
 
5506
- // Do not reuse sender tracks in SFU
5507
- if (sender && !sfu) {
5580
+ // Do not reuse sender video tracks in SFU
5581
+ if (sender && (!sfu || newTrack.kind === 'audio')) {
5508
5582
  trackUpdates.push(
5509
5583
  new Promise((resolve) => {
5510
5584
  this.logger.debug(`SessionDescriptionHandler.setLocalMediaStream - replacing sender ${kind} track`);
@@ -5958,9 +6032,15 @@ class WebRTCClient extends Emitter {
5958
6032
 
5959
6033
  call(number , enableVideo , audioOnly = false, conference = false) {
5960
6034
  logger.info('sdk webrtc creating call', { number, enableVideo, audioOnly });
5961
- const inviterOptions = {};
6035
+ const inviterOptions = {
6036
+ sessionDescriptionHandlerOptionsReInvite: {
6037
+ conference,
6038
+ audioOnly,
6039
+ },
6040
+ };
6041
+
5962
6042
  if (audioOnly) {
5963
- inviterOptions.sessionDescriptionHandlerModifiersReInvite = [deactivateVideoModifier];
6043
+ inviterOptions.sessionDescriptionHandlerModifiersReInvite = [modifiers.stripVideo];
5964
6044
  }
5965
6045
 
5966
6046
  const session = new inviter.Inviter(this.userAgent, this._makeURI(number), inviterOptions);
@@ -5989,10 +6069,11 @@ class WebRTCClient extends Emitter {
5989
6069
  sessionDescriptionHandlerOptions: this.getMediaConfiguration(enableVideo || false, conference),
5990
6070
  };
5991
6071
 
5992
- inviteOptions.sessionDescriptionHandlerModifiers = [replaceLocalIpModifier];
6072
+ inviteOptions.sessionDescriptionHandlerOptions.audioOnly = audioOnly;
5993
6073
 
6074
+ inviteOptions.sessionDescriptionHandlerModifiers = [replaceLocalIpModifier];
5994
6075
  if (audioOnly) {
5995
- inviteOptions.sessionDescriptionHandlerModifiers.push(deactivateVideoModifier);
6076
+ inviteOptions.sessionDescriptionHandlerModifiers.push(modifiers.stripVideo);
5996
6077
  }
5997
6078
 
5998
6079
  // Do not await invite here or we'll miss the Establishing state transition
@@ -6206,6 +6287,9 @@ class WebRTCClient extends Emitter {
6206
6287
  if (!this._isWeb()) {
6207
6288
  options.sessionDescriptionHandlerModifiers = [modifiers.holdModifier];
6208
6289
  }
6290
+ options.sessionDescriptionHandlerOptions = {
6291
+ constraints: options.constraints,
6292
+ };
6209
6293
 
6210
6294
  // Send re-INVITE
6211
6295
  return session.invite(options);
@@ -6245,6 +6329,9 @@ class WebRTCClient extends Emitter {
6245
6329
  // (eg: holdModifier)
6246
6330
  options.sessionDescriptionHandlerModifiers = [];
6247
6331
  }
6332
+ options.sessionDescriptionHandlerOptions = {
6333
+ constraints: options.constraints,
6334
+ };
6248
6335
 
6249
6336
  // Send re-INVITE
6250
6337
  return session.invite(options);
@@ -6474,7 +6561,8 @@ class WebRTCClient extends Emitter {
6474
6561
  ? this.video.deviceId.exact : undefined;
6475
6562
  }
6476
6563
 
6477
- reinvite(sipSession , newConstraints = null, conference = false) {
6564
+ reinvite(sipSession , newConstraints = null, conference = false,
6565
+ audioOnly = false) {
6478
6566
  if (!sipSession) {
6479
6567
  return false;
6480
6568
  }
@@ -6484,16 +6572,17 @@ class WebRTCClient extends Emitter {
6484
6572
  }
6485
6573
 
6486
6574
  const wasMuted = this.isAudioMuted(sipSession);
6487
- // When upgrading to video, remove the `deactivateVideoModifier` modifiers
6575
+ // When upgrading to video, remove the `stripVideo` modifiers
6488
6576
  if (newConstraints && newConstraints.video) {
6489
- const modifiers = sipSession.sessionDescriptionHandlerModifiersReInvite;
6490
- sipSession.sessionDescriptionHandlerModifiersReInvite = modifiers.filter(modifier =>
6491
- modifier !== deactivateVideoModifier);
6577
+ const modifiers$1 = sipSession.sessionDescriptionHandlerModifiersReInvite;
6578
+ sipSession.sessionDescriptionHandlerModifiersReInvite = modifiers$1.filter(modifier =>
6579
+ modifier !== modifiers.stripVideo);
6492
6580
  }
6493
6581
 
6494
6582
  sipSession.sessionDescriptionHandlerOptionsReInvite = {
6495
6583
  ...sipSession.sessionDescriptionHandlerOptionsReInvite,
6496
6584
  conference,
6585
+ audioOnly,
6497
6586
  };
6498
6587
 
6499
6588
  const shouldDoVideo = newConstraints ? newConstraints.video : this.sessionWantsToDoVideo(sipSession);
@@ -6533,6 +6622,8 @@ class WebRTCClient extends Emitter {
6533
6622
  },
6534
6623
  sessionDescriptionHandlerOptions: {
6535
6624
  constraints,
6625
+ conference,
6626
+ audioOnly,
6536
6627
  offerOptions: {
6537
6628
  iceRestart: false,
6538
6629
  },
@@ -6992,6 +7083,8 @@ class WebRTCClient extends Emitter {
6992
7083
 
6993
7084
  // Invitation and Inviter extends Session
6994
7085
  _setupSession(session ) {
7086
+ const sipSessionId = this.getSipSessionId(session);
7087
+
6995
7088
  // When receiving an Invitation, the delegate is not defined.
6996
7089
  if (!session.delegate) {
6997
7090
  session.delegate = {};
@@ -7015,8 +7108,18 @@ class WebRTCClient extends Emitter {
7015
7108
  };
7016
7109
  };
7017
7110
 
7111
+ const oldInviteRequest = session.onInviteRequest.bind(session);
7112
+ let hadRemoteVideo = false;
7113
+
7114
+ // Monkey patch `onInviteRequest` to be able to know if there was a remote video stream before `onInvite` is called
7115
+ // Becase when `onInvite` is called we already got the video track
7116
+ session.onInviteRequest = (request) => {
7117
+ hadRemoteVideo = this.hasARemoteVideoTrack(sipSessionId);
7118
+
7119
+ oldInviteRequest(request);
7120
+ };
7121
+
7018
7122
  session.delegate.onInvite = (request ) => {
7019
- const sipSessionId = this.getSipSessionId(session);
7020
7123
  let updatedCalleeName = null;
7021
7124
  let updatedNumber = null;
7022
7125
  if (session.assertedIdentity) {
@@ -7026,7 +7129,6 @@ class WebRTCClient extends Emitter {
7026
7129
  logger.info('re-invite received', { updatedCalleeName, updatedNumber });
7027
7130
 
7028
7131
  // Useful to know if it's a video upgrade or an unhold from a remote peer with a video stream
7029
- const hadRemoteVideo = this.hasARemoteVideoTrack(sipSessionId);
7030
7132
 
7031
7133
  // Update SDP
7032
7134
  // Remote video is handled by the `track` event. Here we're dealing with video stream removal.
@@ -7076,7 +7178,7 @@ class WebRTCClient extends Emitter {
7076
7178
  }
7077
7179
 
7078
7180
  _isAudioOnly(session ) {
7079
- return session.sessionDescriptionHandlerModifiersReInvite.find(modifier => modifier === deactivateVideoModifier);
7181
+ return session.sessionDescriptionHandlerModifiersReInvite.find(modifier => modifier === modifiers.stripVideo);
7080
7182
  }
7081
7183
 
7082
7184
  _setupMedias(session , newStream ) {
@@ -308,7 +308,13 @@ class IssueReporter {
308
308
  }
309
309
 
310
310
  _isLevelAbove(level1 , level2 ) {
311
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
311
+ const index1 = LOG_LEVELS.indexOf(level1);
312
+ const index2 = LOG_LEVELS.indexOf(level2);
313
+ if (index1 === -1 || index2 === -1) {
314
+ return false;
315
+ }
316
+
317
+ return index1 > index2;
312
318
  }
313
319
 
314
320
  _makeCategory(category ) {