@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
@@ -138,6 +138,7 @@ class IssueReporter {
138
138
 
139
139
 
140
140
 
141
+
141
142
 
142
143
  constructor() {
143
144
  addLevelsTo(this);
@@ -149,12 +150,17 @@ class IssueReporter {
149
150
  this.bufferTimeout = null;
150
151
  this._boundProcessBuffer = this._processBuffer.bind(this);
151
152
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
153
+ this._callback = null;
152
154
  }
153
155
 
154
156
  init() {
155
157
  this._catchConsole();
156
158
  }
157
159
 
160
+ setCallback(cb ) {
161
+ this._callback = cb;
162
+ }
163
+
158
164
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
159
165
  this.remoteClientConfiguration = configuration;
160
166
  }
@@ -190,6 +196,7 @@ class IssueReporter {
190
196
 
191
197
  // Handle category label
192
198
  let category = null;
199
+ let skipSendToRemote = false;
193
200
  let extra = {};
194
201
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
195
202
  category = args[0].split('=')[1];
@@ -205,6 +212,7 @@ class IssueReporter {
205
212
  errorMessage: lastArg.message,
206
213
  errorStack: lastArg.stack,
207
214
  errorType: lastArg.constructor.name,
215
+ skipSendToRemote: lastArg.skipSendToRemote,
208
216
  };
209
217
  } else {
210
218
  extra = lastArg;
@@ -213,6 +221,11 @@ class IssueReporter {
213
221
  args.splice(1, 1);
214
222
  }
215
223
 
224
+ if (extra.skipSendToRemote) {
225
+ skipSendToRemote = true;
226
+ delete extra.skipSendToRemote;
227
+ }
228
+
216
229
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
217
230
  const message = args.join(', ');
218
231
  let consoleMessage = message;
@@ -233,7 +246,13 @@ class IssueReporter {
233
246
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
234
247
  oldMethod.apply(oldMethod, [date, consoleMessage]);
235
248
 
236
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
249
+ if (this._callback) {
250
+ this._callback(level, consoleMessage);
251
+ }
252
+
253
+ if (!skipSendToRemote) {
254
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
255
+ }
237
256
  }
238
257
 
239
258
  logRequest(url , options , response , start ) {
@@ -378,7 +397,11 @@ class IssueReporter {
378
397
  },
379
398
  // $FlowFixMe
380
399
  body,
381
- }).catch(() => {
400
+ }).catch((e ) => {
401
+ // $FlowFixMe
402
+ e.skipSendToRemote = true;
403
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
404
+
382
405
  setTimeout(() => {
383
406
  if (isArray) {
384
407
  payload = payload.map(message => {
@@ -1516,6 +1539,9 @@ class Contact {
1516
1539
  }
1517
1540
 
1518
1541
  static parseMany(response ) {
1542
+ if (!response || !response.results) {
1543
+ return [];
1544
+ }
1519
1545
  return response.results.map(r => Contact.parse(r, response.column_types));
1520
1546
  }
1521
1547
 
@@ -2622,11 +2648,27 @@ class Meeting {
2622
2648
  });
2623
2649
  }
2624
2650
 
2651
+ static parseMany(items ) {
2652
+ if (!items) {
2653
+ return [];
2654
+ }
2655
+ return items.map(plain => Meeting.parse(plain));
2656
+ }
2657
+
2625
2658
  static newFrom(meeting ) {
2626
2659
  return newFrom(meeting, Meeting);
2627
2660
  }
2628
2661
 
2629
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2662
+ constructor({
2663
+ uuid,
2664
+ name,
2665
+ guestSipAuthorization,
2666
+ ownerUuids,
2667
+ port,
2668
+ uri,
2669
+ number,
2670
+ persistent,
2671
+ } = {}) {
2630
2672
  this.guestSipAuthorization = guestSipAuthorization;
2631
2673
  this.uri = uri;
2632
2674
  this.name = name;
@@ -2712,8 +2754,11 @@ var confdMethods = (client , baseUrl ) => ({
2712
2754
  }
2713
2755
  },
2714
2756
 
2715
- createMyMeeting: (name ) =>
2716
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2757
+ getMyMeetings: () =>
2758
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2759
+
2760
+ createMyMeeting: (name , persistent ) =>
2761
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2717
2762
 
2718
2763
  deleteMyMeeting: (meetingUuid ) =>
2719
2764
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2809,6 +2854,10 @@ class ChatMessage {
2809
2854
 
2810
2855
 
2811
2856
  static parseMany(plain ) {
2857
+ if (!plain || !plain.items) {
2858
+ return [];
2859
+ }
2860
+
2812
2861
  return plain.items.map(item => ChatMessage.parse(item));
2813
2862
  }
2814
2863
 
@@ -2918,6 +2967,9 @@ class Voicemail {
2918
2967
  }
2919
2968
 
2920
2969
  static parseMany(plain ) {
2970
+ if (!plain) {
2971
+ return [];
2972
+ }
2921
2973
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2922
2974
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2923
2975
 
@@ -3027,6 +3079,9 @@ class Call {
3027
3079
 
3028
3080
 
3029
3081
  static parseMany(plain ) {
3082
+ if (!plain) {
3083
+ return [];
3084
+ }
3030
3085
  return plain.map((plainCall ) => Call.parse(plainCall));
3031
3086
  }
3032
3087
 
@@ -3199,6 +3254,9 @@ class Recording {
3199
3254
 
3200
3255
 
3201
3256
  static parseMany(recordings = []) {
3257
+ if (!recordings) {
3258
+ return [];
3259
+ }
3202
3260
  return recordings.map(item => Recording.parse(item));
3203
3261
  }
3204
3262
 
@@ -3300,6 +3358,10 @@ class CallLog {
3300
3358
  }
3301
3359
 
3302
3360
  static parseMany(plain ) {
3361
+ if (!plain || !plain.items) {
3362
+ return [];
3363
+ }
3364
+
3303
3365
  return plain.items.map(item => CallLog.parse(item));
3304
3366
  }
3305
3367
 
@@ -3857,6 +3919,9 @@ class ChatRoom {
3857
3919
 
3858
3920
 
3859
3921
  static parseMany(plain ) {
3922
+ if (!plain || !plain.items) {
3923
+ return [];
3924
+ }
3860
3925
  return plain.items.map(item => ChatRoom.parse(item));
3861
3926
  }
3862
3927
 
@@ -49,11 +49,27 @@ class Meeting {
49
49
  });
50
50
  }
51
51
 
52
+ static parseMany(items ) {
53
+ if (!items) {
54
+ return [];
55
+ }
56
+ return items.map(plain => Meeting.parse(plain));
57
+ }
58
+
52
59
  static newFrom(meeting ) {
53
60
  return newFrom(meeting, Meeting);
54
61
  }
55
62
 
56
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
63
+ constructor({
64
+ uuid,
65
+ name,
66
+ guestSipAuthorization,
67
+ ownerUuids,
68
+ port,
69
+ uri,
70
+ number,
71
+ persistent,
72
+ } = {}) {
57
73
  this.guestSipAuthorization = guestSipAuthorization;
58
74
  this.uri = uri;
59
75
  this.name = name;
@@ -853,6 +853,9 @@ class Contact {
853
853
  }
854
854
 
855
855
  static parseMany(response ) {
856
+ if (!response || !response.results) {
857
+ return [];
858
+ }
856
859
  return response.results.map(r => Contact.parse(r, response.column_types));
857
860
  }
858
861
 
@@ -1559,6 +1562,9 @@ class Call {
1559
1562
 
1560
1563
 
1561
1564
  static parseMany(plain ) {
1565
+ if (!plain) {
1566
+ return [];
1567
+ }
1562
1568
  return plain.map((plainCall ) => Call.parse(plainCall));
1563
1569
  }
1564
1570
 
@@ -2102,6 +2108,9 @@ class Recording {
2102
2108
 
2103
2109
 
2104
2110
  static parseMany(recordings = []) {
2111
+ if (!recordings) {
2112
+ return [];
2113
+ }
2105
2114
  return recordings.map(item => Recording.parse(item));
2106
2115
  }
2107
2116
 
@@ -2203,6 +2212,10 @@ class CallLog {
2203
2212
  }
2204
2213
 
2205
2214
  static parseMany(plain ) {
2215
+ if (!plain || !plain.items) {
2216
+ return [];
2217
+ }
2218
+
2206
2219
  return plain.items.map(item => CallLog.parse(item));
2207
2220
  }
2208
2221
 
@@ -2519,6 +2532,7 @@ class IssueReporter {
2519
2532
 
2520
2533
 
2521
2534
 
2535
+
2522
2536
 
2523
2537
  constructor() {
2524
2538
  addLevelsTo(this);
@@ -2530,12 +2544,17 @@ class IssueReporter {
2530
2544
  this.bufferTimeout = null;
2531
2545
  this._boundProcessBuffer = this._processBuffer.bind(this);
2532
2546
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
2547
+ this._callback = null;
2533
2548
  }
2534
2549
 
2535
2550
  init() {
2536
2551
  this._catchConsole();
2537
2552
  }
2538
2553
 
2554
+ setCallback(cb ) {
2555
+ this._callback = cb;
2556
+ }
2557
+
2539
2558
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
2540
2559
  this.remoteClientConfiguration = configuration;
2541
2560
  }
@@ -2571,6 +2590,7 @@ class IssueReporter {
2571
2590
 
2572
2591
  // Handle category label
2573
2592
  let category = null;
2593
+ let skipSendToRemote = false;
2574
2594
  let extra = {};
2575
2595
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
2576
2596
  category = args[0].split('=')[1];
@@ -2586,6 +2606,7 @@ class IssueReporter {
2586
2606
  errorMessage: lastArg.message,
2587
2607
  errorStack: lastArg.stack,
2588
2608
  errorType: lastArg.constructor.name,
2609
+ skipSendToRemote: lastArg.skipSendToRemote,
2589
2610
  };
2590
2611
  } else {
2591
2612
  extra = lastArg;
@@ -2594,6 +2615,11 @@ class IssueReporter {
2594
2615
  args.splice(1, 1);
2595
2616
  }
2596
2617
 
2618
+ if (extra.skipSendToRemote) {
2619
+ skipSendToRemote = true;
2620
+ delete extra.skipSendToRemote;
2621
+ }
2622
+
2597
2623
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
2598
2624
  const message = args.join(', ');
2599
2625
  let consoleMessage = message;
@@ -2614,7 +2640,13 @@ class IssueReporter {
2614
2640
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
2615
2641
  oldMethod.apply(oldMethod, [date, consoleMessage]);
2616
2642
 
2617
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
2643
+ if (this._callback) {
2644
+ this._callback(level, consoleMessage);
2645
+ }
2646
+
2647
+ if (!skipSendToRemote) {
2648
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
2649
+ }
2618
2650
  }
2619
2651
 
2620
2652
  logRequest(url , options , response , start ) {
@@ -2759,7 +2791,11 @@ class IssueReporter {
2759
2791
  },
2760
2792
  // $FlowFixMe
2761
2793
  body,
2762
- }).catch(() => {
2794
+ }).catch((e ) => {
2795
+ // $FlowFixMe
2796
+ e.skipSendToRemote = true;
2797
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
2798
+
2763
2799
  setTimeout(() => {
2764
2800
  if (isArray) {
2765
2801
  payload = payload.map(message => {
@@ -3518,11 +3554,27 @@ class Meeting {
3518
3554
  });
3519
3555
  }
3520
3556
 
3557
+ static parseMany(items ) {
3558
+ if (!items) {
3559
+ return [];
3560
+ }
3561
+ return items.map(plain => Meeting.parse(plain));
3562
+ }
3563
+
3521
3564
  static newFrom(meeting ) {
3522
3565
  return newFrom(meeting, Meeting);
3523
3566
  }
3524
3567
 
3525
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
3568
+ constructor({
3569
+ uuid,
3570
+ name,
3571
+ guestSipAuthorization,
3572
+ ownerUuids,
3573
+ port,
3574
+ uri,
3575
+ number,
3576
+ persistent,
3577
+ } = {}) {
3526
3578
  this.guestSipAuthorization = guestSipAuthorization;
3527
3579
  this.uri = uri;
3528
3580
  this.name = name;
@@ -3608,8 +3660,11 @@ var confdMethods = (client , baseUrl ) => ({
3608
3660
  }
3609
3661
  },
3610
3662
 
3611
- createMyMeeting: (name ) =>
3612
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
3663
+ getMyMeetings: () =>
3664
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
3665
+
3666
+ createMyMeeting: (name , persistent ) =>
3667
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
3613
3668
 
3614
3669
  deleteMyMeeting: (meetingUuid ) =>
3615
3670
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -3662,6 +3717,10 @@ class ChatMessage {
3662
3717
 
3663
3718
 
3664
3719
  static parseMany(plain ) {
3720
+ if (!plain || !plain.items) {
3721
+ return [];
3722
+ }
3723
+
3665
3724
  return plain.items.map(item => ChatMessage.parse(item));
3666
3725
  }
3667
3726
 
@@ -3771,6 +3830,9 @@ class Voicemail {
3771
3830
  }
3772
3831
 
3773
3832
  static parseMany(plain ) {
3833
+ if (!plain) {
3834
+ return [];
3835
+ }
3774
3836
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3775
3837
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3776
3838
 
@@ -4154,6 +4216,9 @@ class ChatRoom {
4154
4216
 
4155
4217
 
4156
4218
  static parseMany(plain ) {
4219
+ if (!plain || !plain.items) {
4220
+ return [];
4221
+ }
4157
4222
  return plain.items.map(item => ChatRoom.parse(item));
4158
4223
  }
4159
4224
 
@@ -5338,6 +5403,10 @@ class CTIPhone extends Emitter {
5338
5403
  return false;
5339
5404
  }
5340
5405
 
5406
+ hasAVideoTrack() {
5407
+ return false;
5408
+ }
5409
+
5341
5410
  getLocalStreamForCall() {
5342
5411
  return null;
5343
5412
  }
@@ -496,6 +496,7 @@ class IssueReporter {
496
496
 
497
497
 
498
498
 
499
+
499
500
 
500
501
  constructor() {
501
502
  addLevelsTo(this);
@@ -507,12 +508,17 @@ class IssueReporter {
507
508
  this.bufferTimeout = null;
508
509
  this._boundProcessBuffer = this._processBuffer.bind(this);
509
510
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
511
+ this._callback = null;
510
512
  }
511
513
 
512
514
  init() {
513
515
  this._catchConsole();
514
516
  }
515
517
 
518
+ setCallback(cb ) {
519
+ this._callback = cb;
520
+ }
521
+
516
522
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
517
523
  this.remoteClientConfiguration = configuration;
518
524
  }
@@ -548,6 +554,7 @@ class IssueReporter {
548
554
 
549
555
  // Handle category label
550
556
  let category = null;
557
+ let skipSendToRemote = false;
551
558
  let extra = {};
552
559
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
553
560
  category = args[0].split('=')[1];
@@ -563,6 +570,7 @@ class IssueReporter {
563
570
  errorMessage: lastArg.message,
564
571
  errorStack: lastArg.stack,
565
572
  errorType: lastArg.constructor.name,
573
+ skipSendToRemote: lastArg.skipSendToRemote,
566
574
  };
567
575
  } else {
568
576
  extra = lastArg;
@@ -571,6 +579,11 @@ class IssueReporter {
571
579
  args.splice(1, 1);
572
580
  }
573
581
 
582
+ if (extra.skipSendToRemote) {
583
+ skipSendToRemote = true;
584
+ delete extra.skipSendToRemote;
585
+ }
586
+
574
587
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
575
588
  const message = args.join(', ');
576
589
  let consoleMessage = message;
@@ -591,7 +604,13 @@ class IssueReporter {
591
604
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
592
605
  oldMethod.apply(oldMethod, [date, consoleMessage]);
593
606
 
594
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
607
+ if (this._callback) {
608
+ this._callback(level, consoleMessage);
609
+ }
610
+
611
+ if (!skipSendToRemote) {
612
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
613
+ }
595
614
  }
596
615
 
597
616
  logRequest(url , options , response , start ) {
@@ -736,7 +755,11 @@ class IssueReporter {
736
755
  },
737
756
  // $FlowFixMe
738
757
  body,
739
- }).catch(() => {
758
+ }).catch((e ) => {
759
+ // $FlowFixMe
760
+ e.skipSendToRemote = true;
761
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
762
+
740
763
  setTimeout(() => {
741
764
  if (isArray) {
742
765
  payload = payload.map(message => {
@@ -1219,7 +1242,10 @@ class WebRTCPhone extends Emitter {
1219
1242
 
1220
1243
  onCancel(message);
1221
1244
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
1222
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
1245
+ const callSession = this._createCallSession(sipSession);
1246
+ delete this.callSessions[callSession.getId()];
1247
+
1248
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
1223
1249
  };
1224
1250
  } else if (sipSession instanceof invitation.Invitation) {
1225
1251
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -1248,9 +1274,11 @@ class WebRTCPhone extends Emitter {
1248
1274
  case sessionState.SessionState.Terminated: {
1249
1275
  logger.info('WebRTC phone - call terminated', { sipId: sipSession.id });
1250
1276
 
1277
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
1278
+ const callSession = this._createCallSession(sipSession);
1251
1279
  const wasCurrentSession = this._onCallTerminated(sipSession);
1252
1280
 
1253
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
1281
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
1254
1282
  }
1255
1283
  }
1256
1284
  });
@@ -1398,18 +1426,20 @@ class WebRTCPhone extends Emitter {
1398
1426
  screenTrack,
1399
1427
  });
1400
1428
 
1401
- screenTrack.onended = () => {
1402
- logger.info('WebRTC phone - on screenshare ended', {
1403
- hadVideo,
1404
- id: this.getSipSessionId(sipSession),
1405
- screenTrack,
1406
- });
1407
-
1408
- this.eventEmitter.emit(
1409
- ON_SHARE_SCREEN_ENDING,
1410
- this._createCallSession(sipSession, callSession),
1411
- );
1412
- };
1429
+ if (screenTrack) {
1430
+ screenTrack.onended = () => {
1431
+ logger.info('WebRTC phone - on screenshare ended', {
1432
+ hadVideo,
1433
+ id: this.getSipSessionId(sipSession),
1434
+ screenTrack,
1435
+ });
1436
+
1437
+ this.eventEmitter.emit(
1438
+ ON_SHARE_SCREEN_ENDING,
1439
+ this._createCallSession(sipSession, callSession),
1440
+ );
1441
+ };
1442
+ }
1413
1443
 
1414
1444
  this.currentScreenShare = {
1415
1445
  stream: screenStream,
@@ -2198,6 +2228,10 @@ class WebRTCPhone extends Emitter {
2198
2228
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
2199
2229
  }
2200
2230
 
2231
+ getRemoteVideoStreamFromPc(callSession ) {
2232
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
2233
+ }
2234
+
2201
2235
  hasRemoteVideo(callSession ) {
2202
2236
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
2203
2237
  }
@@ -32,6 +32,9 @@ class Recording {
32
32
 
33
33
 
34
34
  static parseMany(recordings = []) {
35
+ if (!recordings) {
36
+ return [];
37
+ }
35
38
  return recordings.map(item => Recording.parse(item));
36
39
  }
37
40
 
@@ -77,6 +77,9 @@ class Voicemail {
77
77
  }
78
78
 
79
79
  static parseMany(plain ) {
80
+ if (!plain) {
81
+ return [];
82
+ }
80
83
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
81
84
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
82
85
 
@@ -77,6 +77,9 @@ class Call {
77
77
 
78
78
 
79
79
  static parseMany(plain ) {
80
+ if (!plain) {
81
+ return [];
82
+ }
80
83
  return plain.map((plainCall ) => Call.parse(plainCall));
81
84
  }
82
85
 
@@ -60,6 +60,9 @@ class Recording {
60
60
 
61
61
 
62
62
  static parseMany(recordings = []) {
63
+ if (!recordings) {
64
+ return [];
65
+ }
63
66
  return recordings.map(item => Recording.parse(item));
64
67
  }
65
68
 
@@ -161,6 +164,10 @@ class CallLog {
161
164
  }
162
165
 
163
166
  static parseMany(plain ) {
167
+ if (!plain || !plain.items) {
168
+ return [];
169
+ }
170
+
164
171
  return plain.items.map(item => CallLog.parse(item));
165
172
  }
166
173
 
@@ -327,6 +327,9 @@ class Contact {
327
327
  }
328
328
 
329
329
  static parseMany(response ) {
330
+ if (!response || !response.results) {
331
+ return [];
332
+ }
330
333
  return response.results.map(r => Contact.parse(r, response.column_types));
331
334
  }
332
335
 
@@ -77,6 +77,9 @@ class Voicemail {
77
77
  }
78
78
 
79
79
  static parseMany(plain ) {
80
+ if (!plain) {
81
+ return [];
82
+ }
80
83
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
81
84
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
82
85