@wazo/sdk 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (158) hide show
  1. package/README.md +16 -7
  2. package/dist/wazo-sdk.js +2 -2
  3. package/esm/__tests__/__voice__/call.test.js +52 -3
  4. package/esm/api/auth.js +3 -0
  5. package/esm/checker/checks/webrtc.js +2 -2
  6. package/esm/domain/CallLog.js +2 -3
  7. package/esm/domain/Phone/CTIPhone.js +2 -2
  8. package/esm/domain/Phone/WebRTCPhone.js +59 -57
  9. package/esm/index.js +3 -1
  10. package/esm/service/CallApi.js +4 -4
  11. package/esm/simple/Auth.js +13 -3
  12. package/esm/simple/Phone.js +5 -5
  13. package/esm/simple/index.js +2 -1
  14. package/esm/simple/room/Room.js +2 -2
  15. package/esm/simple/room/SipRoom.js +2 -2
  16. package/esm/state-machine/call-state-machine.js +34 -19
  17. package/esm/state-machine/softphone-state-machine.js +1 -2
  18. package/esm/state-machine/utils.js +10 -4
  19. package/esm/types/api/auth.d.ts +3 -0
  20. package/esm/types/api/auth.d.ts.map +1 -1
  21. package/esm/types/checker/checks/index.d.ts +1 -1
  22. package/esm/types/checker/checks/webrtc-transport.d.ts +2 -2
  23. package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -1
  24. package/esm/types/domain/CallLog.d.ts.map +1 -1
  25. package/esm/types/domain/CallSession.d.ts +3 -3
  26. package/esm/types/domain/CallSession.d.ts.map +1 -1
  27. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  28. package/esm/types/domain/Phone/WebRTCPhone.d.ts +22 -22
  29. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  30. package/esm/types/domain/types.d.ts +0 -4
  31. package/esm/types/domain/types.d.ts.map +1 -1
  32. package/esm/types/index.d.ts +3 -1
  33. package/esm/types/index.d.ts.map +1 -1
  34. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +3 -3
  35. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
  36. package/esm/types/service/CallApi.d.ts +5 -5
  37. package/esm/types/service/CallApi.d.ts.map +1 -1
  38. package/esm/types/simple/Auth.d.ts +6 -1
  39. package/esm/types/simple/Auth.d.ts.map +1 -1
  40. package/esm/types/simple/Phone.d.ts +8 -8
  41. package/esm/types/simple/Phone.d.ts.map +1 -1
  42. package/esm/types/simple/index.d.ts +3 -1
  43. package/esm/types/simple/index.d.ts.map +1 -1
  44. package/esm/types/state-machine/call-state-machine.d.ts +12 -1
  45. package/esm/types/state-machine/call-state-machine.d.ts.map +1 -1
  46. package/esm/types/state-machine/softphone-state-machine.d.ts +1 -2
  47. package/esm/types/state-machine/softphone-state-machine.d.ts.map +1 -1
  48. package/esm/types/state-machine/utils.d.ts +1 -1
  49. package/esm/types/state-machine/utils.d.ts.map +1 -1
  50. package/esm/types/utils/sdp.d.ts +1 -2
  51. package/esm/types/utils/sdp.d.ts.map +1 -1
  52. package/esm/types/utils/update-from.d.ts +1 -1
  53. package/esm/types/utils/update-from.d.ts.map +1 -1
  54. package/esm/types/utils/webrtc.d.ts.map +1 -1
  55. package/esm/types/voice/call.d.ts +15 -3
  56. package/esm/types/voice/call.d.ts.map +1 -1
  57. package/esm/types/voice/softphone.d.ts +7 -0
  58. package/esm/types/voice/softphone.d.ts.map +1 -1
  59. package/esm/types/web-rtc-client.d.ts +39 -38
  60. package/esm/types/web-rtc-client.d.ts.map +1 -1
  61. package/esm/utils/sdp.js +16 -9
  62. package/esm/utils/update-from.js +2 -2
  63. package/esm/utils/webrtc.js +10 -4
  64. package/esm/voice/call.js +86 -28
  65. package/esm/voice/softphone.js +58 -17
  66. package/esm/web-rtc-client.js +67 -58
  67. package/lib/__tests__/__voice__/call.test.js +51 -2
  68. package/lib/api/auth.js +3 -0
  69. package/lib/checker/checks/webrtc.js +1 -1
  70. package/lib/domain/CallLog.js +2 -3
  71. package/lib/domain/Phone/CTIPhone.js +2 -2
  72. package/lib/domain/Phone/WebRTCPhone.js +58 -56
  73. package/lib/index.js +7 -3
  74. package/lib/service/CallApi.js +2 -2
  75. package/lib/simple/Auth.js +15 -3
  76. package/lib/simple/Phone.js +2 -2
  77. package/lib/simple/index.js +2 -1
  78. package/lib/simple/room/Room.js +1 -1
  79. package/lib/simple/room/SipRoom.js +1 -1
  80. package/lib/state-machine/call-state-machine.js +35 -20
  81. package/lib/state-machine/softphone-state-machine.js +1 -2
  82. package/lib/state-machine/utils.js +10 -4
  83. package/lib/types/api/auth.d.ts +3 -0
  84. package/lib/types/api/auth.d.ts.map +1 -1
  85. package/lib/types/checker/checks/index.d.ts +1 -1
  86. package/lib/types/checker/checks/webrtc-transport.d.ts +2 -2
  87. package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -1
  88. package/lib/types/domain/CallLog.d.ts.map +1 -1
  89. package/lib/types/domain/CallSession.d.ts +3 -3
  90. package/lib/types/domain/CallSession.d.ts.map +1 -1
  91. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  92. package/lib/types/domain/Phone/WebRTCPhone.d.ts +22 -22
  93. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  94. package/lib/types/domain/types.d.ts +0 -4
  95. package/lib/types/domain/types.d.ts.map +1 -1
  96. package/lib/types/index.d.ts +3 -1
  97. package/lib/types/index.d.ts.map +1 -1
  98. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +3 -3
  99. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
  100. package/lib/types/service/CallApi.d.ts +5 -5
  101. package/lib/types/service/CallApi.d.ts.map +1 -1
  102. package/lib/types/simple/Auth.d.ts +6 -1
  103. package/lib/types/simple/Auth.d.ts.map +1 -1
  104. package/lib/types/simple/Phone.d.ts +8 -8
  105. package/lib/types/simple/Phone.d.ts.map +1 -1
  106. package/lib/types/simple/index.d.ts +3 -1
  107. package/lib/types/simple/index.d.ts.map +1 -1
  108. package/lib/types/state-machine/call-state-machine.d.ts +12 -1
  109. package/lib/types/state-machine/call-state-machine.d.ts.map +1 -1
  110. package/lib/types/state-machine/softphone-state-machine.d.ts +1 -2
  111. package/lib/types/state-machine/softphone-state-machine.d.ts.map +1 -1
  112. package/lib/types/state-machine/utils.d.ts +1 -1
  113. package/lib/types/state-machine/utils.d.ts.map +1 -1
  114. package/lib/types/utils/sdp.d.ts +1 -2
  115. package/lib/types/utils/sdp.d.ts.map +1 -1
  116. package/lib/types/utils/update-from.d.ts +1 -1
  117. package/lib/types/utils/update-from.d.ts.map +1 -1
  118. package/lib/types/utils/webrtc.d.ts.map +1 -1
  119. package/lib/types/voice/call.d.ts +15 -3
  120. package/lib/types/voice/call.d.ts.map +1 -1
  121. package/lib/types/voice/softphone.d.ts +7 -0
  122. package/lib/types/voice/softphone.d.ts.map +1 -1
  123. package/lib/types/web-rtc-client.d.ts +39 -38
  124. package/lib/types/web-rtc-client.d.ts.map +1 -1
  125. package/lib/utils/sdp.js +17 -10
  126. package/lib/utils/update-from.js +2 -2
  127. package/lib/utils/webrtc.js +11 -4
  128. package/lib/voice/call.js +89 -27
  129. package/lib/voice/softphone.js +62 -17
  130. package/lib/web-rtc-client.js +66 -57
  131. package/package.json +1 -1
  132. package/src/__tests__/__voice__/call.test.ts +61 -3
  133. package/src/api/auth.ts +5 -0
  134. package/src/checker/checks/webrtc-transport.ts +2 -2
  135. package/src/checker/checks/webrtc.ts +2 -2
  136. package/src/domain/CallLog.ts +2 -3
  137. package/src/domain/CallSession.ts +3 -3
  138. package/src/domain/Phone/CTIPhone.ts +3 -2
  139. package/src/domain/Phone/WebRTCPhone.ts +87 -85
  140. package/src/domain/__tests__/CallSession.test.ts +4 -0
  141. package/src/domain/types.ts +0 -5
  142. package/src/index.ts +4 -1
  143. package/src/lib/WazoSessionDescriptionHandler.ts +3 -3
  144. package/src/service/CallApi.ts +7 -7
  145. package/src/simple/Auth.ts +15 -3
  146. package/src/simple/Phone.ts +11 -11
  147. package/src/simple/index.ts +2 -1
  148. package/src/simple/room/Room.ts +3 -3
  149. package/src/simple/room/SipRoom.ts +3 -3
  150. package/src/state-machine/call-state-machine.ts +38 -19
  151. package/src/state-machine/softphone-state-machine.ts +1 -2
  152. package/src/state-machine/utils.ts +12 -4
  153. package/src/utils/sdp.ts +18 -11
  154. package/src/utils/update-from.ts +2 -2
  155. package/src/utils/webrtc.ts +11 -4
  156. package/src/voice/call.ts +109 -36
  157. package/src/voice/softphone.ts +75 -18
  158. package/src/web-rtc-client.ts +112 -98
@@ -47,6 +47,7 @@ const IssueReporter_1 = __importDefault(require("../service/IssueReporter"));
47
47
  const sip_logger_1 = __importDefault(require("../utils/sip-logger"));
48
48
  const call_1 = __importDefault(require("./call"));
49
49
  const utils_1 = require("../state-machine/utils");
50
+ const sdp_1 = require("../utils/sdp");
50
51
  exports.EVENT_INCOMING = 'incoming';
51
52
  exports.EVENT_OUTGOING = 'outgoing';
52
53
  exports.EVENT_HEARTBEAT = 'heartbeat';
@@ -80,6 +81,7 @@ class Softphone extends events_1.EventEmitter {
80
81
  this.audioRingVolume = 1;
81
82
  const server = __1.default.Auth.getHost();
82
83
  const session = __1.default.Auth.getSession();
84
+ logger.info('softphone - connect', { server, session: !!session });
83
85
  if (!server || !session) {
84
86
  throw new Error('Please connect to the server using `Wazo.Auth.logIn` or `Wazo.Auth.authenticate` before using Room.connect().');
85
87
  }
@@ -91,15 +93,23 @@ class Softphone extends events_1.EventEmitter {
91
93
  this.options.userUuid = session.uuid || '';
92
94
  return this.connectWithCredentials(server, this.sipLine, session.displayName(), options);
93
95
  }
96
+ hangupAllCalls() {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ return Promise.all(this.calls.map(call => call.hangup()));
99
+ });
100
+ }
94
101
  disconnect() {
95
102
  return __awaiter(this, void 0, void 0, function* () {
96
103
  (0, utils_1.assertCan)(this.softphoneActor, softphone_state_machine_1.Actions.UNREGISTER);
104
+ logger.info('softphone - disconnect');
97
105
  if (!this.client) {
106
+ logger.info('softphone - disconnect, not client to disconnect, bailing');
98
107
  return null;
99
108
  }
100
109
  // Terminate all calls
101
- yield Promise.all(this.calls.map(call => call.hangup()));
102
- return this.client.unregister();
110
+ yield this.hangupAllCalls();
111
+ yield this.client.unregister();
112
+ return this.client.close();
103
113
  });
104
114
  }
105
115
  getPrimaryWebRtcLine() {
@@ -109,7 +119,8 @@ class Softphone extends events_1.EventEmitter {
109
119
  connectWithCredentials(server_1, sipLine_1, displayName_1) {
110
120
  return __awaiter(this, arguments, void 0, function* (server, sipLine, displayName, rawOptions = {}) {
111
121
  (0, utils_1.assertCan)(this.softphoneActor, softphone_state_machine_1.Actions.REGISTER);
112
- this.softphoneActor.send({ type: softphone_state_machine_1.Actions.REGISTER });
122
+ logger.info('softphone - connect with credentials', { server, username: sipLine.username, displayName, options: rawOptions });
123
+ this._sendAction(softphone_state_machine_1.Actions.REGISTER);
113
124
  const [host, port = 443] = server.split(':');
114
125
  let options = Object.assign({}, rawOptions);
115
126
  options.media = options.media || {
@@ -134,7 +145,7 @@ class Softphone extends events_1.EventEmitter {
134
145
  if (!this.client) {
135
146
  return;
136
147
  }
137
- this.client.attemptReconnection();
148
+ this.client.register();
138
149
  }
139
150
  call(options) {
140
151
  return __awaiter(this, void 0, void 0, function* () {
@@ -147,7 +158,7 @@ class Softphone extends events_1.EventEmitter {
147
158
  logger.info('softphone - calling when registering, waiting for Softphone to be registered ...');
148
159
  yield (0, utils_1.waitUntilState)(this.softphoneActor, softphone_state_machine_1.States.REGISTERED);
149
160
  }
150
- if (this.state !== softphone_state_machine_1.States.UNREGISTERED) {
161
+ if (this.state !== softphone_state_machine_1.States.REGISTERED) {
151
162
  throw new InvalidState_1.default(`Invalid state ${softphone_state_machine_1.States.UNREGISTERED}`, softphone_state_machine_1.States.UNREGISTERED);
152
163
  }
153
164
  // Hold other calls
@@ -156,6 +167,8 @@ class Softphone extends events_1.EventEmitter {
156
167
  try {
157
168
  sipCall = this.client.call(options.params.To, options.withCamera, options.audioOnly, options.conference, options);
158
169
  const call = new call_1.default(sipCall, this);
170
+ call.onMakeCall();
171
+ this.calls.push(call);
159
172
  this.emit(exports.EVENT_OUTGOING, call);
160
173
  return call;
161
174
  }
@@ -221,10 +234,12 @@ class Softphone extends events_1.EventEmitter {
221
234
  this.ringingEnabled = false;
222
235
  }
223
236
  holdAllCalls(exceptCall = null) {
224
- this.calls.filter(call => !call.isHeld() && call.id === (exceptCall === null || exceptCall === void 0 ? void 0 : exceptCall.id)).forEach(call => call.hold());
237
+ logger.info('softphone - hold all calls', { exceptId: exceptCall === null || exceptCall === void 0 ? void 0 : exceptCall.id, ids: this.calls.map(call => call.id) });
238
+ this.calls.filter(call => !call.isHeld() && call.id !== (exceptCall === null || exceptCall === void 0 ? void 0 : exceptCall.id)).forEach(call => call.hold());
225
239
  }
226
240
  startHeartbeat() {
227
- logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: this.client.hasHeartbeat() });
241
+ var _a;
242
+ logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: (_a = this.client) === null || _a === void 0 ? void 0 : _a.hasHeartbeat() });
228
243
  if (!this.client || this.client.hasHeartbeat()) {
229
244
  return;
230
245
  }
@@ -275,7 +290,10 @@ class Softphone extends events_1.EventEmitter {
275
290
  this.audioRingVolume = volume;
276
291
  }
277
292
  getCurrentCall() {
278
- return this.calls.find(call => call.isEstablished());
293
+ return this.getActiveCalls()[0];
294
+ }
295
+ getActiveCalls() {
296
+ return this.calls.filter(call => call.isEstablished());
279
297
  }
280
298
  getIncomingCalls() {
281
299
  return this.calls.filter(call => call.isRinging());
@@ -283,13 +301,23 @@ class Softphone extends events_1.EventEmitter {
283
301
  get state() {
284
302
  return (0, utils_1.getState)(this.softphoneActor);
285
303
  }
304
+ get user() {
305
+ var _a, _b, _c, _d;
306
+ return (_d = (_c = (_b = (_a = this.client) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.contact) === null || _c === void 0 ? void 0 : _c.uri) === null || _d === void 0 ? void 0 : _d.user;
307
+ }
286
308
  getUserAgent() {
287
309
  var _a, _b;
288
310
  return ((_b = (_a = this.client) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.userAgentString) || 'softphone';
289
311
  }
312
+ isRegistering() {
313
+ return this.state === softphone_state_machine_1.States.REGISTERING;
314
+ }
290
315
  isRegistered() {
291
316
  return this.state === softphone_state_machine_1.States.REGISTERED;
292
317
  }
318
+ isUnRegistered() {
319
+ return this.state === softphone_state_machine_1.States.UNREGISTERED;
320
+ }
293
321
  _bindEvents() {
294
322
  this.client.on(this.client.INVITE, (sipSession) => {
295
323
  const call = new call_1.default(sipSession, this);
@@ -308,7 +336,7 @@ class Softphone extends events_1.EventEmitter {
308
336
  });
309
337
  this.client.on(this.client.ON_REINVITE, (sipCall, request, updatedCalleeName, updatedNumber, hadRemoteVideo) => {
310
338
  logger.info('softphone - on reinvite', {
311
- callId: sipCall.id,
339
+ callId: (0, sdp_1.getSipCallId)(sipCall),
312
340
  inviteId: request.callId,
313
341
  updatedCalleeName,
314
342
  updatedNumber,
@@ -348,18 +376,26 @@ class Softphone extends events_1.EventEmitter {
348
376
  });
349
377
  this.client.on(this.client.UNREGISTERED, () => {
350
378
  logger.info('softphone - unregistered');
379
+ if (!(0, utils_1.can)(this.softphoneActor, softphone_state_machine_1.Actions.UNREGISTER)) {
380
+ logger.warn('softphone - cannot unregister', { state: this.state });
381
+ return;
382
+ }
383
+ this._sendAction(softphone_state_machine_1.Actions.UNREGISTER);
351
384
  this.emit(exports.EVENT_UNREGISTERED);
352
- this._sendAction(softphone_state_machine_1.Actions.UNREGISTERED);
353
385
  });
354
386
  this.client.on(this.client.ON_DISCONNECTED, () => {
355
387
  logger.info('softphone - disconnected');
356
- this.emit(exports.EVENT_DISCONNECTED);
388
+ if (!(0, utils_1.can)(this.softphoneActor, softphone_state_machine_1.Actions.TRANSPORT_CLOSED)) {
389
+ logger.warn('softphone - cannot disconnected', { state: this.state });
390
+ return;
391
+ }
357
392
  this._sendAction(softphone_state_machine_1.Actions.TRANSPORT_CLOSED);
393
+ this.emit(exports.EVENT_DISCONNECTED);
358
394
  });
359
395
  this.client.on(this.client.REGISTERED, () => {
360
- logger.info('softphone - registered', { state: (0, utils_1.getState)(this.softphoneActor) });
396
+ logger.info('softphone - registered', { state: (0, utils_1.getState)(this.softphoneActor), reinvite: this.shouldSendReinvite });
361
397
  if (!(0, utils_1.can)(this.softphoneActor, softphone_state_machine_1.Actions.REGISTER_DONE)) {
362
- logger.warn('softphone - registered but not in REGISTERING state', { state: (0, utils_1.getState)(this.softphoneActor) });
398
+ logger.warn('softphone - registered but not in REGISTERING state', { state: this.state });
363
399
  return;
364
400
  }
365
401
  this.stopHeartbeat();
@@ -375,9 +411,13 @@ class Softphone extends events_1.EventEmitter {
375
411
  }
376
412
  });
377
413
  this.client.on(this.client.CONNECTED, () => {
378
- logger.info('softphone - connected');
414
+ logger.info('softphone - connected', { state: this.state });
379
415
  this.stopHeartbeat();
380
416
  });
417
+ this.client.on(this.client.REGISTERING, () => {
418
+ logger.info('softphone - registering', { state: this.state });
419
+ this._sendAction(softphone_state_machine_1.Actions.REGISTER);
420
+ });
381
421
  this.client.on(this.client.DISCONNECTED, () => {
382
422
  logger.info('softphone - disconnected');
383
423
  this.emit(exports.EVENT_DISCONNECTED);
@@ -403,16 +443,21 @@ class Softphone extends events_1.EventEmitter {
403
443
  });
404
444
  }
405
445
  _sendAction(action) {
446
+ const was = this.state;
406
447
  this.softphoneActor.send({ type: action });
448
+ logger.trace('softphone - send action', { action, was, state: this.state });
407
449
  }
408
450
  _getCall(sipCall) {
409
- return this.calls.find(call => call.id === sipCall.id);
451
+ return this.calls.find(call => call.id === (0, sdp_1.getSipCallId)(sipCall));
452
+ }
453
+ _getCallIds() {
454
+ return this.calls.map(call => call.id);
410
455
  }
411
456
  _onCallEvent(sipCall, eventName, ...args) {
412
- logger.warn('softphone - received call event', { eventName, sipId: sipCall.id });
457
+ logger.info('softphone - received call event', { eventName, sipId: (0, sdp_1.getSipCallId)(sipCall) });
413
458
  const call = this._getCall(sipCall);
414
459
  if (!call) {
415
- logger.warn('softphone - no call found to send the event', { eventName, sipId: sipCall.id });
460
+ logger.warn('softphone - no call found to send the event', { eventName, sipId: (0, sdp_1.getSipCallId)(sipCall), ids: this._getCallIds() });
416
461
  return;
417
462
  }
418
463
  // @ts-ignore