@wazo/sdk 0.37.19 → 0.37.23

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 (142) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +70 -5
  3. package/esm/__tests__/web-rtc-client.test.js +111 -67
  4. package/esm/api/agentd.js +25 -2
  5. package/esm/api/amid.js +25 -2
  6. package/esm/api/application.js +25 -2
  7. package/esm/api/auth.js +25 -2
  8. package/esm/api/call-logd.js +32 -2
  9. package/esm/api/calld.js +35 -2
  10. package/esm/api/chatd.js +32 -2
  11. package/esm/api/confd.js +47 -5
  12. package/esm/api/ctid-ng.js +35 -2
  13. package/esm/api/dird.js +28 -2
  14. package/esm/api/webhookd.js +25 -2
  15. package/esm/api-client.js +70 -5
  16. package/esm/checker/Checker.js +113 -67
  17. package/esm/checker/checks/aor.js +70 -5
  18. package/esm/checker/checks/api.js +70 -5
  19. package/esm/checker/checks/index.js +113 -67
  20. package/esm/checker/checks/wazo-websocket.js +27 -2
  21. package/esm/checker/checks/webrtc-transport.js +111 -67
  22. package/esm/checker/checks/webrtc.js +111 -67
  23. package/esm/domain/AdHocAPIConference.js +70 -5
  24. package/esm/domain/Call.js +3 -0
  25. package/esm/domain/CallLog.js +7 -0
  26. package/esm/domain/ChatMessage.js +4 -0
  27. package/esm/domain/ChatRoom.js +3 -0
  28. package/esm/domain/Contact.js +3 -0
  29. package/esm/domain/Features.js +70 -5
  30. package/esm/domain/Meeting.js +17 -1
  31. package/esm/domain/Phone/CTIPhone.js +74 -5
  32. package/esm/domain/Phone/WebRTCPhone.js +50 -16
  33. package/esm/domain/Recording.js +3 -0
  34. package/esm/domain/Voicemail.js +3 -0
  35. package/esm/domain/__tests__/Call.test.js +3 -0
  36. package/esm/domain/__tests__/CallLog.test.js +7 -0
  37. package/esm/domain/__tests__/Contact.test.js +3 -0
  38. package/esm/domain/__tests__/Voicemail.test.js +3 -0
  39. package/esm/index.js +147 -80
  40. package/esm/lib/WazoSessionDescriptionHandler.js +25 -40
  41. package/esm/service/CallApi.js +70 -5
  42. package/esm/service/IssueReporter.js +25 -2
  43. package/esm/service/__tests__/IssueReporter.test.js +25 -2
  44. package/esm/service/getApiClient.js +70 -5
  45. package/esm/simple/Auth.js +147 -80
  46. package/esm/simple/Configuration.js +147 -80
  47. package/esm/simple/Directory.js +70 -5
  48. package/esm/simple/Phone.js +147 -80
  49. package/esm/simple/Websocket.js +28 -2
  50. package/esm/simple/index.js +147 -80
  51. package/esm/simple/room/LocalParticipant.js +147 -80
  52. package/esm/simple/room/Participant.js +147 -80
  53. package/esm/simple/room/RemoteParticipant.js +147 -80
  54. package/esm/simple/room/Room.js +147 -80
  55. package/esm/simple/room/SipRoom.js +147 -80
  56. package/esm/simple/room/Stream.js +147 -80
  57. package/esm/simple/room/__tests__/RemoteParticipant.test.js +147 -80
  58. package/esm/simple/utils.js +147 -80
  59. package/esm/utils/__tests__/api-requester.test.js +25 -2
  60. package/esm/utils/api-requester.js +25 -2
  61. package/esm/web-rtc-client.js +111 -67
  62. package/esm/websocket-client.js +28 -3
  63. package/lib/__tests__/api-client.test.js +70 -5
  64. package/lib/__tests__/web-rtc-client.test.js +111 -67
  65. package/lib/api/agentd.js +25 -2
  66. package/lib/api/amid.js +25 -2
  67. package/lib/api/application.js +25 -2
  68. package/lib/api/auth.js +25 -2
  69. package/lib/api/call-logd.js +32 -2
  70. package/lib/api/calld.js +35 -2
  71. package/lib/api/chatd.js +32 -2
  72. package/lib/api/confd.js +47 -5
  73. package/lib/api/ctid-ng.js +35 -2
  74. package/lib/api/dird.js +28 -2
  75. package/lib/api/webhookd.js +25 -2
  76. package/lib/api-client.js +70 -5
  77. package/lib/checker/Checker.js +113 -67
  78. package/lib/checker/checks/aor.js +70 -5
  79. package/lib/checker/checks/api.js +70 -5
  80. package/lib/checker/checks/index.js +113 -67
  81. package/lib/checker/checks/wazo-websocket.js +27 -2
  82. package/lib/checker/checks/webrtc-transport.js +111 -67
  83. package/lib/checker/checks/webrtc.js +111 -67
  84. package/lib/domain/AdHocAPIConference.js +70 -5
  85. package/lib/domain/Call.js +3 -0
  86. package/lib/domain/CallLog.js +7 -0
  87. package/lib/domain/ChatMessage.js +4 -0
  88. package/lib/domain/ChatRoom.js +3 -0
  89. package/lib/domain/Contact.js +3 -0
  90. package/lib/domain/Features.js +70 -5
  91. package/lib/domain/Meeting.js +17 -1
  92. package/lib/domain/Phone/CTIPhone.js +74 -5
  93. package/lib/domain/Phone/WebRTCPhone.js +50 -16
  94. package/lib/domain/Recording.js +3 -0
  95. package/lib/domain/Voicemail.js +3 -0
  96. package/lib/domain/__tests__/Call.test.js +3 -0
  97. package/lib/domain/__tests__/CallLog.test.js +7 -0
  98. package/lib/domain/__tests__/Contact.test.js +3 -0
  99. package/lib/domain/__tests__/Voicemail.test.js +3 -0
  100. package/lib/index.js +147 -80
  101. package/lib/lib/WazoSessionDescriptionHandler.js +25 -40
  102. package/lib/service/CallApi.js +70 -5
  103. package/lib/service/IssueReporter.js +25 -2
  104. package/lib/service/__tests__/IssueReporter.test.js +25 -2
  105. package/lib/service/getApiClient.js +70 -5
  106. package/lib/simple/Auth.js +147 -80
  107. package/lib/simple/Configuration.js +147 -80
  108. package/lib/simple/Directory.js +70 -5
  109. package/lib/simple/Phone.js +147 -80
  110. package/lib/simple/Websocket.js +28 -2
  111. package/lib/simple/index.js +147 -80
  112. package/lib/simple/room/LocalParticipant.js +147 -80
  113. package/lib/simple/room/Participant.js +147 -80
  114. package/lib/simple/room/RemoteParticipant.js +147 -80
  115. package/lib/simple/room/Room.js +147 -80
  116. package/lib/simple/room/SipRoom.js +147 -80
  117. package/lib/simple/room/Stream.js +147 -80
  118. package/lib/simple/room/__tests__/RemoteParticipant.test.js +147 -80
  119. package/lib/simple/utils.js +147 -80
  120. package/lib/utils/__tests__/api-requester.test.js +25 -2
  121. package/lib/utils/api-requester.js +25 -2
  122. package/lib/web-rtc-client.js +111 -67
  123. package/lib/websocket-client.js +28 -2
  124. package/package.json +2 -2
  125. package/src/api/confd.js +5 -2
  126. package/src/domain/Call.js +3 -0
  127. package/src/domain/CallLog.js +4 -0
  128. package/src/domain/ChatMessage.js +4 -0
  129. package/src/domain/ChatRoom.js +3 -0
  130. package/src/domain/Contact.js +3 -0
  131. package/src/domain/Meeting.js +17 -1
  132. package/src/domain/Phone/CTIPhone.js +4 -0
  133. package/src/domain/Phone/Phone.js +2 -0
  134. package/src/domain/Phone/WebRTCPhone.js +25 -14
  135. package/src/domain/Recording.js +3 -0
  136. package/src/domain/Voicemail.js +3 -0
  137. package/src/lib/WazoSessionDescriptionHandler.js +1 -35
  138. package/src/service/IssueReporter.js +25 -2
  139. package/src/simple/Phone.js +5 -0
  140. package/src/types/WebSocketMessage.js +5 -1
  141. package/src/web-rtc-client.js +41 -24
  142. package/src/websocket-client.js +2 -0
@@ -423,6 +423,7 @@ class IssueReporter {
423
423
 
424
424
 
425
425
 
426
+
426
427
 
427
428
  constructor() {
428
429
  addLevelsTo(this);
@@ -434,12 +435,17 @@ class IssueReporter {
434
435
  this.bufferTimeout = null;
435
436
  this._boundProcessBuffer = this._processBuffer.bind(this);
436
437
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
438
+ this._callback = null;
437
439
  }
438
440
 
439
441
  init() {
440
442
  this._catchConsole();
441
443
  }
442
444
 
445
+ setCallback(cb ) {
446
+ this._callback = cb;
447
+ }
448
+
443
449
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
444
450
  this.remoteClientConfiguration = configuration;
445
451
  }
@@ -475,6 +481,7 @@ class IssueReporter {
475
481
 
476
482
  // Handle category label
477
483
  let category = null;
484
+ let skipSendToRemote = false;
478
485
  let extra = {};
479
486
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
480
487
  category = args[0].split('=')[1];
@@ -490,6 +497,7 @@ class IssueReporter {
490
497
  errorMessage: lastArg.message,
491
498
  errorStack: lastArg.stack,
492
499
  errorType: lastArg.constructor.name,
500
+ skipSendToRemote: lastArg.skipSendToRemote,
493
501
  };
494
502
  } else {
495
503
  extra = lastArg;
@@ -498,6 +506,11 @@ class IssueReporter {
498
506
  args.splice(1, 1);
499
507
  }
500
508
 
509
+ if (extra.skipSendToRemote) {
510
+ skipSendToRemote = true;
511
+ delete extra.skipSendToRemote;
512
+ }
513
+
501
514
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
502
515
  const message = args.join(', ');
503
516
  let consoleMessage = message;
@@ -518,7 +531,13 @@ class IssueReporter {
518
531
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
519
532
  oldMethod.apply(oldMethod, [date, consoleMessage]);
520
533
 
521
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
534
+ if (this._callback) {
535
+ this._callback(level, consoleMessage);
536
+ }
537
+
538
+ if (!skipSendToRemote) {
539
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
540
+ }
522
541
  }
523
542
 
524
543
  logRequest(url , options , response , start ) {
@@ -663,7 +682,11 @@ class IssueReporter {
663
682
  },
664
683
  // $FlowFixMe
665
684
  body,
666
- }).catch(() => {
685
+ }).catch((e ) => {
686
+ // $FlowFixMe
687
+ e.skipSendToRemote = true;
688
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
689
+
667
690
  setTimeout(() => {
668
691
  if (isArray) {
669
692
  payload = payload.map(message => {
@@ -712,10 +735,6 @@ const getSrflxOrRelay = (candidates ) =>
712
735
  candidates
713
736
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
714
737
 
715
- const areCandidateValid = (candidates ) =>
716
- getSrflxOrRelay(candidates)
717
- .length > 0;
718
-
719
738
  const getVideoDirection = (sdp ) => {
720
739
  const parsedSdp = sdpParser__default['default'].parse(sdp);
721
740
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -768,8 +787,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
768
787
  /* global RTCSessionDescriptionInit, navigator */
769
788
 
770
789
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
771
- const MAX_WAIT_FOR_ICE_TRIES = 20;
772
- const WAIT_FOR_ICE_TIMEOUT = 500;
773
790
 
774
791
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
775
792
  const wazoMediaStreamFactory = (constraints ) => {
@@ -959,38 +976,6 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
959
976
  this._peerConnection = undefined;
960
977
  }
961
978
 
962
- async _waitForValidGatheredIce() {
963
- let tries = 0;
964
-
965
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
966
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
967
- tries,
968
- max: MAX_WAIT_FOR_ICE_TRIES,
969
- });
970
-
971
- tries++;
972
-
973
- // eslint-disable-next-line no-await-in-loop
974
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
975
- }
976
-
977
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
978
- const errorMsg = 'No valid candidates found, can\'t answer the call';
979
- const error = new Error(errorMsg);
980
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
981
-
982
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
983
- this.eventEmitter.emit('error', error);
984
-
985
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
986
- }
987
-
988
- // eslint-disable-next-line
989
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
990
-
991
- return this.getLocalSessionDescription();
992
- }
993
-
994
979
  // Overridden to send `inactive` in conference
995
980
  updateDirection(options , isConference = false,
996
981
  audioOnly = false) {
@@ -2100,6 +2085,9 @@ class Contact {
2100
2085
  }
2101
2086
 
2102
2087
  static parseMany(response ) {
2088
+ if (!response || !response.results) {
2089
+ return [];
2090
+ }
2103
2091
  return response.results.map(r => Contact.parse(r, response.column_types));
2104
2092
  }
2105
2093
 
@@ -3206,11 +3194,27 @@ class Meeting {
3206
3194
  });
3207
3195
  }
3208
3196
 
3197
+ static parseMany(items ) {
3198
+ if (!items) {
3199
+ return [];
3200
+ }
3201
+ return items.map(plain => Meeting.parse(plain));
3202
+ }
3203
+
3209
3204
  static newFrom(meeting ) {
3210
3205
  return newFrom(meeting, Meeting);
3211
3206
  }
3212
3207
 
3213
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
3208
+ constructor({
3209
+ uuid,
3210
+ name,
3211
+ guestSipAuthorization,
3212
+ ownerUuids,
3213
+ port,
3214
+ uri,
3215
+ number,
3216
+ persistent,
3217
+ } = {}) {
3214
3218
  this.guestSipAuthorization = guestSipAuthorization;
3215
3219
  this.uri = uri;
3216
3220
  this.name = name;
@@ -3296,8 +3300,11 @@ var confdMethods = (client , baseUrl ) => ({
3296
3300
  }
3297
3301
  },
3298
3302
 
3299
- createMyMeeting: (name ) =>
3300
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
3303
+ getMyMeetings: () =>
3304
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
3305
+
3306
+ createMyMeeting: (name , persistent ) =>
3307
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
3301
3308
 
3302
3309
  deleteMyMeeting: (meetingUuid ) =>
3303
3310
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -3393,6 +3400,10 @@ class ChatMessage {
3393
3400
 
3394
3401
 
3395
3402
  static parseMany(plain ) {
3403
+ if (!plain || !plain.items) {
3404
+ return [];
3405
+ }
3406
+
3396
3407
  return plain.items.map(item => ChatMessage.parse(item));
3397
3408
  }
3398
3409
 
@@ -3502,6 +3513,9 @@ class Voicemail {
3502
3513
  }
3503
3514
 
3504
3515
  static parseMany(plain ) {
3516
+ if (!plain) {
3517
+ return [];
3518
+ }
3505
3519
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3506
3520
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3507
3521
 
@@ -3611,6 +3625,9 @@ class Call {
3611
3625
 
3612
3626
 
3613
3627
  static parseMany(plain ) {
3628
+ if (!plain) {
3629
+ return [];
3630
+ }
3614
3631
  return plain.map((plainCall ) => Call.parse(plainCall));
3615
3632
  }
3616
3633
 
@@ -3783,6 +3800,9 @@ class Recording {
3783
3800
 
3784
3801
 
3785
3802
  static parseMany(recordings = []) {
3803
+ if (!recordings) {
3804
+ return [];
3805
+ }
3786
3806
  return recordings.map(item => Recording.parse(item));
3787
3807
  }
3788
3808
 
@@ -3884,6 +3904,10 @@ class CallLog {
3884
3904
  }
3885
3905
 
3886
3906
  static parseMany(plain ) {
3907
+ if (!plain || !plain.items) {
3908
+ return [];
3909
+ }
3910
+
3887
3911
  return plain.items.map(item => CallLog.parse(item));
3888
3912
  }
3889
3913
 
@@ -4456,6 +4480,9 @@ class ChatRoom {
4456
4480
 
4457
4481
 
4458
4482
  static parseMany(plain ) {
4483
+ if (!plain || !plain.items) {
4484
+ return [];
4485
+ }
4459
4486
  return plain.items.map(item => ChatRoom.parse(item));
4460
4487
  }
4461
4488
 
@@ -5712,7 +5739,9 @@ class WebRTCClient extends Emitter {
5712
5739
  const inviteOptions = {
5713
5740
  requestDelegate: {
5714
5741
  onAccept: (response ) => {
5715
- session.sessionDescriptionHandler.peerConnection.sfu = conference;
5742
+ if (session.sessionDescriptionHandler.peerConnection) {
5743
+ session.sessionDescriptionHandler.peerConnection.sfu = conference;
5744
+ }
5716
5745
  this._onAccepted(session, response.session, true);
5717
5746
  },
5718
5747
  onReject: (response ) => {
@@ -6584,6 +6613,16 @@ class WebRTCClient extends Emitter {
6584
6613
  return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
6585
6614
  }
6586
6615
 
6616
+ // Useful in a react-native environment when remoteMediaStream is not updated
6617
+ getRemoteVideoStreamFromPc(sessionId ) {
6618
+ const pc = this.getPeerConnection(sessionId);
6619
+ if (!pc) {
6620
+ return null;
6621
+ }
6622
+
6623
+ return pc.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
6624
+ }
6625
+
6587
6626
  hasVideo(sessionId ) {
6588
6627
  return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
6589
6628
  }
@@ -7094,6 +7133,7 @@ class WebRTCClient extends Emitter {
7094
7133
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
7095
7134
 
7096
7135
  pc.oniceconnectionstatechange = () => {
7136
+ logger.info('on ice connection state changed', { state: pc.iceConnectionState });
7097
7137
  if (pc.iceConnectionState === 'disconnected') {
7098
7138
  this.eventEmitter.emit(ON_DISCONNECTED);
7099
7139
  }
@@ -7322,25 +7362,25 @@ class WebRTCClient extends Emitter {
7322
7362
 
7323
7363
  stats.forEach(report => {
7324
7364
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
7325
- audioBytesSent += report.bytesSent + report.headerBytesSent;
7365
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
7326
7366
  }
7327
7367
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
7328
- audioBytesSent += report.bytesSent;
7368
+ audioBytesSent += Number(report.bytesSent);
7329
7369
  }
7330
7370
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
7331
- videoBytesSent += report.bytesSent + report.headerBytesSent;
7371
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
7332
7372
  }
7333
7373
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
7334
- packetsLost += report.packetsLost;
7335
- networkStats.packetsReceived = report.packetsReceived;
7336
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
7374
+ packetsLost += Number(report.packetsLost);
7375
+ networkStats.packetsReceived = Number(report.packetsReceived);
7376
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
7337
7377
  }
7338
7378
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
7339
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
7379
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
7340
7380
  }
7341
7381
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
7342
7382
  if ('framesPerSecond' in report) {
7343
- networkStats.framesPerSecond = report.framesPerSecond;
7383
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
7344
7384
  }
7345
7385
  if ('framerateMean' in report) {
7346
7386
  // framerateMean is only available in FF
@@ -7348,32 +7388,36 @@ class WebRTCClient extends Emitter {
7348
7388
  }
7349
7389
  }
7350
7390
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
7351
- packetsLost += report.packetsLost;
7352
- networkStats.roundTripTime = report.roundTripTime;
7353
- networkStats.jitter = report.jitter;
7391
+ packetsLost += Number(report.packetsLost);
7392
+ networkStats.roundTripTime = Number(report.roundTripTime);
7393
+ networkStats.jitter = Number(report.jitter);
7354
7394
  }
7355
7395
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
7356
- packetsLost += report.packetsLost;
7396
+ packetsLost += Number(report.packetsLost);
7357
7397
  }
7358
7398
  if (report.type === 'transport') {
7359
- transportSent += report.bytesSent;
7360
- transportReceived += report.bytesReceived;
7399
+ transportSent += Number(report.bytesSent);
7400
+ transportReceived += Number(report.bytesReceived);
7361
7401
  }
7362
7402
  });
7363
7403
 
7364
7404
  networkStats.packetsLost = packetsLost;
7365
- networkStats.audioBytesSent = audioBytesSent;
7405
+ networkStats.totalAudioBytesSent = audioBytesSent;
7406
+ networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
7407
+ networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
7366
7408
  networkStats.audioBytesReceived = audioBytesReceived;
7367
- networkStats.videoBytesSent = videoBytesSent;
7368
- networkStats.videoBytesReceived = videoBytesReceived;
7409
+ networkStats.totalVideoBytesSent = videoBytesSent;
7410
+ networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
7411
+ networkStats.totalVideoBytesReceived = videoBytesReceived;
7412
+ networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
7413
+ networkStats.totalTransportSent = transportSent - lastTransportSent;
7369
7414
  networkStats.transportSent = transportSent;
7370
- networkStats.transportReceived = transportReceived;
7371
-
7372
- const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
7373
- + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
7374
- + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
7415
+ networkStats.totalTransportReceived = transportReceived;
7416
+ networkStats.transportReceived = transportReceived - lastTransportReceived;
7375
7417
 
7376
- networkStats.bandwidth = bandwidth;
7418
+ networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived
7419
+ + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived
7420
+ + networkStats.transportSent;
7377
7421
 
7378
7422
  this.eventEmitter.emit(ON_NETWORK_STATS, session, networkStats, this.sessionNetworkStats[sessionId]);
7379
7423
  this.sessionNetworkStats[sessionId].push(networkStats);
@@ -131,6 +131,7 @@ class IssueReporter {
131
131
 
132
132
 
133
133
 
134
+
134
135
 
135
136
  constructor() {
136
137
  addLevelsTo(this);
@@ -142,12 +143,17 @@ class IssueReporter {
142
143
  this.bufferTimeout = null;
143
144
  this._boundProcessBuffer = this._processBuffer.bind(this);
144
145
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
146
+ this._callback = null;
145
147
  }
146
148
 
147
149
  init() {
148
150
  this._catchConsole();
149
151
  }
150
152
 
153
+ setCallback(cb ) {
154
+ this._callback = cb;
155
+ }
156
+
151
157
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
152
158
  this.remoteClientConfiguration = configuration;
153
159
  }
@@ -183,6 +189,7 @@ class IssueReporter {
183
189
 
184
190
  // Handle category label
185
191
  let category = null;
192
+ let skipSendToRemote = false;
186
193
  let extra = {};
187
194
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
188
195
  category = args[0].split('=')[1];
@@ -198,6 +205,7 @@ class IssueReporter {
198
205
  errorMessage: lastArg.message,
199
206
  errorStack: lastArg.stack,
200
207
  errorType: lastArg.constructor.name,
208
+ skipSendToRemote: lastArg.skipSendToRemote,
201
209
  };
202
210
  } else {
203
211
  extra = lastArg;
@@ -206,6 +214,11 @@ class IssueReporter {
206
214
  args.splice(1, 1);
207
215
  }
208
216
 
217
+ if (extra.skipSendToRemote) {
218
+ skipSendToRemote = true;
219
+ delete extra.skipSendToRemote;
220
+ }
221
+
209
222
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
210
223
  const message = args.join(', ');
211
224
  let consoleMessage = message;
@@ -226,7 +239,13 @@ class IssueReporter {
226
239
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
227
240
  oldMethod.apply(oldMethod, [date, consoleMessage]);
228
241
 
229
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
242
+ if (this._callback) {
243
+ this._callback(level, consoleMessage);
244
+ }
245
+
246
+ if (!skipSendToRemote) {
247
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
248
+ }
230
249
  }
231
250
 
232
251
  logRequest(url , options , response , start ) {
@@ -371,7 +390,11 @@ class IssueReporter {
371
390
  },
372
391
  // $FlowFixMe
373
392
  body,
374
- }).catch(() => {
393
+ }).catch((e ) => {
394
+ // $FlowFixMe
395
+ e.skipSendToRemote = true;
396
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
397
+
375
398
  setTimeout(() => {
376
399
  if (isArray) {
377
400
  payload = payload.map(message => {
@@ -588,6 +611,7 @@ const AGENT_PAUSED = 'agent_paused';
588
611
  const AGENT_UNPAUSED = 'agent_unpaused';
589
612
  const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
590
613
  const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
614
+ const MEETING_USER_PROGRESS = 'meeting_user_progress';
591
615
 
592
616
  const BLACKLIST_EVENTS = [
593
617
  CHAT_MESSAGE_SENT,
@@ -938,6 +962,7 @@ WebSocketClient.eventLists = [
938
962
  AGENT_UNPAUSED,
939
963
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
940
964
  CONFERENCE_ADHOC_DELETED,
965
+ MEETING_USER_PROGRESS,
941
966
  ];
942
967
 
943
968
  exports.AGENT_PAUSED = AGENT_PAUSED;
@@ -993,6 +1018,7 @@ exports.HEARTBEAT_ENGINE_VERSION = HEARTBEAT_ENGINE_VERSION;
993
1018
  exports.LINE_STATUS_UPDATED = LINE_STATUS_UPDATED;
994
1019
  exports.MEETING_USER_PARTICIPANT_JOINED = MEETING_USER_PARTICIPANT_JOINED;
995
1020
  exports.MEETING_USER_PARTICIPANT_LEFT = MEETING_USER_PARTICIPANT_LEFT;
1021
+ exports.MEETING_USER_PROGRESS = MEETING_USER_PROGRESS;
996
1022
  exports.SOCKET_EVENTS = SOCKET_EVENTS;
997
1023
  exports.SWITCHBOARD_HELD_CALLS_UPDATED = SWITCHBOARD_HELD_CALLS_UPDATED;
998
1024
  exports.SWITCHBOARD_HELD_CALL_ANSWERED = SWITCHBOARD_HELD_CALL_ANSWERED;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.37.19",
3
+ "version": "0.37.23",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "events": "^3.3.0",
49
49
  "fstream": "^1.0.12",
50
- "getstats": "manuquentin/getStats#fix_undefined_results",
50
+ "getstats": "manuquentin/getStats#fix_stats_mobile",
51
51
  "globby": "^11.0.3",
52
52
  "google-libphonenumber": "^3.2.18",
53
53
  "js-base64": "^3.6.0",
package/src/api/confd.js CHANGED
@@ -69,8 +69,11 @@ export default (client: ApiRequester, baseUrl: string) => ({
69
69
  }
70
70
  },
71
71
 
72
- createMyMeeting: (name: string): Promise<Meeting> =>
73
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
72
+ getMyMeetings: (): Promise<Meeting> =>
73
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
74
+
75
+ createMyMeeting: (name: string, persistent: boolean): Promise<Meeting> =>
76
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
74
77
 
75
78
  deleteMyMeeting: (meetingUuid: string): Promise<Meeting> =>
76
79
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -61,6 +61,9 @@ export default class Call {
61
61
  recording: boolean;
62
62
 
63
63
  static parseMany(plain: Array<CallResponse>): Array<Call> {
64
+ if (!plain) {
65
+ return [];
66
+ }
64
67
  return plain.map((plainCall: CallResponse) => Call.parse(plainCall));
65
68
  }
66
69
 
@@ -84,6 +84,10 @@ export default class CallLog {
84
84
  }
85
85
 
86
86
  static parseMany(plain: Response): Array<CallLog> {
87
+ if (!plain || !plain.items) {
88
+ return [];
89
+ }
90
+
87
91
  return plain.items.map(item => CallLog.parse(item));
88
92
  }
89
93
 
@@ -42,6 +42,10 @@ export default class ChatMessage {
42
42
  read: boolean;
43
43
 
44
44
  static parseMany(plain: ChatMessageListResponse): Array<ChatMessage> {
45
+ if (!plain || !plain.items) {
46
+ return [];
47
+ }
48
+
45
49
  return plain.items.map(item => ChatMessage.parse(item));
46
50
  }
47
51
 
@@ -22,6 +22,9 @@ export default class ChatRoom {
22
22
  users: Array<ChatUser>;
23
23
 
24
24
  static parseMany(plain: RootListResponse): Array<ChatRoom> {
25
+ if (!plain || !plain.items) {
26
+ return [];
27
+ }
25
28
  return plain.items.map(item => ChatRoom.parse(item));
26
29
  }
27
30
 
@@ -281,6 +281,9 @@ export default class Contact {
281
281
  }
282
282
 
283
283
  static parseMany(response: ContactsResponse): Array<Contact> {
284
+ if (!response || !response.results) {
285
+ return [];
286
+ }
284
287
  return response.results.map(r => Contact.parse(r, response.column_types));
285
288
  }
286
289
 
@@ -37,11 +37,27 @@ export default class Meeting {
37
37
  });
38
38
  }
39
39
 
40
+ static parseMany(items: MeetingCreationResponse[]): Array<Meeting> {
41
+ if (!items) {
42
+ return [];
43
+ }
44
+ return items.map(plain => Meeting.parse(plain));
45
+ }
46
+
40
47
  static newFrom(meeting: Meeting) {
41
48
  return newFrom(meeting, Meeting);
42
49
  }
43
50
 
44
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent }: Object = {}) {
51
+ constructor({
52
+ uuid,
53
+ name,
54
+ guestSipAuthorization,
55
+ ownerUuids,
56
+ port,
57
+ uri,
58
+ number,
59
+ persistent,
60
+ }: Object = {}) {
45
61
  this.guestSipAuthorization = guestSipAuthorization;
46
62
  this.uri = uri;
47
63
  this.name = name;
@@ -280,6 +280,10 @@ export default class CTIPhone extends Emitter implements Phone {
280
280
  return false;
281
281
  }
282
282
 
283
+ hasAVideoTrack(): boolean {
284
+ return false;
285
+ }
286
+
283
287
  getLocalStreamForCall(): ?MediaStream {
284
288
  return null;
285
289
  }
@@ -80,6 +80,8 @@ export interface Phone {
80
80
 
81
81
  hasVideo(callSession: CallSession): boolean;
82
82
 
83
+ hasAVideoTrack(callSession: CallSession): boolean;
84
+
83
85
  isWebRTC(): boolean;
84
86
 
85
87
  getUserAgent(): string;
@@ -385,7 +385,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
385
385
 
386
386
  onCancel(message);
387
387
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
388
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
388
+ const callSession = this._createCallSession(sipSession);
389
+ delete this.callSessions[callSession.getId()];
390
+
391
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
389
392
  };
390
393
  } else if (sipSession instanceof Invitation) {
391
394
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -414,9 +417,11 @@ export default class WebRTCPhone extends Emitter implements Phone {
414
417
  case SessionState.Terminated: {
415
418
  logger.info('WebRTC phone - call terminated', { sipId: sipSession.id });
416
419
 
420
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
421
+ const callSession = this._createCallSession(sipSession);
417
422
  const wasCurrentSession = this._onCallTerminated(sipSession);
418
423
 
419
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
424
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
420
425
  }
421
426
  default:
422
427
  break;
@@ -566,18 +571,20 @@ export default class WebRTCPhone extends Emitter implements Phone {
566
571
  screenTrack,
567
572
  });
568
573
 
569
- screenTrack.onended = () => {
570
- logger.info('WebRTC phone - on screenshare ended', {
571
- hadVideo,
572
- id: this.getSipSessionId(sipSession),
573
- screenTrack,
574
- });
575
-
576
- this.eventEmitter.emit(
577
- ON_SHARE_SCREEN_ENDING,
578
- this._createCallSession(sipSession, callSession),
579
- );
580
- };
574
+ if (screenTrack) {
575
+ screenTrack.onended = () => {
576
+ logger.info('WebRTC phone - on screenshare ended', {
577
+ hadVideo,
578
+ id: this.getSipSessionId(sipSession),
579
+ screenTrack,
580
+ });
581
+
582
+ this.eventEmitter.emit(
583
+ ON_SHARE_SCREEN_ENDING,
584
+ this._createCallSession(sipSession, callSession),
585
+ );
586
+ };
587
+ }
581
588
 
582
589
  this.currentScreenShare = {
583
590
  stream: screenStream,
@@ -1366,6 +1373,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
1366
1373
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
1367
1374
  }
1368
1375
 
1376
+ getRemoteVideoStreamFromPc(callSession: CallSession): ?MediaStream {
1377
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
1378
+ }
1379
+
1369
1380
  hasRemoteVideo(callSession: CallSession): boolean {
1370
1381
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
1371
1382
  }