@wazo/sdk 0.37.17 → 0.37.21

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 (118) hide show
  1. package/dist/wazo-sdk.js +3 -3
  2. package/esm/__tests__/api-client.test.js +52 -9
  3. package/esm/__tests__/web-rtc-client.test.js +96 -21
  4. package/esm/api/agentd.js +26 -3
  5. package/esm/api/amid.js +26 -3
  6. package/esm/api/application.js +26 -3
  7. package/esm/api/auth.js +26 -3
  8. package/esm/api/call-logd.js +28 -5
  9. package/esm/api/calld.js +26 -3
  10. package/esm/api/chatd.js +26 -3
  11. package/esm/api/confd.js +50 -7
  12. package/esm/api/ctid-ng.js +26 -3
  13. package/esm/api/dird.js +26 -3
  14. package/esm/api/webhookd.js +26 -3
  15. package/esm/api-client.js +52 -9
  16. package/esm/checker/Checker.js +98 -21
  17. package/esm/checker/checks/aor.js +52 -9
  18. package/esm/checker/checks/api.js +52 -9
  19. package/esm/checker/checks/index.js +98 -21
  20. package/esm/checker/checks/wazo-websocket.js +28 -3
  21. package/esm/checker/checks/webrtc-transport.js +96 -21
  22. package/esm/checker/checks/webrtc.js +96 -21
  23. package/esm/domain/AdHocAPIConference.js +52 -9
  24. package/esm/domain/CallLog.js +2 -2
  25. package/esm/domain/Features.js +52 -9
  26. package/esm/domain/Meeting.js +19 -2
  27. package/esm/domain/Phone/CTIPhone.js +52 -9
  28. package/esm/domain/Phone/WebRTCPhone.js +41 -5
  29. package/esm/domain/Recording.js +1 -1
  30. package/esm/domain/__tests__/CallLog.test.js +2 -2
  31. package/esm/index.js +119 -22
  32. package/esm/lib/WazoSessionDescriptionHandler.js +26 -3
  33. package/esm/service/CallApi.js +52 -9
  34. package/esm/service/IssueReporter.js +26 -3
  35. package/esm/service/__tests__/IssueReporter.test.js +26 -3
  36. package/esm/service/getApiClient.js +52 -9
  37. package/esm/simple/Auth.js +119 -22
  38. package/esm/simple/Configuration.js +119 -22
  39. package/esm/simple/Directory.js +52 -9
  40. package/esm/simple/Phone.js +119 -22
  41. package/esm/simple/Websocket.js +29 -3
  42. package/esm/simple/index.js +119 -22
  43. package/esm/simple/room/LocalParticipant.js +119 -22
  44. package/esm/simple/room/Participant.js +119 -22
  45. package/esm/simple/room/RemoteParticipant.js +119 -22
  46. package/esm/simple/room/Room.js +119 -22
  47. package/esm/simple/room/SipRoom.js +119 -22
  48. package/esm/simple/room/Stream.js +119 -22
  49. package/esm/simple/room/__tests__/RemoteParticipant.test.js +119 -22
  50. package/esm/simple/utils.js +119 -22
  51. package/esm/utils/__tests__/api-requester.test.js +26 -3
  52. package/esm/utils/api-requester.js +26 -3
  53. package/esm/web-rtc-client.js +96 -21
  54. package/esm/websocket-client.js +29 -4
  55. package/lib/__tests__/api-client.test.js +52 -9
  56. package/lib/__tests__/web-rtc-client.test.js +96 -21
  57. package/lib/api/agentd.js +26 -3
  58. package/lib/api/amid.js +26 -3
  59. package/lib/api/application.js +26 -3
  60. package/lib/api/auth.js +26 -3
  61. package/lib/api/call-logd.js +28 -5
  62. package/lib/api/calld.js +26 -3
  63. package/lib/api/chatd.js +26 -3
  64. package/lib/api/confd.js +50 -7
  65. package/lib/api/ctid-ng.js +26 -3
  66. package/lib/api/dird.js +26 -3
  67. package/lib/api/webhookd.js +26 -3
  68. package/lib/api-client.js +52 -9
  69. package/lib/checker/Checker.js +98 -21
  70. package/lib/checker/checks/aor.js +52 -9
  71. package/lib/checker/checks/api.js +52 -9
  72. package/lib/checker/checks/index.js +98 -21
  73. package/lib/checker/checks/wazo-websocket.js +28 -3
  74. package/lib/checker/checks/webrtc-transport.js +96 -21
  75. package/lib/checker/checks/webrtc.js +96 -21
  76. package/lib/domain/AdHocAPIConference.js +52 -9
  77. package/lib/domain/CallLog.js +2 -2
  78. package/lib/domain/Features.js +52 -9
  79. package/lib/domain/Meeting.js +19 -2
  80. package/lib/domain/Phone/CTIPhone.js +52 -9
  81. package/lib/domain/Phone/WebRTCPhone.js +41 -4
  82. package/lib/domain/Recording.js +1 -1
  83. package/lib/domain/__tests__/CallLog.test.js +2 -2
  84. package/lib/index.js +119 -22
  85. package/lib/lib/WazoSessionDescriptionHandler.js +26 -3
  86. package/lib/service/CallApi.js +52 -9
  87. package/lib/service/IssueReporter.js +26 -3
  88. package/lib/service/__tests__/IssueReporter.test.js +26 -3
  89. package/lib/service/getApiClient.js +52 -9
  90. package/lib/simple/Auth.js +119 -22
  91. package/lib/simple/Configuration.js +119 -22
  92. package/lib/simple/Directory.js +52 -9
  93. package/lib/simple/Phone.js +119 -22
  94. package/lib/simple/Websocket.js +29 -3
  95. package/lib/simple/index.js +119 -22
  96. package/lib/simple/room/LocalParticipant.js +119 -22
  97. package/lib/simple/room/Participant.js +119 -22
  98. package/lib/simple/room/RemoteParticipant.js +119 -22
  99. package/lib/simple/room/Room.js +119 -22
  100. package/lib/simple/room/SipRoom.js +119 -22
  101. package/lib/simple/room/Stream.js +119 -22
  102. package/lib/simple/room/__tests__/RemoteParticipant.test.js +119 -22
  103. package/lib/simple/utils.js +119 -22
  104. package/lib/utils/__tests__/api-requester.test.js +26 -3
  105. package/lib/utils/api-requester.js +26 -3
  106. package/lib/web-rtc-client.js +96 -21
  107. package/lib/websocket-client.js +29 -3
  108. package/package.json +2 -2
  109. package/src/api/confd.js +5 -2
  110. package/src/domain/CallLog.js +1 -1
  111. package/src/domain/Meeting.js +19 -2
  112. package/src/domain/Phone/WebRTCPhone.js +14 -1
  113. package/src/domain/Recording.js +1 -1
  114. package/src/service/IssueReporter.js +26 -3
  115. package/src/simple/Phone.js +5 -0
  116. package/src/types/WebSocketMessage.js +5 -1
  117. package/src/web-rtc-client.js +44 -12
  118. package/src/websocket-client.js +2 -0
@@ -72,6 +72,7 @@ class IssueReporter {
72
72
 
73
73
 
74
74
 
75
+
75
76
 
76
77
  constructor() {
77
78
  addLevelsTo(this);
@@ -83,12 +84,17 @@ class IssueReporter {
83
84
  this.bufferTimeout = null;
84
85
  this._boundProcessBuffer = this._processBuffer.bind(this);
85
86
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
87
+ this._callback = null;
86
88
  }
87
89
 
88
90
  init() {
89
91
  this._catchConsole();
90
92
  }
91
93
 
94
+ setCallback(cb ) {
95
+ this._callback = cb;
96
+ }
97
+
92
98
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
93
99
  this.remoteClientConfiguration = configuration;
94
100
  }
@@ -124,6 +130,7 @@ class IssueReporter {
124
130
 
125
131
  // Handle category label
126
132
  let category = null;
133
+ let skipSendToRemote = false;
127
134
  let extra = {};
128
135
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
129
136
  category = args[0].split('=')[1];
@@ -139,6 +146,7 @@ class IssueReporter {
139
146
  errorMessage: lastArg.message,
140
147
  errorStack: lastArg.stack,
141
148
  errorType: lastArg.constructor.name,
149
+ skipSendToRemote: lastArg.skipSendToRemote,
142
150
  };
143
151
  } else {
144
152
  extra = lastArg;
@@ -147,6 +155,11 @@ class IssueReporter {
147
155
  args.splice(1, 1);
148
156
  }
149
157
 
158
+ if (extra.skipSendToRemote) {
159
+ skipSendToRemote = true;
160
+ delete extra.skipSendToRemote;
161
+ }
162
+
150
163
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
151
164
  const message = args.join(', ');
152
165
  let consoleMessage = message;
@@ -167,7 +180,13 @@ class IssueReporter {
167
180
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
168
181
  oldMethod.apply(oldMethod, [date, consoleMessage]);
169
182
 
170
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
183
+ if (this._callback) {
184
+ this._callback(level, consoleMessage);
185
+ }
186
+
187
+ if (!skipSendToRemote) {
188
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
189
+ }
171
190
  }
172
191
 
173
192
  logRequest(url , options , response , start ) {
@@ -312,7 +331,11 @@ class IssueReporter {
312
331
  },
313
332
  // $FlowFixMe
314
333
  body,
315
- }).catch(() => {
334
+ }).catch((e ) => {
335
+ // $FlowFixMe
336
+ e.skipSendToRemote = true;
337
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
338
+
316
339
  setTimeout(() => {
317
340
  if (isArray) {
318
341
  payload = payload.map(message => {
@@ -324,7 +347,7 @@ class IssueReporter {
324
347
  payload._retry = retry + 1;
325
348
  }
326
349
 
327
- this._sendDebugToGrafana(body, retry + 1);
350
+ this._sendDebugToGrafana(payload, retry + 1);
328
351
  }, 5000 + retry * 1000);
329
352
  });
330
353
  }
@@ -426,7 +449,7 @@ class Recording {
426
449
 
427
450
 
428
451
 
429
- static parseMany(recordings ) {
452
+ static parseMany(recordings = []) {
430
453
  return recordings.map(item => Recording.parse(item));
431
454
  }
432
455
 
@@ -552,7 +575,7 @@ class CallLog {
552
575
  duration: (plain.duration || 0) * 1000, // duration is in seconds
553
576
  start: moment__default['default'](plain.start).toDate(),
554
577
  end: plain.end ? moment__default['default'](plain.end).toDate() : null,
555
- recordings: Recording.parseMany(plain.recordings),
578
+ recordings: Recording.parseMany(plain.recordings || []),
556
579
  });
557
580
  }
558
581
 
package/lib/api/calld.js CHANGED
@@ -133,6 +133,7 @@ class IssueReporter {
133
133
 
134
134
 
135
135
 
136
+
136
137
 
137
138
  constructor() {
138
139
  addLevelsTo(this);
@@ -144,12 +145,17 @@ class IssueReporter {
144
145
  this.bufferTimeout = null;
145
146
  this._boundProcessBuffer = this._processBuffer.bind(this);
146
147
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
148
+ this._callback = null;
147
149
  }
148
150
 
149
151
  init() {
150
152
  this._catchConsole();
151
153
  }
152
154
 
155
+ setCallback(cb ) {
156
+ this._callback = cb;
157
+ }
158
+
153
159
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
154
160
  this.remoteClientConfiguration = configuration;
155
161
  }
@@ -185,6 +191,7 @@ class IssueReporter {
185
191
 
186
192
  // Handle category label
187
193
  let category = null;
194
+ let skipSendToRemote = false;
188
195
  let extra = {};
189
196
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
190
197
  category = args[0].split('=')[1];
@@ -200,6 +207,7 @@ class IssueReporter {
200
207
  errorMessage: lastArg.message,
201
208
  errorStack: lastArg.stack,
202
209
  errorType: lastArg.constructor.name,
210
+ skipSendToRemote: lastArg.skipSendToRemote,
203
211
  };
204
212
  } else {
205
213
  extra = lastArg;
@@ -208,6 +216,11 @@ class IssueReporter {
208
216
  args.splice(1, 1);
209
217
  }
210
218
 
219
+ if (extra.skipSendToRemote) {
220
+ skipSendToRemote = true;
221
+ delete extra.skipSendToRemote;
222
+ }
223
+
211
224
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
212
225
  const message = args.join(', ');
213
226
  let consoleMessage = message;
@@ -228,7 +241,13 @@ class IssueReporter {
228
241
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
229
242
  oldMethod.apply(oldMethod, [date, consoleMessage]);
230
243
 
231
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
244
+ if (this._callback) {
245
+ this._callback(level, consoleMessage);
246
+ }
247
+
248
+ if (!skipSendToRemote) {
249
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
250
+ }
232
251
  }
233
252
 
234
253
  logRequest(url , options , response , start ) {
@@ -373,7 +392,11 @@ class IssueReporter {
373
392
  },
374
393
  // $FlowFixMe
375
394
  body,
376
- }).catch(() => {
395
+ }).catch((e ) => {
396
+ // $FlowFixMe
397
+ e.skipSendToRemote = true;
398
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
399
+
377
400
  setTimeout(() => {
378
401
  if (isArray) {
379
402
  payload = payload.map(message => {
@@ -385,7 +408,7 @@ class IssueReporter {
385
408
  payload._retry = retry + 1;
386
409
  }
387
410
 
388
- this._sendDebugToGrafana(body, retry + 1);
411
+ this._sendDebugToGrafana(payload, retry + 1);
389
412
  }, 5000 + retry * 1000);
390
413
  });
391
414
  }
package/lib/api/chatd.js CHANGED
@@ -132,6 +132,7 @@ class IssueReporter {
132
132
 
133
133
 
134
134
 
135
+
135
136
 
136
137
  constructor() {
137
138
  addLevelsTo(this);
@@ -143,12 +144,17 @@ class IssueReporter {
143
144
  this.bufferTimeout = null;
144
145
  this._boundProcessBuffer = this._processBuffer.bind(this);
145
146
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
147
+ this._callback = null;
146
148
  }
147
149
 
148
150
  init() {
149
151
  this._catchConsole();
150
152
  }
151
153
 
154
+ setCallback(cb ) {
155
+ this._callback = cb;
156
+ }
157
+
152
158
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
153
159
  this.remoteClientConfiguration = configuration;
154
160
  }
@@ -184,6 +190,7 @@ class IssueReporter {
184
190
 
185
191
  // Handle category label
186
192
  let category = null;
193
+ let skipSendToRemote = false;
187
194
  let extra = {};
188
195
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
189
196
  category = args[0].split('=')[1];
@@ -199,6 +206,7 @@ class IssueReporter {
199
206
  errorMessage: lastArg.message,
200
207
  errorStack: lastArg.stack,
201
208
  errorType: lastArg.constructor.name,
209
+ skipSendToRemote: lastArg.skipSendToRemote,
202
210
  };
203
211
  } else {
204
212
  extra = lastArg;
@@ -207,6 +215,11 @@ class IssueReporter {
207
215
  args.splice(1, 1);
208
216
  }
209
217
 
218
+ if (extra.skipSendToRemote) {
219
+ skipSendToRemote = true;
220
+ delete extra.skipSendToRemote;
221
+ }
222
+
210
223
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
211
224
  const message = args.join(', ');
212
225
  let consoleMessage = message;
@@ -227,7 +240,13 @@ class IssueReporter {
227
240
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
228
241
  oldMethod.apply(oldMethod, [date, consoleMessage]);
229
242
 
230
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
243
+ if (this._callback) {
244
+ this._callback(level, consoleMessage);
245
+ }
246
+
247
+ if (!skipSendToRemote) {
248
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
249
+ }
231
250
  }
232
251
 
233
252
  logRequest(url , options , response , start ) {
@@ -372,7 +391,11 @@ class IssueReporter {
372
391
  },
373
392
  // $FlowFixMe
374
393
  body,
375
- }).catch(() => {
394
+ }).catch((e ) => {
395
+ // $FlowFixMe
396
+ e.skipSendToRemote = true;
397
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
398
+
376
399
  setTimeout(() => {
377
400
  if (isArray) {
378
401
  payload = payload.map(message => {
@@ -384,7 +407,7 @@ class IssueReporter {
384
407
  payload._retry = retry + 1;
385
408
  }
386
409
 
387
- this._sendDebugToGrafana(body, retry + 1);
410
+ this._sendDebugToGrafana(payload, retry + 1);
388
411
  }, 5000 + retry * 1000);
389
412
  });
390
413
  }
package/lib/api/confd.js CHANGED
@@ -132,6 +132,7 @@ class IssueReporter {
132
132
 
133
133
 
134
134
 
135
+
135
136
 
136
137
  constructor() {
137
138
  addLevelsTo(this);
@@ -143,12 +144,17 @@ class IssueReporter {
143
144
  this.bufferTimeout = null;
144
145
  this._boundProcessBuffer = this._processBuffer.bind(this);
145
146
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
147
+ this._callback = null;
146
148
  }
147
149
 
148
150
  init() {
149
151
  this._catchConsole();
150
152
  }
151
153
 
154
+ setCallback(cb ) {
155
+ this._callback = cb;
156
+ }
157
+
152
158
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
153
159
  this.remoteClientConfiguration = configuration;
154
160
  }
@@ -184,6 +190,7 @@ class IssueReporter {
184
190
 
185
191
  // Handle category label
186
192
  let category = null;
193
+ let skipSendToRemote = false;
187
194
  let extra = {};
188
195
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
189
196
  category = args[0].split('=')[1];
@@ -199,6 +206,7 @@ class IssueReporter {
199
206
  errorMessage: lastArg.message,
200
207
  errorStack: lastArg.stack,
201
208
  errorType: lastArg.constructor.name,
209
+ skipSendToRemote: lastArg.skipSendToRemote,
202
210
  };
203
211
  } else {
204
212
  extra = lastArg;
@@ -207,6 +215,11 @@ class IssueReporter {
207
215
  args.splice(1, 1);
208
216
  }
209
217
 
218
+ if (extra.skipSendToRemote) {
219
+ skipSendToRemote = true;
220
+ delete extra.skipSendToRemote;
221
+ }
222
+
210
223
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
211
224
  const message = args.join(', ');
212
225
  let consoleMessage = message;
@@ -227,7 +240,13 @@ class IssueReporter {
227
240
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
228
241
  oldMethod.apply(oldMethod, [date, consoleMessage]);
229
242
 
230
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
243
+ if (this._callback) {
244
+ this._callback(level, consoleMessage);
245
+ }
246
+
247
+ if (!skipSendToRemote) {
248
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
249
+ }
231
250
  }
232
251
 
233
252
  logRequest(url , options , response , start ) {
@@ -372,7 +391,11 @@ class IssueReporter {
372
391
  },
373
392
  // $FlowFixMe
374
393
  body,
375
- }).catch(() => {
394
+ }).catch((e ) => {
395
+ // $FlowFixMe
396
+ e.skipSendToRemote = true;
397
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
398
+
376
399
  setTimeout(() => {
377
400
  if (isArray) {
378
401
  payload = payload.map(message => {
@@ -384,7 +407,7 @@ class IssueReporter {
384
407
  payload._retry = retry + 1;
385
408
  }
386
409
 
387
- this._sendDebugToGrafana(body, retry + 1);
410
+ this._sendDebugToGrafana(payload, retry + 1);
388
411
  }, 5000 + retry * 1000);
389
412
  });
390
413
  }
@@ -1265,7 +1288,8 @@ class ExternalApp {
1265
1288
 
1266
1289
 
1267
1290
 
1268
-
1291
+
1292
+
1269
1293
 
1270
1294
 
1271
1295
  class Meeting {
@@ -1277,6 +1301,7 @@ class Meeting {
1277
1301
 
1278
1302
 
1279
1303
 
1304
+
1280
1305
 
1281
1306
 
1282
1307
  static parse(plain ) {
@@ -1288,14 +1313,28 @@ class Meeting {
1288
1313
  port: plain.port,
1289
1314
  uuid: plain.uuid,
1290
1315
  number: plain.number,
1316
+ persistent: plain.persistent,
1291
1317
  });
1292
1318
  }
1293
1319
 
1320
+ static parseMany(items ) {
1321
+ return items.map(plain => Meeting.parse(plain));
1322
+ }
1323
+
1294
1324
  static newFrom(meeting ) {
1295
1325
  return newFrom(meeting, Meeting);
1296
1326
  }
1297
1327
 
1298
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number } = {}) {
1328
+ constructor({
1329
+ uuid,
1330
+ name,
1331
+ guestSipAuthorization,
1332
+ ownerUuids,
1333
+ port,
1334
+ uri,
1335
+ number,
1336
+ persistent,
1337
+ } = {}) {
1299
1338
  this.guestSipAuthorization = guestSipAuthorization;
1300
1339
  this.uri = uri;
1301
1340
  this.name = name;
@@ -1303,6 +1342,7 @@ class Meeting {
1303
1342
  this.port = port;
1304
1343
  this.uuid = uuid;
1305
1344
  this.number = number;
1345
+ this.persistent = persistent;
1306
1346
 
1307
1347
  // Useful to compare instead of instanceof with minified code
1308
1348
  this.type = 'Meeting';
@@ -1380,8 +1420,11 @@ var confd = (client , baseUrl ) => ({
1380
1420
  }
1381
1421
  },
1382
1422
 
1383
- createMyMeeting: (name ) =>
1384
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
1423
+ getMyMeetings: () =>
1424
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
1425
+
1426
+ createMyMeeting: (name , persistent ) =>
1427
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
1385
1428
 
1386
1429
  deleteMyMeeting: (meetingUuid ) =>
1387
1430
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -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 => {
@@ -388,7 +411,7 @@ class IssueReporter {
388
411
  payload._retry = retry + 1;
389
412
  }
390
413
 
391
- this._sendDebugToGrafana(body, retry + 1);
414
+ this._sendDebugToGrafana(payload, retry + 1);
392
415
  }, 5000 + retry * 1000);
393
416
  });
394
417
  }
package/lib/api/dird.js CHANGED
@@ -134,6 +134,7 @@ class IssueReporter {
134
134
 
135
135
 
136
136
 
137
+
137
138
 
138
139
  constructor() {
139
140
  addLevelsTo(this);
@@ -145,12 +146,17 @@ class IssueReporter {
145
146
  this.bufferTimeout = null;
146
147
  this._boundProcessBuffer = this._processBuffer.bind(this);
147
148
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
149
+ this._callback = null;
148
150
  }
149
151
 
150
152
  init() {
151
153
  this._catchConsole();
152
154
  }
153
155
 
156
+ setCallback(cb ) {
157
+ this._callback = cb;
158
+ }
159
+
154
160
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
155
161
  this.remoteClientConfiguration = configuration;
156
162
  }
@@ -186,6 +192,7 @@ class IssueReporter {
186
192
 
187
193
  // Handle category label
188
194
  let category = null;
195
+ let skipSendToRemote = false;
189
196
  let extra = {};
190
197
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
191
198
  category = args[0].split('=')[1];
@@ -201,6 +208,7 @@ class IssueReporter {
201
208
  errorMessage: lastArg.message,
202
209
  errorStack: lastArg.stack,
203
210
  errorType: lastArg.constructor.name,
211
+ skipSendToRemote: lastArg.skipSendToRemote,
204
212
  };
205
213
  } else {
206
214
  extra = lastArg;
@@ -209,6 +217,11 @@ class IssueReporter {
209
217
  args.splice(1, 1);
210
218
  }
211
219
 
220
+ if (extra.skipSendToRemote) {
221
+ skipSendToRemote = true;
222
+ delete extra.skipSendToRemote;
223
+ }
224
+
212
225
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
213
226
  const message = args.join(', ');
214
227
  let consoleMessage = message;
@@ -229,7 +242,13 @@ class IssueReporter {
229
242
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
230
243
  oldMethod.apply(oldMethod, [date, consoleMessage]);
231
244
 
232
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
245
+ if (this._callback) {
246
+ this._callback(level, consoleMessage);
247
+ }
248
+
249
+ if (!skipSendToRemote) {
250
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
251
+ }
233
252
  }
234
253
 
235
254
  logRequest(url , options , response , start ) {
@@ -374,7 +393,11 @@ class IssueReporter {
374
393
  },
375
394
  // $FlowFixMe
376
395
  body,
377
- }).catch(() => {
396
+ }).catch((e ) => {
397
+ // $FlowFixMe
398
+ e.skipSendToRemote = true;
399
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
400
+
378
401
  setTimeout(() => {
379
402
  if (isArray) {
380
403
  payload = payload.map(message => {
@@ -386,7 +409,7 @@ class IssueReporter {
386
409
  payload._retry = retry + 1;
387
410
  }
388
411
 
389
- this._sendDebugToGrafana(body, retry + 1);
412
+ this._sendDebugToGrafana(payload, retry + 1);
390
413
  }, 5000 + retry * 1000);
391
414
  });
392
415
  }
@@ -71,6 +71,7 @@ class IssueReporter {
71
71
 
72
72
 
73
73
 
74
+
74
75
 
75
76
  constructor() {
76
77
  addLevelsTo(this);
@@ -82,12 +83,17 @@ class IssueReporter {
82
83
  this.bufferTimeout = null;
83
84
  this._boundProcessBuffer = this._processBuffer.bind(this);
84
85
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
86
+ this._callback = null;
85
87
  }
86
88
 
87
89
  init() {
88
90
  this._catchConsole();
89
91
  }
90
92
 
93
+ setCallback(cb ) {
94
+ this._callback = cb;
95
+ }
96
+
91
97
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
92
98
  this.remoteClientConfiguration = configuration;
93
99
  }
@@ -123,6 +129,7 @@ class IssueReporter {
123
129
 
124
130
  // Handle category label
125
131
  let category = null;
132
+ let skipSendToRemote = false;
126
133
  let extra = {};
127
134
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
128
135
  category = args[0].split('=')[1];
@@ -138,6 +145,7 @@ class IssueReporter {
138
145
  errorMessage: lastArg.message,
139
146
  errorStack: lastArg.stack,
140
147
  errorType: lastArg.constructor.name,
148
+ skipSendToRemote: lastArg.skipSendToRemote,
141
149
  };
142
150
  } else {
143
151
  extra = lastArg;
@@ -146,6 +154,11 @@ class IssueReporter {
146
154
  args.splice(1, 1);
147
155
  }
148
156
 
157
+ if (extra.skipSendToRemote) {
158
+ skipSendToRemote = true;
159
+ delete extra.skipSendToRemote;
160
+ }
161
+
149
162
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
150
163
  const message = args.join(', ');
151
164
  let consoleMessage = message;
@@ -166,7 +179,13 @@ class IssueReporter {
166
179
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
167
180
  oldMethod.apply(oldMethod, [date, consoleMessage]);
168
181
 
169
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
182
+ if (this._callback) {
183
+ this._callback(level, consoleMessage);
184
+ }
185
+
186
+ if (!skipSendToRemote) {
187
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
188
+ }
170
189
  }
171
190
 
172
191
  logRequest(url , options , response , start ) {
@@ -311,7 +330,11 @@ class IssueReporter {
311
330
  },
312
331
  // $FlowFixMe
313
332
  body,
314
- }).catch(() => {
333
+ }).catch((e ) => {
334
+ // $FlowFixMe
335
+ e.skipSendToRemote = true;
336
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
337
+
315
338
  setTimeout(() => {
316
339
  if (isArray) {
317
340
  payload = payload.map(message => {
@@ -323,7 +346,7 @@ class IssueReporter {
323
346
  payload._retry = retry + 1;
324
347
  }
325
348
 
326
- this._sendDebugToGrafana(body, retry + 1);
349
+ this._sendDebugToGrafana(payload, retry + 1);
327
350
  }, 5000 + retry * 1000);
328
351
  });
329
352
  }