@wazo/sdk 0.37.23 → 0.37.24

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 (103) hide show
  1. package/dist/wazo-sdk.js +6 -6
  2. package/esm/__tests__/api-client.test.js +22 -17
  3. package/esm/__tests__/web-rtc-client.test.js +105 -100
  4. package/esm/api/amid.js +1 -1
  5. package/esm/api/call-logd.js +2 -2
  6. package/esm/api/confd.js +10 -5
  7. package/esm/api/ctid-ng.js +3 -3
  8. package/esm/api/dird.js +1 -1
  9. package/esm/api/webhookd.js +1 -1
  10. package/esm/api-client.js +22 -17
  11. package/esm/checker/Checker.js +130 -125
  12. package/esm/checker/checks/aor.js +22 -17
  13. package/esm/checker/checks/api.js +22 -17
  14. package/esm/checker/checks/index.js +120 -115
  15. package/esm/checker/checks/wazo-websocket.js +15 -15
  16. package/esm/checker/checks/webrtc-transport.js +105 -100
  17. package/esm/checker/checks/webrtc.js +105 -100
  18. package/esm/domain/AdHocAPIConference.js +22 -17
  19. package/esm/domain/CallLog.js +1 -1
  20. package/esm/domain/Contact.js +1 -1
  21. package/esm/domain/Features.js +22 -17
  22. package/esm/domain/Meeting.js +12 -5
  23. package/esm/domain/Phone/CTIPhone.js +36 -31
  24. package/esm/domain/Phone/WebRTCPhone.js +110 -87
  25. package/esm/domain/__tests__/CallLog.test.js +1 -1
  26. package/esm/domain/__tests__/Contact.test.js +1 -1
  27. package/esm/domain/__tests__/Meeting.test.js +144 -0
  28. package/esm/index.js +365 -337
  29. package/esm/lib/WazoSessionDescriptionHandler.js +1 -1
  30. package/esm/service/CallApi.js +22 -17
  31. package/esm/service/IssueReporter.js +1 -1
  32. package/esm/service/__tests__/IssueReporter.test.js +1 -1
  33. package/esm/service/getApiClient.js +22 -17
  34. package/esm/simple/Auth.js +355 -327
  35. package/esm/simple/Configuration.js +355 -327
  36. package/esm/simple/Directory.js +22 -17
  37. package/esm/simple/Phone.js +355 -327
  38. package/esm/simple/Websocket.js +17 -17
  39. package/esm/simple/index.js +359 -331
  40. package/esm/simple/room/LocalParticipant.js +359 -331
  41. package/esm/simple/room/Participant.js +359 -331
  42. package/esm/simple/room/RemoteParticipant.js +359 -331
  43. package/esm/simple/room/Room.js +360 -332
  44. package/esm/simple/room/SipRoom.js +359 -331
  45. package/esm/simple/room/Stream.js +359 -331
  46. package/esm/simple/room/__tests__/RemoteParticipant.test.js +359 -331
  47. package/esm/simple/utils.js +359 -331
  48. package/esm/types/WebSocketMessage.js +1 -1
  49. package/esm/web-rtc-client.js +105 -100
  50. package/esm/websocket-client.js +15 -15
  51. package/lib/__tests__/api-client.test.js +22 -17
  52. package/lib/__tests__/web-rtc-client.test.js +105 -100
  53. package/lib/api/amid.js +1 -1
  54. package/lib/api/call-logd.js +2 -2
  55. package/lib/api/confd.js +10 -5
  56. package/lib/api/ctid-ng.js +3 -3
  57. package/lib/api/dird.js +1 -1
  58. package/lib/api/webhookd.js +1 -1
  59. package/lib/api-client.js +22 -17
  60. package/lib/checker/Checker.js +130 -125
  61. package/lib/checker/checks/aor.js +22 -17
  62. package/lib/checker/checks/api.js +22 -17
  63. package/lib/checker/checks/index.js +120 -115
  64. package/lib/checker/checks/wazo-websocket.js +15 -15
  65. package/lib/checker/checks/webrtc-transport.js +105 -100
  66. package/lib/checker/checks/webrtc.js +105 -100
  67. package/lib/domain/AdHocAPIConference.js +22 -17
  68. package/lib/domain/CallLog.js +1 -1
  69. package/lib/domain/Contact.js +1 -1
  70. package/lib/domain/Features.js +22 -17
  71. package/lib/domain/Meeting.js +16 -5
  72. package/lib/domain/Phone/CTIPhone.js +36 -31
  73. package/lib/domain/Phone/WebRTCPhone.js +110 -87
  74. package/lib/domain/__tests__/CallLog.test.js +1 -1
  75. package/lib/domain/__tests__/Contact.test.js +1 -1
  76. package/lib/domain/__tests__/Meeting.test.js +150 -0
  77. package/lib/index.js +365 -337
  78. package/lib/lib/WazoSessionDescriptionHandler.js +1 -1
  79. package/lib/service/CallApi.js +22 -17
  80. package/lib/service/IssueReporter.js +1 -1
  81. package/lib/service/__tests__/IssueReporter.test.js +1 -1
  82. package/lib/service/getApiClient.js +22 -17
  83. package/lib/simple/Auth.js +355 -327
  84. package/lib/simple/Configuration.js +355 -327
  85. package/lib/simple/Directory.js +22 -17
  86. package/lib/simple/Phone.js +355 -327
  87. package/lib/simple/Websocket.js +17 -17
  88. package/lib/simple/index.js +359 -331
  89. package/lib/simple/room/LocalParticipant.js +359 -331
  90. package/lib/simple/room/Participant.js +359 -331
  91. package/lib/simple/room/RemoteParticipant.js +359 -331
  92. package/lib/simple/room/Room.js +360 -332
  93. package/lib/simple/room/SipRoom.js +359 -331
  94. package/lib/simple/room/Stream.js +359 -331
  95. package/lib/simple/room/__tests__/RemoteParticipant.test.js +359 -331
  96. package/lib/simple/utils.js +359 -331
  97. package/lib/types/WebSocketMessage.js +2 -0
  98. package/lib/web-rtc-client.js +105 -100
  99. package/lib/websocket-client.js +15 -15
  100. package/package.json +1 -1
  101. package/src/domain/Meeting.js +12 -5
  102. package/src/domain/Phone/WebRTCPhone.js +24 -1
  103. package/src/domain/__tests__/Meeting.test.js +50 -0
@@ -45,7 +45,7 @@ const isMobile = () => typeof navigator !== 'undefined' && navigator.product ===
45
45
 
46
46
  /* */
47
47
 
48
- IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
48
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
49
49
 
50
50
  // Use a function here to be able to mock it in tests
51
51
  const realFetch = () => {
@@ -621,7 +621,7 @@ const BLACKLIST_EVENTS = [
621
621
  ];
622
622
 
623
623
  const HEARTBEAT_ENGINE_VERSION = '20.09';
624
- const logger = IssueReporter$1.loggerFor('wazo-ws');
624
+ const logger$1 = IssueReporter$1.loggerFor('wazo-ws');
625
625
  const messageLogger = IssueReporter$1.loggerFor('wazo-ws-message');
626
626
 
627
627
  class WebSocketClient extends Emitter {
@@ -670,19 +670,19 @@ class WebSocketClient extends Emitter {
670
670
  }
671
671
 
672
672
  connect() {
673
- logger.info('connect method started', { host: this.host, token: this.token });
673
+ logger$1.info('connect method started', { host: this.host, token: this.token });
674
674
  this.socket = new ReconnectingWebSocket__default['default'](this._getUrl.bind(this), [], this.options);
675
675
  if (this.options.binaryType) {
676
676
  this.socket.binaryType = this.options.binaryType;
677
677
  }
678
678
 
679
679
  this.socket.onopen = () => {
680
- logger.info('on Wazo WS open', { method: 'connect', host: this.host });
680
+ logger$1.info('on Wazo WS open', { method: 'connect', host: this.host });
681
681
  this.eventEmitter.emit(SOCKET_EVENTS.ON_OPEN);
682
682
  };
683
683
 
684
684
  this.socket.onerror = event => {
685
- logger.error('on Wazo WS error', event.target);
685
+ logger$1.error('on Wazo WS error', event.target);
686
686
  this.eventEmitter.emit(SOCKET_EVENTS.ON_ERROR, event);
687
687
  };
688
688
 
@@ -712,7 +712,7 @@ class WebSocketClient extends Emitter {
712
712
 
713
713
  this.socket.onclose = event => {
714
714
  // Can't be converted to JSON (circular structure)
715
- logger.info('on Wazo WS close', {
715
+ logger$1.info('on Wazo WS close', {
716
716
  reason: event.reason,
717
717
  code: event.code,
718
718
  readyState: event.target.readyState,
@@ -730,12 +730,12 @@ class WebSocketClient extends Emitter {
730
730
  };
731
731
 
732
732
  this.socket.onerror = event => {
733
- logger.info('Wazo WS error', { message: event.message, code: event.code, readyState: event.target.readyState });
733
+ logger$1.info('Wazo WS error', { message: event.message, code: event.code, readyState: event.target.readyState });
734
734
  };
735
735
  }
736
736
 
737
737
  close(force = false) {
738
- logger.info('Wazo WS close', { socket: !!this.socket, host: this.host, token: this.token });
738
+ logger$1.info('Wazo WS close', { socket: !!this.socket, host: this.host, token: this.token });
739
739
 
740
740
  if (!this.socket) {
741
741
  return;
@@ -753,7 +753,7 @@ class WebSocketClient extends Emitter {
753
753
 
754
754
  updateToken(token ) {
755
755
  this.token = token;
756
- logger.info('Wazo WS updating token', { url: this._getUrl(), token, socket: !!this.socket });
756
+ logger$1.info('Wazo WS updating token', { url: this._getUrl(), token, socket: !!this.socket });
757
757
 
758
758
  if (this.socket) {
759
759
  // If still connected, send the token to the WS
@@ -771,7 +771,7 @@ class WebSocketClient extends Emitter {
771
771
  }
772
772
 
773
773
  startHeartbeat() {
774
- logger.info('Wazo WS start heartbeat', { host: this.host, token: this.token });
774
+ logger$1.info('Wazo WS start heartbeat', { host: this.host, token: this.token });
775
775
 
776
776
  if (!this.socket) {
777
777
  this.heartbeat.stop();
@@ -785,7 +785,7 @@ class WebSocketClient extends Emitter {
785
785
  }
786
786
 
787
787
  stopHeartbeat() {
788
- logger.info('Wazo WS stop heartbeat', { host: this.host, token: this.token });
788
+ logger$1.info('Wazo WS stop heartbeat', { host: this.host, token: this.token });
789
789
 
790
790
  this.heartbeat.stop();
791
791
  }
@@ -815,7 +815,7 @@ class WebSocketClient extends Emitter {
815
815
  }
816
816
 
817
817
  reconnect(reason ) {
818
- logger.info('Wazo WS reconnect', { reason, socket: !!this.socket, host: this.host, token: this.token });
818
+ logger$1.info('Wazo WS reconnect', { reason, socket: !!this.socket, host: this.host, token: this.token });
819
819
  if (!this.socket) {
820
820
  return;
821
821
  }
@@ -871,7 +871,7 @@ class WebSocketClient extends Emitter {
871
871
  this.close();
872
872
  }
873
873
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
874
- logger.log('Wazo WS url computed to reconnect', { url });
874
+ logger$1.log('Wazo WS url computed to reconnect', { url });
875
875
 
876
876
  return url;
877
877
  }
@@ -879,12 +879,12 @@ class WebSocketClient extends Emitter {
879
879
  _onHeartbeat(message ) {
880
880
  if (message.payload === 'pong') {
881
881
  this.heartbeat.onHeartbeat();
882
- logger.log('on heartbeat received from Wazo WS');
882
+ logger$1.log('on heartbeat received from Wazo WS');
883
883
  }
884
884
  }
885
885
 
886
886
  async _onHeartbeatTimeout() {
887
- logger.log('heartbeat timed out', { host: this.host, token: this.token });
887
+ logger$1.log('heartbeat timed out', { host: this.host, token: this.token });
888
888
 
889
889
  this.close();
890
890
  this.eventEmitter.emit(SOCKET_EVENTS.ON_CLOSE, new Error('Websocket ping failure.'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.37.23",
3
+ "version": "0.37.24",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
@@ -1,4 +1,6 @@
1
1
  // @flow
2
+ import moment from 'moment';
3
+
2
4
  import newFrom from '../utils/new-from';
3
5
 
4
6
  export type MeetingCreationResponse = {
@@ -8,8 +10,9 @@ export type MeetingCreationResponse = {
8
10
  owner_uuids: Array<string>,
9
11
  port: string,
10
12
  uuid: string,
11
- number: string,
13
+ exten: string,
12
14
  persistent: boolean,
15
+ creation_time: string,
13
16
  }
14
17
 
15
18
  export default class Meeting {
@@ -20,9 +23,10 @@ export default class Meeting {
20
23
  uuid: string;
21
24
  name: string;
22
25
  port: string;
23
- number: string;
26
+ extension: string;
24
27
  persistent: boolean;
25
28
  ownerUuids: Array<string>;
29
+ creationTime: Date;
26
30
 
27
31
  static parse(plain: MeetingCreationResponse): Meeting {
28
32
  return new Meeting({
@@ -32,8 +36,9 @@ export default class Meeting {
32
36
  ownerUuids: plain.owner_uuids,
33
37
  port: plain.port,
34
38
  uuid: plain.uuid,
35
- number: plain.number,
39
+ extension: plain.exten,
36
40
  persistent: plain.persistent,
41
+ creationTime: moment(plain.creation_time).toDate(),
37
42
  });
38
43
  }
39
44
 
@@ -55,8 +60,9 @@ export default class Meeting {
55
60
  ownerUuids,
56
61
  port,
57
62
  uri,
58
- number,
63
+ extension,
59
64
  persistent,
65
+ creationTime,
60
66
  }: Object = {}) {
61
67
  this.guestSipAuthorization = guestSipAuthorization;
62
68
  this.uri = uri;
@@ -64,8 +70,9 @@ export default class Meeting {
64
70
  this.ownerUuids = ownerUuids;
65
71
  this.port = port;
66
72
  this.uuid = uuid;
67
- this.number = number;
73
+ this.extension = extension;
68
74
  this.persistent = persistent;
75
+ this.creationTime = creationTime;
69
76
 
70
77
  // Useful to compare instead of instanceof with minified code
71
78
  this.type = 'Meeting';
@@ -306,6 +306,11 @@ export default class WebRTCPhone extends Emitter implements Phone {
306
306
 
307
307
  this.client.downgradeToAudio(sipSession);
308
308
 
309
+ if (callSession) {
310
+ callSession.cameraEnabled = false;
311
+ this._updateCallSession(callSession);
312
+ }
313
+
309
314
  if (withMessage) {
310
315
  this._sendReinviteMessage(callSession, false);
311
316
  }
@@ -333,6 +338,11 @@ export default class WebRTCPhone extends Emitter implements Phone {
333
338
 
334
339
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
335
340
 
341
+ if (callSession) {
342
+ callSession.cameraEnabled = true;
343
+ this._updateCallSession(callSession);
344
+ }
345
+
336
346
  // If no stream is returned, it means we have to reinvite
337
347
  if (!newStream) {
338
348
  return true;
@@ -1477,9 +1487,13 @@ export default class WebRTCPhone extends Emitter implements Phone {
1477
1487
  if (this.shouldSendReinvite && this.currentSipSession
1478
1488
  && this.currentSipSession.state === SessionState.Established) {
1479
1489
  this.shouldSendReinvite = false;
1490
+ const pc = this.currentSipSession.sessionDescriptionHandler.peerConnection;
1491
+ const isConference = pc ? pc.sfu : false;
1492
+ const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
1493
+
1480
1494
  try {
1481
1495
  // Send reinvite with iceRestart
1482
- this.sendReinvite(this.currentCallSession, null, false, false, true);
1496
+ this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
1483
1497
  } catch (e) {
1484
1498
  logger.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
1485
1499
  }
@@ -1563,6 +1577,15 @@ export default class WebRTCPhone extends Emitter implements Phone {
1563
1577
  return this.client.getSipSessionId(sipSession);
1564
1578
  }
1565
1579
 
1580
+ _updateCallSession(callSession: CallSession) {
1581
+ const sipSession = this.findSipSession(callSession);
1582
+ const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
1583
+
1584
+ if (sipSessionId) {
1585
+ this.callSessions[sipSessionId] = callSession;
1586
+ }
1587
+ }
1588
+
1566
1589
  _onMessage(message: Message) {
1567
1590
  if (!message || message.method !== 'MESSAGE') {
1568
1591
  return;
@@ -0,0 +1,50 @@
1
+ // @flow
2
+ /* global btoa */
3
+
4
+ import Meeting from '../Meeting';
5
+
6
+ describe('Meeting domain', () => {
7
+ it('can return username and secret from an base64 encrypted string', () => {
8
+ const USERNAME = 'username';
9
+ const SECRET = 'secret';
10
+
11
+ const args = {
12
+ guest_sip_authorization: btoa(`${USERNAME}:${SECRET}`),
13
+ creation_time: '',
14
+ ingress_http_uri: '',
15
+ name: '',
16
+ owner_uuids: [],
17
+ port: '',
18
+ uuid: '',
19
+ exten: '',
20
+ persistent: false,
21
+ };
22
+
23
+ const meeting = Meeting.parse(args);
24
+
25
+ const { username, secret } = meeting.getGuestSipCredentials();
26
+
27
+ expect(username).toEqual(USERNAME);
28
+ expect(secret).toEqual(SECRET);
29
+ });
30
+
31
+ it('should return a date from a string', () => {
32
+ const args = {
33
+ creation_time: '2021-12-21T15:56:42.880Z',
34
+ guest_sip_authorization: '',
35
+ ingress_http_uri: '',
36
+ name: '',
37
+ owner_uuids: [],
38
+ port: '',
39
+ uuid: '',
40
+ exten: '',
41
+ persistent: false,
42
+ };
43
+
44
+ const { creationTime } = Meeting.parse(args);
45
+
46
+ expect(creationTime.getDate()).toEqual(21);
47
+ expect(creationTime.getFullYear()).toEqual(2021);
48
+ expect(creationTime.getMonth()).toEqual(11);
49
+ });
50
+ });