@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
@@ -136,6 +136,7 @@ class IssueReporter {
136
136
 
137
137
 
138
138
 
139
+
139
140
 
140
141
  constructor() {
141
142
  addLevelsTo(this);
@@ -147,12 +148,17 @@ class IssueReporter {
147
148
  this.bufferTimeout = null;
148
149
  this._boundProcessBuffer = this._processBuffer.bind(this);
149
150
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
151
+ this._callback = null;
150
152
  }
151
153
 
152
154
  init() {
153
155
  this._catchConsole();
154
156
  }
155
157
 
158
+ setCallback(cb ) {
159
+ this._callback = cb;
160
+ }
161
+
156
162
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
157
163
  this.remoteClientConfiguration = configuration;
158
164
  }
@@ -188,6 +194,7 @@ class IssueReporter {
188
194
 
189
195
  // Handle category label
190
196
  let category = null;
197
+ let skipSendToRemote = false;
191
198
  let extra = {};
192
199
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
193
200
  category = args[0].split('=')[1];
@@ -203,6 +210,7 @@ class IssueReporter {
203
210
  errorMessage: lastArg.message,
204
211
  errorStack: lastArg.stack,
205
212
  errorType: lastArg.constructor.name,
213
+ skipSendToRemote: lastArg.skipSendToRemote,
206
214
  };
207
215
  } else {
208
216
  extra = lastArg;
@@ -211,6 +219,11 @@ class IssueReporter {
211
219
  args.splice(1, 1);
212
220
  }
213
221
 
222
+ if (extra.skipSendToRemote) {
223
+ skipSendToRemote = true;
224
+ delete extra.skipSendToRemote;
225
+ }
226
+
214
227
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
215
228
  const message = args.join(', ');
216
229
  let consoleMessage = message;
@@ -231,7 +244,13 @@ class IssueReporter {
231
244
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
232
245
  oldMethod.apply(oldMethod, [date, consoleMessage]);
233
246
 
234
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
247
+ if (this._callback) {
248
+ this._callback(level, consoleMessage);
249
+ }
250
+
251
+ if (!skipSendToRemote) {
252
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
253
+ }
235
254
  }
236
255
 
237
256
  logRequest(url , options , response , start ) {
@@ -376,7 +395,11 @@ class IssueReporter {
376
395
  },
377
396
  // $FlowFixMe
378
397
  body,
379
- }).catch(() => {
398
+ }).catch((e ) => {
399
+ // $FlowFixMe
400
+ e.skipSendToRemote = true;
401
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
402
+
380
403
  setTimeout(() => {
381
404
  if (isArray) {
382
405
  payload = payload.map(message => {
@@ -1514,6 +1537,9 @@ class Contact {
1514
1537
  }
1515
1538
 
1516
1539
  static parseMany(response ) {
1540
+ if (!response || !response.results) {
1541
+ return [];
1542
+ }
1517
1543
  return response.results.map(r => Contact.parse(r, response.column_types));
1518
1544
  }
1519
1545
 
@@ -2620,11 +2646,27 @@ class Meeting {
2620
2646
  });
2621
2647
  }
2622
2648
 
2649
+ static parseMany(items ) {
2650
+ if (!items) {
2651
+ return [];
2652
+ }
2653
+ return items.map(plain => Meeting.parse(plain));
2654
+ }
2655
+
2623
2656
  static newFrom(meeting ) {
2624
2657
  return newFrom(meeting, Meeting);
2625
2658
  }
2626
2659
 
2627
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2660
+ constructor({
2661
+ uuid,
2662
+ name,
2663
+ guestSipAuthorization,
2664
+ ownerUuids,
2665
+ port,
2666
+ uri,
2667
+ number,
2668
+ persistent,
2669
+ } = {}) {
2628
2670
  this.guestSipAuthorization = guestSipAuthorization;
2629
2671
  this.uri = uri;
2630
2672
  this.name = name;
@@ -2710,8 +2752,11 @@ var confdMethods = (client , baseUrl ) => ({
2710
2752
  }
2711
2753
  },
2712
2754
 
2713
- createMyMeeting: (name ) =>
2714
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2755
+ getMyMeetings: () =>
2756
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2757
+
2758
+ createMyMeeting: (name , persistent ) =>
2759
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2715
2760
 
2716
2761
  deleteMyMeeting: (meetingUuid ) =>
2717
2762
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2807,6 +2852,10 @@ class ChatMessage {
2807
2852
 
2808
2853
 
2809
2854
  static parseMany(plain ) {
2855
+ if (!plain || !plain.items) {
2856
+ return [];
2857
+ }
2858
+
2810
2859
  return plain.items.map(item => ChatMessage.parse(item));
2811
2860
  }
2812
2861
 
@@ -2916,6 +2965,9 @@ class Voicemail {
2916
2965
  }
2917
2966
 
2918
2967
  static parseMany(plain ) {
2968
+ if (!plain) {
2969
+ return [];
2970
+ }
2919
2971
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2920
2972
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2921
2973
 
@@ -3025,6 +3077,9 @@ class Call {
3025
3077
 
3026
3078
 
3027
3079
  static parseMany(plain ) {
3080
+ if (!plain) {
3081
+ return [];
3082
+ }
3028
3083
  return plain.map((plainCall ) => Call.parse(plainCall));
3029
3084
  }
3030
3085
 
@@ -3197,6 +3252,9 @@ class Recording {
3197
3252
 
3198
3253
 
3199
3254
  static parseMany(recordings = []) {
3255
+ if (!recordings) {
3256
+ return [];
3257
+ }
3200
3258
  return recordings.map(item => Recording.parse(item));
3201
3259
  }
3202
3260
 
@@ -3298,6 +3356,10 @@ class CallLog {
3298
3356
  }
3299
3357
 
3300
3358
  static parseMany(plain ) {
3359
+ if (!plain || !plain.items) {
3360
+ return [];
3361
+ }
3362
+
3301
3363
  return plain.items.map(item => CallLog.parse(item));
3302
3364
  }
3303
3365
 
@@ -3870,6 +3932,9 @@ class ChatRoom {
3870
3932
 
3871
3933
 
3872
3934
  static parseMany(plain ) {
3935
+ if (!plain || !plain.items) {
3936
+ return [];
3937
+ }
3873
3938
  return plain.items.map(item => ChatRoom.parse(item));
3874
3939
  }
3875
3940
 
@@ -136,6 +136,7 @@ class IssueReporter {
136
136
 
137
137
 
138
138
 
139
+
139
140
 
140
141
  constructor() {
141
142
  addLevelsTo(this);
@@ -147,12 +148,17 @@ class IssueReporter {
147
148
  this.bufferTimeout = null;
148
149
  this._boundProcessBuffer = this._processBuffer.bind(this);
149
150
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
151
+ this._callback = null;
150
152
  }
151
153
 
152
154
  init() {
153
155
  this._catchConsole();
154
156
  }
155
157
 
158
+ setCallback(cb ) {
159
+ this._callback = cb;
160
+ }
161
+
156
162
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
157
163
  this.remoteClientConfiguration = configuration;
158
164
  }
@@ -188,6 +194,7 @@ class IssueReporter {
188
194
 
189
195
  // Handle category label
190
196
  let category = null;
197
+ let skipSendToRemote = false;
191
198
  let extra = {};
192
199
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
193
200
  category = args[0].split('=')[1];
@@ -203,6 +210,7 @@ class IssueReporter {
203
210
  errorMessage: lastArg.message,
204
211
  errorStack: lastArg.stack,
205
212
  errorType: lastArg.constructor.name,
213
+ skipSendToRemote: lastArg.skipSendToRemote,
206
214
  };
207
215
  } else {
208
216
  extra = lastArg;
@@ -211,6 +219,11 @@ class IssueReporter {
211
219
  args.splice(1, 1);
212
220
  }
213
221
 
222
+ if (extra.skipSendToRemote) {
223
+ skipSendToRemote = true;
224
+ delete extra.skipSendToRemote;
225
+ }
226
+
214
227
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
215
228
  const message = args.join(', ');
216
229
  let consoleMessage = message;
@@ -231,7 +244,13 @@ class IssueReporter {
231
244
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
232
245
  oldMethod.apply(oldMethod, [date, consoleMessage]);
233
246
 
234
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
247
+ if (this._callback) {
248
+ this._callback(level, consoleMessage);
249
+ }
250
+
251
+ if (!skipSendToRemote) {
252
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
253
+ }
235
254
  }
236
255
 
237
256
  logRequest(url , options , response , start ) {
@@ -376,7 +395,11 @@ class IssueReporter {
376
395
  },
377
396
  // $FlowFixMe
378
397
  body,
379
- }).catch(() => {
398
+ }).catch((e ) => {
399
+ // $FlowFixMe
400
+ e.skipSendToRemote = true;
401
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
402
+
380
403
  setTimeout(() => {
381
404
  if (isArray) {
382
405
  payload = payload.map(message => {
@@ -1514,6 +1537,9 @@ class Contact {
1514
1537
  }
1515
1538
 
1516
1539
  static parseMany(response ) {
1540
+ if (!response || !response.results) {
1541
+ return [];
1542
+ }
1517
1543
  return response.results.map(r => Contact.parse(r, response.column_types));
1518
1544
  }
1519
1545
 
@@ -2620,11 +2646,27 @@ class Meeting {
2620
2646
  });
2621
2647
  }
2622
2648
 
2649
+ static parseMany(items ) {
2650
+ if (!items) {
2651
+ return [];
2652
+ }
2653
+ return items.map(plain => Meeting.parse(plain));
2654
+ }
2655
+
2623
2656
  static newFrom(meeting ) {
2624
2657
  return newFrom(meeting, Meeting);
2625
2658
  }
2626
2659
 
2627
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2660
+ constructor({
2661
+ uuid,
2662
+ name,
2663
+ guestSipAuthorization,
2664
+ ownerUuids,
2665
+ port,
2666
+ uri,
2667
+ number,
2668
+ persistent,
2669
+ } = {}) {
2628
2670
  this.guestSipAuthorization = guestSipAuthorization;
2629
2671
  this.uri = uri;
2630
2672
  this.name = name;
@@ -2710,8 +2752,11 @@ var confdMethods = (client , baseUrl ) => ({
2710
2752
  }
2711
2753
  },
2712
2754
 
2713
- createMyMeeting: (name ) =>
2714
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2755
+ getMyMeetings: () =>
2756
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2757
+
2758
+ createMyMeeting: (name , persistent ) =>
2759
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2715
2760
 
2716
2761
  deleteMyMeeting: (meetingUuid ) =>
2717
2762
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2807,6 +2852,10 @@ class ChatMessage {
2807
2852
 
2808
2853
 
2809
2854
  static parseMany(plain ) {
2855
+ if (!plain || !plain.items) {
2856
+ return [];
2857
+ }
2858
+
2810
2859
  return plain.items.map(item => ChatMessage.parse(item));
2811
2860
  }
2812
2861
 
@@ -2916,6 +2965,9 @@ class Voicemail {
2916
2965
  }
2917
2966
 
2918
2967
  static parseMany(plain ) {
2968
+ if (!plain) {
2969
+ return [];
2970
+ }
2919
2971
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2920
2972
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2921
2973
 
@@ -3025,6 +3077,9 @@ class Call {
3025
3077
 
3026
3078
 
3027
3079
  static parseMany(plain ) {
3080
+ if (!plain) {
3081
+ return [];
3082
+ }
3028
3083
  return plain.map((plainCall ) => Call.parse(plainCall));
3029
3084
  }
3030
3085
 
@@ -3197,6 +3252,9 @@ class Recording {
3197
3252
 
3198
3253
 
3199
3254
  static parseMany(recordings = []) {
3255
+ if (!recordings) {
3256
+ return [];
3257
+ }
3200
3258
  return recordings.map(item => Recording.parse(item));
3201
3259
  }
3202
3260
 
@@ -3298,6 +3356,10 @@ class CallLog {
3298
3356
  }
3299
3357
 
3300
3358
  static parseMany(plain ) {
3359
+ if (!plain || !plain.items) {
3360
+ return [];
3361
+ }
3362
+
3301
3363
  return plain.items.map(item => CallLog.parse(item));
3302
3364
  }
3303
3365
 
@@ -3870,6 +3932,9 @@ class ChatRoom {
3870
3932
 
3871
3933
 
3872
3934
  static parseMany(plain ) {
3935
+ if (!plain || !plain.items) {
3936
+ return [];
3937
+ }
3873
3938
  return plain.items.map(item => ChatRoom.parse(item));
3874
3939
  }
3875
3940