@wazo/sdk 0.37.0 → 0.37.4

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 (144) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +91 -23
  3. package/esm/__tests__/web-rtc-client.test.js +165 -56
  4. package/esm/api/agentd.js +7 -1
  5. package/esm/api/amid.js +7 -1
  6. package/esm/api/application.js +7 -1
  7. package/esm/api/auth.js +7 -1
  8. package/esm/api/call-logd.js +17 -23
  9. package/esm/api/calld.js +10 -18
  10. package/esm/api/chatd.js +7 -1
  11. package/esm/api/confd.js +78 -1
  12. package/esm/api/ctid-ng.js +7 -1
  13. package/esm/api/dird.js +7 -1
  14. package/esm/api/webhookd.js +7 -1
  15. package/esm/api-client.js +91 -23
  16. package/esm/checker/Checker.js +169 -56
  17. package/esm/checker/checks/aor.js +91 -23
  18. package/esm/checker/checks/api.js +91 -23
  19. package/esm/checker/checks/index.js +169 -56
  20. package/esm/checker/checks/wazo-websocket.js +11 -1
  21. package/esm/checker/checks/webrtc-transport.js +165 -56
  22. package/esm/checker/checks/webrtc.js +165 -56
  23. package/esm/domain/AdHocAPIConference.js +1722 -1654
  24. package/esm/domain/CallLog.js +10 -22
  25. package/esm/domain/CallSession.js +1 -18
  26. package/esm/domain/Features.js +91 -23
  27. package/esm/domain/IndirectTransfer.js +0 -17
  28. package/esm/domain/Meeting.js +71 -0
  29. package/esm/domain/Phone/CTIPhone.js +98 -26
  30. package/esm/domain/Phone/Phone.js +0 -17
  31. package/esm/domain/Phone/WebRTCPhone.js +47 -27
  32. package/esm/domain/Room.js +0 -17
  33. package/esm/domain/SwitchboardCall.js +0 -17
  34. package/esm/domain/__tests__/CallLog.test.js +10 -22
  35. package/esm/domain/__tests__/CallSession.test.js +1 -18
  36. package/esm/domain/__tests__/IndirectTransfer.test.js +1 -18
  37. package/esm/domain/__tests__/Room.test.js +1 -18
  38. package/esm/index.js +3880 -3111
  39. package/esm/lib/WazoSessionDescriptionHandler.js +24 -10
  40. package/esm/service/CallApi.js +91 -23
  41. package/esm/service/IssueReporter.js +7 -1
  42. package/esm/service/__tests__/IssueReporter.test.js +9 -1
  43. package/esm/service/getApiClient.js +91 -23
  44. package/esm/simple/Auth.js +1126 -360
  45. package/esm/simple/Configuration.js +1126 -360
  46. package/esm/simple/Directory.js +91 -23
  47. package/esm/simple/Phone.js +3724 -2958
  48. package/esm/simple/Websocket.js +13 -1
  49. package/esm/simple/index.js +1128 -362
  50. package/esm/simple/room/LocalParticipant.js +1097 -331
  51. package/esm/simple/room/Participant.js +1097 -331
  52. package/esm/simple/room/RemoteParticipant.js +1097 -331
  53. package/esm/simple/room/Room.js +1097 -331
  54. package/esm/simple/room/SipRoom.js +12996 -0
  55. package/esm/simple/room/Stream.js +1128 -362
  56. package/esm/simple/room/__tests__/RemoteParticipant.test.js +5157 -4389
  57. package/esm/simple/utils.js +1128 -362
  58. package/esm/utils/__tests__/api-requester.test.js +7 -1
  59. package/esm/utils/api-requester.js +7 -1
  60. package/esm/web-rtc-client.js +165 -56
  61. package/esm/websocket-client.js +12 -2
  62. package/lib/__tests__/api-client.test.js +91 -23
  63. package/lib/__tests__/web-rtc-client.test.js +165 -56
  64. package/lib/api/agentd.js +7 -1
  65. package/lib/api/amid.js +7 -1
  66. package/lib/api/application.js +7 -1
  67. package/lib/api/auth.js +7 -1
  68. package/lib/api/call-logd.js +17 -23
  69. package/lib/api/calld.js +10 -18
  70. package/lib/api/chatd.js +7 -1
  71. package/lib/api/confd.js +78 -1
  72. package/lib/api/ctid-ng.js +7 -1
  73. package/lib/api/dird.js +7 -1
  74. package/lib/api/webhookd.js +7 -1
  75. package/lib/api-client.js +91 -23
  76. package/lib/checker/Checker.js +169 -56
  77. package/lib/checker/checks/aor.js +91 -23
  78. package/lib/checker/checks/api.js +91 -23
  79. package/lib/checker/checks/index.js +169 -56
  80. package/lib/checker/checks/wazo-websocket.js +11 -1
  81. package/lib/checker/checks/webrtc-transport.js +165 -56
  82. package/lib/checker/checks/webrtc.js +165 -56
  83. package/lib/domain/AdHocAPIConference.js +1722 -1654
  84. package/lib/domain/CallLog.js +10 -22
  85. package/lib/domain/CallSession.js +1 -18
  86. package/lib/domain/Features.js +91 -23
  87. package/lib/domain/IndirectTransfer.js +0 -17
  88. package/lib/domain/Meeting.js +73 -0
  89. package/lib/domain/Phone/CTIPhone.js +98 -26
  90. package/lib/domain/Phone/Phone.js +0 -16
  91. package/lib/domain/Phone/WebRTCPhone.js +47 -27
  92. package/lib/domain/Room.js +0 -17
  93. package/lib/domain/SwitchboardCall.js +0 -17
  94. package/lib/domain/__tests__/CallLog.test.js +10 -22
  95. package/lib/domain/__tests__/CallSession.test.js +1 -18
  96. package/lib/domain/__tests__/IndirectTransfer.test.js +1 -18
  97. package/lib/domain/__tests__/Room.test.js +1 -18
  98. package/lib/index.js +3880 -3111
  99. package/lib/lib/WazoSessionDescriptionHandler.js +24 -10
  100. package/lib/service/CallApi.js +91 -23
  101. package/lib/service/IssueReporter.js +7 -1
  102. package/lib/service/__tests__/IssueReporter.test.js +9 -1
  103. package/lib/service/getApiClient.js +91 -23
  104. package/lib/simple/Auth.js +1126 -360
  105. package/lib/simple/Configuration.js +1126 -360
  106. package/lib/simple/Directory.js +91 -23
  107. package/lib/simple/Phone.js +3724 -2958
  108. package/lib/simple/Websocket.js +13 -1
  109. package/lib/simple/index.js +1128 -362
  110. package/lib/simple/room/LocalParticipant.js +1097 -331
  111. package/lib/simple/room/Participant.js +1097 -331
  112. package/lib/simple/room/RemoteParticipant.js +1097 -331
  113. package/lib/simple/room/Room.js +1097 -331
  114. package/lib/simple/room/SipRoom.js +13006 -0
  115. package/lib/simple/room/Stream.js +1128 -362
  116. package/lib/simple/room/__tests__/RemoteParticipant.test.js +5157 -4389
  117. package/lib/simple/utils.js +1128 -362
  118. package/lib/utils/__tests__/api-requester.test.js +7 -1
  119. package/lib/utils/api-requester.js +7 -1
  120. package/lib/web-rtc-client.js +165 -56
  121. package/lib/websocket-client.js +13 -1
  122. package/package.json +1 -1
  123. package/src/api/calld.js +3 -0
  124. package/src/api/confd.js +13 -0
  125. package/src/domain/CallLog.js +10 -22
  126. package/src/domain/CallSession.js +1 -2
  127. package/src/domain/Meeting.js +59 -0
  128. package/src/domain/Phone/CTIPhone.js +6 -2
  129. package/src/domain/Phone/Phone.js +2 -0
  130. package/src/domain/Phone/WebRTCPhone.js +22 -8
  131. package/src/index.js +6 -0
  132. package/src/lib/WazoSessionDescriptionHandler.js +17 -9
  133. package/src/service/IssueReporter.js +7 -1
  134. package/src/service/__tests__/IssueReporter.test.js +2 -0
  135. package/src/simple/Phone.js +13 -4
  136. package/src/simple/index.js +8 -0
  137. package/src/simple/room/Participant.js +7 -0
  138. package/src/simple/room/Room.js +157 -79
  139. package/src/simple/room/SipRoom.js +147 -0
  140. package/src/simple/room/Stream.js +1 -3
  141. package/src/simple/room/__tests__/RemoteParticipant.test.js +3 -2
  142. package/src/types/WebSocketMessage.js +21 -0
  143. package/src/web-rtc-client.js +57 -24
  144. package/src/websocket-client.js +4 -0
@@ -200,7 +200,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
200
200
  });
201
201
 
202
202
  if (!sipSession) {
203
- return null;
203
+ return false;
204
204
  }
205
205
 
206
206
  // $FlowFixMe
@@ -210,19 +210,17 @@ export default class WebRTCPhone extends Emitter implements Phone {
210
210
  // Downgrade
211
211
  if (constraints && !isUpgrade) {
212
212
  // No reinvite needed
213
- return this._downgradeToAudio(callSession);
213
+ this._downgradeToAudio(callSession);
214
+ return false;
214
215
  }
215
216
 
216
217
  if (isUpgrade) {
217
218
  const shouldReinvite = await this._upgradeToVideo(callSession, constraints, conference);
218
219
  if (!shouldReinvite) {
219
- return;
220
+ return false;
220
221
  }
221
222
  }
222
223
 
223
- // Force reinvite in SDH
224
- sipSession.sessionDescriptionHandler.localMediaStreamConstraints = null;
225
-
226
224
  return this.client.reinvite(sipSession, constraints, conference, audioOnly);
227
225
  }
228
226
 
@@ -295,7 +293,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
295
293
  _downgradeToAudio(callSession: ?CallSession) {
296
294
  const sipSession = this.findSipSession(callSession);
297
295
  if (!sipSession) {
298
- return;
296
+ return false;
299
297
  }
300
298
 
301
299
  // Release local video stream when downgrading to audio
@@ -499,6 +497,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
499
497
  localStream.removeTrack(videoTrack);
500
498
  }
501
499
 
500
+ if (localStream) {
501
+ localStream.addTrack(screenTrack);
502
+ }
503
+
502
504
  if (sender) {
503
505
  sender.replaceTrack(screenTrack);
504
506
  }
@@ -514,6 +516,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
514
516
  }
515
517
 
516
518
  logger.info('WebRTC phone - stop screen sharing');
519
+ let reinvited = false;
517
520
 
518
521
  try {
519
522
  if (this.currentScreenShare.stream) {
@@ -528,7 +531,8 @@ export default class WebRTCPhone extends Emitter implements Phone {
528
531
  // When upgrading directly to screenshare (eg: we don't have a videoLocalStream to replace)
529
532
  // We have to downgrade to audio.
530
533
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
531
- await this.sendReinvite(targetCallSession, { audio: false, video: screenshareStopped }, conference);
534
+ const constraints = { audio: false, video: screenshareStopped };
535
+ reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
532
536
  }
533
537
  } catch (e) {
534
538
  console.warn(e);
@@ -542,6 +546,8 @@ export default class WebRTCPhone extends Emitter implements Phone {
542
546
  );
543
547
 
544
548
  this.currentScreenShare = null;
549
+
550
+ return reinvited;
545
551
  }
546
552
 
547
553
  async _getStreamFromConstraints(constraints: Object, conference: boolean = false): Promise<?MediaStream> {
@@ -602,6 +608,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
602
608
  this.client.changeAudioOutputDevice(id);
603
609
  }
604
610
 
611
+ createAudioElementFor(sessionId: string) {
612
+ return this.client.createAudioElementFor(sessionId);
613
+ }
614
+
605
615
  changeRingDevice(id: string) {
606
616
  this.audioRingDeviceId = id;
607
617
  }
@@ -1249,6 +1259,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
1249
1259
  return callSession ? this.client.hasLocalVideo(callSession.sipCallId) : null;
1250
1260
  }
1251
1261
 
1262
+ hasALocalVideoTrack(callSession: CallSession) {
1263
+ return callSession ? this.client.hasALocalVideoTrack(callSession.sipCallId) : null;
1264
+ }
1265
+
1252
1266
  getRemoteStream(callSession: CallSession): ?MediaStream {
1253
1267
  return callSession ? this.client.getRemoteStream(callSession.sipCallId) : null;
1254
1268
  }
package/src/index.js CHANGED
@@ -28,6 +28,9 @@ import Room from './domain/Room';
28
28
  import CallSession from './domain/CallSession';
29
29
  import IndirectTransfer from './domain/IndirectTransfer';
30
30
  import SwitchboardCall from './domain/SwitchboardCall';
31
+ import WebRTCPhone from './domain/Phone/WebRTCPhone';
32
+ import CTIPhone from './domain/Phone/CTIPhone';
33
+ import Meeting from './domain/Meeting';
31
34
  import type {
32
35
  NewContact as NewContactType,
33
36
  ContactResponse as ContactResponseType,
@@ -94,6 +97,7 @@ export default {
94
97
  ServerError,
95
98
  Call,
96
99
  CallSession,
100
+ CTIPhone,
97
101
  Features,
98
102
  IndirectTransfer,
99
103
  SwitchboardCall,
@@ -118,4 +122,6 @@ export default {
118
122
  LINE_STATE,
119
123
  SOCKET_EVENTS,
120
124
  Wazo,
125
+ WebRTCPhone,
126
+ Meeting,
121
127
  };
@@ -116,7 +116,9 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
116
116
  .then(() => {
117
117
  if (isConference && (options.constraints && !options.constraints.video) && !('hold' in options) && !audioOnly) {
118
118
  // Add a video an empty bundle to be able to replaceTrack when joining a conference without video
119
- this.peerConnection.addTransceiver('video', { streams: [this._localMediaStream], direction: 'sendrecv' });
119
+ if (this.peerConnection.addTransceiver) {
120
+ this.peerConnection.addTransceiver('video', { streams: [this._localMediaStream], direction: 'sendrecv' });
121
+ }
120
122
  }
121
123
  })
122
124
  .then(() => this.createLocalOfferOrAnswer(options))
@@ -143,12 +145,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
143
145
  };
144
146
  })
145
147
  .then((sessionDescription) => this.applyModifiers(sessionDescription, modifiers))
146
- .then((sessionDescription) => {
147
- // Set new constraints to avoid the constraints check issue in `sdh.getLocalMediaStream` later.
148
- this.localMediaStreamConstraints = options.constraints;
149
-
150
- return sessionDescription;
151
- })
152
148
  .then((sessionDescription) => ({ body: sessionDescription.sdp, contentType: 'application/sdp' }))
153
149
  .catch((error) => {
154
150
  wazoLogger.error('error when creating media', error);
@@ -343,6 +339,9 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
343
339
 
344
340
  // set the transceiver direction to the answer direction
345
341
  this._peerConnection.getTransceivers().forEach((transceiver) => {
342
+ if (transceiver.stopped) {
343
+ return;
344
+ }
346
345
  if (transceiver.direction /* guarding, but should always be true */) {
347
346
  const { receiver } = transceiver;
348
347
  if (isConference && audioOnly && receiver.track && receiver.track.kind === 'video') {
@@ -387,10 +386,15 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
387
386
  if (kind !== 'audio' && kind !== 'video') {
388
387
  throw new Error(`Unknown new track kind ${kind}.`);
389
388
  }
390
- const sender = pc.getSenders().find((otherSender) => otherSender.track && otherSender.track.kind === kind);
389
+ const sender = pc.getSenders && pc.getSenders().find((otherSender) =>
390
+ otherSender.track && otherSender.track.kind === kind);
391
391
 
392
392
  // Do not reuse sender video tracks in SFU
393
393
  if (sender && (!sfu || newTrack.kind === 'audio')) {
394
+ if (sender.track) {
395
+ // eslint-disable-next-line no-param-reassign
396
+ newTrack.enabled = sender.track.enabled;
397
+ }
394
398
  trackUpdates.push(
395
399
  new Promise((resolve) => {
396
400
  this.logger.debug(`SessionDescriptionHandler.setLocalMediaStream - replacing sender ${kind} track`);
@@ -424,7 +428,11 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
424
428
  // Review: could make streamless tracks a configurable option?
425
429
  // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack#Usage_notes
426
430
  try {
427
- pc.addTrack(newTrack, localStream);
431
+ if (pc.addTrack) {
432
+ pc.addTrack(newTrack, localStream);
433
+ } else {
434
+ pc.addStream(localStream);
435
+ }
428
436
  } catch (error) {
429
437
  this.logger.error(`SessionDescriptionHandler.setLocalMediaStream - failed to add sender ${kind} track`);
430
438
  throw error;
@@ -243,7 +243,13 @@ class IssueReporter {
243
243
  }
244
244
 
245
245
  _isLevelAbove(level1: string, level2: string) {
246
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
246
+ const index1 = LOG_LEVELS.indexOf(level1);
247
+ const index2 = LOG_LEVELS.indexOf(level2);
248
+ if (index1 === -1 || index2 === -1) {
249
+ return false;
250
+ }
251
+
252
+ return index1 > index2;
247
253
  }
248
254
 
249
255
  _makeCategory(category: string) {
@@ -41,6 +41,8 @@ describe('IssueReporter', () => {
41
41
  expect(IssueReporter._isLevelAbove('error', 'warn')).toBeTruthy();
42
42
  expect(IssueReporter._isLevelAbove('info', 'warn')).toBeFalsy();
43
43
  expect(IssueReporter._isLevelAbove('trace', 'trace')).toBeFalsy();
44
+ expect(IssueReporter._isLevelAbove('trace', 'something')).toBeFalsy();
45
+ expect(IssueReporter._isLevelAbove('something', 'trace')).toBeFalsy();
44
46
  });
45
47
 
46
48
  it('should send if verbosity is higher than required', () => {
@@ -171,13 +171,18 @@ class Phone extends Emitter {
171
171
  return adHocConference.start();
172
172
  }
173
173
 
174
- mute(callSession: CallSession) {
175
- this.muteViaAPI(callSession);
174
+ mute(callSession: CallSession, withApi: boolean = true) {
175
+ if (withApi) {
176
+ this.muteViaAPI(callSession);
177
+ }
178
+
176
179
  return this.phone && this.phone.mute(callSession);
177
180
  }
178
181
 
179
- unmute(callSession: CallSession) {
180
- this.unmuteViaAPI(callSession);
182
+ unmute(callSession: CallSession, withApi: boolean = true) {
183
+ if (withApi) {
184
+ this.unmuteViaAPI(callSession);
185
+ }
181
186
 
182
187
  return this.phone && this.phone.unmute(callSession);
183
188
  }
@@ -283,6 +288,10 @@ class Phone extends Emitter {
283
288
  return this.phone && this.phone.hasLocalVideo(callSession);
284
289
  }
285
290
 
291
+ hasALocalVideoTrack(callSession: CallSession) {
292
+ return this.phone && this.phone.hasALocalVideoTrack(callSession);
293
+ }
294
+
286
295
  // @Deprecated
287
296
  getLocalMediaStream(callSession: CallSession) {
288
297
  logger.warn('Phone.getLocalMediaStream is deprecated, use Phone.getLocalStream instead');
@@ -3,6 +3,7 @@ import Auth, { InvalidSubscription, InvalidAuthorization } from './Auth';
3
3
  import Phone from './Phone';
4
4
  import Websocket from './Websocket';
5
5
  import Room from './room/Room';
6
+ import SipRoom from './room/SipRoom';
6
7
  import RemoteParticipant from './room/RemoteParticipant';
7
8
  import LocalParticipant from './room/LocalParticipant';
8
9
  import Stream from './room/Stream';
@@ -29,10 +30,13 @@ import Voicemail from '../domain/Voicemail';
29
30
  import Relocation from '../domain/Relocation';
30
31
  import ConferenceRoom from '../domain/Room';
31
32
  import CallSession from '../domain/CallSession';
33
+ import WebRTCPhone from '../domain/Phone/WebRTCPhone';
34
+ import CTIPhone from '../domain/Phone/CTIPhone';
32
35
  import IndirectTransfer from '../domain/IndirectTransfer';
33
36
  import SwitchboardCall from '../domain/SwitchboardCall';
34
37
  import IssueReporter from '../service/IssueReporter';
35
38
  import Features from '../domain/Features';
39
+ import Meeting from '../domain/Meeting';
36
40
  import Checker from '../checker/Checker';
37
41
 
38
42
  const Wazo = {
@@ -40,6 +44,7 @@ const Wazo = {
40
44
  Phone,
41
45
  Websocket,
42
46
  Room,
47
+ SipRoom,
43
48
  RemoteParticipant,
44
49
  LocalParticipant,
45
50
  Stream,
@@ -59,6 +64,7 @@ const Wazo = {
59
64
  ServerError,
60
65
  Call,
61
66
  CallLog,
67
+ CTIPhone,
62
68
  Recording,
63
69
  ChatMessage,
64
70
  ChatRoom,
@@ -74,6 +80,8 @@ const Wazo = {
74
80
  CallSession,
75
81
  IndirectTransfer,
76
82
  SwitchboardCall,
83
+ WebRTCPhone,
84
+ Meeting,
77
85
  },
78
86
 
79
87
  // Api
@@ -3,6 +3,7 @@ import Emitter from '../../utils/Emitter';
3
3
  import IssueReporter from '../../service/IssueReporter';
4
4
 
5
5
  import Room, { SIGNAL_TYPE_PARTICIPANT_UPDATE } from './Room';
6
+ import Contact from '../../domain/Contact';
6
7
 
7
8
  const logger = IssueReporter.loggerFor('room');
8
9
 
@@ -38,6 +39,7 @@ class Participant extends Emitter {
38
39
  ON_RESUME: string;
39
40
 
40
41
  /**
42
+ * @param room Room The room where the participant is
41
43
  * @param rawParticipant string Participant sent via the Wazo WS
42
44
  * @param extra Object extra status of the participant
43
45
  */
@@ -267,6 +269,11 @@ class Participant extends Emitter {
267
269
  // Poor man's object comparison
268
270
  if (typeof status.extra !== 'undefined' && JSON.stringify(this.extra) !== JSON.stringify(status.extra)) {
269
271
  this.extra = { ...this.extra, ...status.extra };
272
+
273
+ if (this.extra.contact && !(this.extra.contact instanceof Contact)) {
274
+ this.extra.contact = new Contact(this.extra.contact);
275
+ }
276
+
270
277
  this.triggerUpdate(this.ON_EXTRA_CHANGE, broadcast);
271
278
  }
272
279
  }