@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
@@ -9,6 +9,7 @@ import IssueReporter from '../service/IssueReporter';
9
9
  import configureLogger from '../utils/sip-logger';
10
10
  import Call from './call';
11
11
  import { assertCan, can, getState, waitUntilState } from '../state-machine/utils';
12
+ import { getSipCallId } from '../utils/sdp';
12
13
  export const EVENT_INCOMING = 'incoming';
13
14
  export const EVENT_OUTGOING = 'outgoing';
14
15
  export const EVENT_HEARTBEAT = 'heartbeat';
@@ -53,6 +54,7 @@ export class Softphone extends EventEmitter {
53
54
  this.audioRingVolume = 1;
54
55
  const server = Wazo.Auth.getHost();
55
56
  const session = Wazo.Auth.getSession();
57
+ logger.info('softphone - connect', { server, session: !!session });
56
58
  if (!server || !session) {
57
59
  throw new Error('Please connect to the server using `Wazo.Auth.logIn` or `Wazo.Auth.authenticate` before using Room.connect().');
58
60
  }
@@ -64,21 +66,28 @@ export class Softphone extends EventEmitter {
64
66
  this.options.userUuid = session.uuid || '';
65
67
  return this.connectWithCredentials(server, this.sipLine, session.displayName(), options);
66
68
  }
69
+ async hangupAllCalls() {
70
+ return Promise.all(this.calls.map(call => call.hangup()));
71
+ }
67
72
  async disconnect() {
68
73
  assertCan(this.softphoneActor, Actions.UNREGISTER);
74
+ logger.info('softphone - disconnect');
69
75
  if (!this.client) {
76
+ logger.info('softphone - disconnect, not client to disconnect, bailing');
70
77
  return null;
71
78
  }
72
79
  // Terminate all calls
73
- await Promise.all(this.calls.map(call => call.hangup()));
74
- return this.client.unregister();
80
+ await this.hangupAllCalls();
81
+ await this.client.unregister();
82
+ return this.client.close();
75
83
  }
76
84
  getPrimaryWebRtcLine() {
77
85
  return this.session?.primaryWebRtcLine() || null;
78
86
  }
79
87
  async connectWithCredentials(server, sipLine, displayName, rawOptions = {}) {
80
88
  assertCan(this.softphoneActor, Actions.REGISTER);
81
- this.softphoneActor.send({ type: Actions.REGISTER });
89
+ logger.info('softphone - connect with credentials', { server, username: sipLine.username, displayName, options: rawOptions });
90
+ this._sendAction(Actions.REGISTER);
82
91
  const [host, port = 443] = server.split(':');
83
92
  let options = { ...rawOptions };
84
93
  options.media = options.media || {
@@ -110,7 +119,7 @@ export class Softphone extends EventEmitter {
110
119
  if (!this.client) {
111
120
  return;
112
121
  }
113
- this.client.attemptReconnection();
122
+ this.client.register();
114
123
  }
115
124
  async call(options) {
116
125
  logger.info('softphone - call', options);
@@ -122,7 +131,7 @@ export class Softphone extends EventEmitter {
122
131
  logger.info('softphone - calling when registering, waiting for Softphone to be registered ...');
123
132
  await waitUntilState(this.softphoneActor, States.REGISTERED);
124
133
  }
125
- if (this.state !== States.UNREGISTERED) {
134
+ if (this.state !== States.REGISTERED) {
126
135
  throw new InvalidState(`Invalid state ${States.UNREGISTERED}`, States.UNREGISTERED);
127
136
  }
128
137
  // Hold other calls
@@ -131,6 +140,8 @@ export class Softphone extends EventEmitter {
131
140
  try {
132
141
  sipCall = this.client.call(options.params.To, options.withCamera, options.audioOnly, options.conference, options);
133
142
  const call = new Call(sipCall, this);
143
+ call.onMakeCall();
144
+ this.calls.push(call);
134
145
  this.emit(EVENT_OUTGOING, call);
135
146
  return call;
136
147
  }
@@ -195,10 +206,11 @@ export class Softphone extends EventEmitter {
195
206
  this.ringingEnabled = false;
196
207
  }
197
208
  holdAllCalls(exceptCall = null) {
198
- this.calls.filter(call => !call.isHeld() && call.id === exceptCall?.id).forEach(call => call.hold());
209
+ logger.info('softphone - hold all calls', { exceptId: exceptCall?.id, ids: this.calls.map(call => call.id) });
210
+ this.calls.filter(call => !call.isHeld() && call.id !== exceptCall?.id).forEach(call => call.hold());
199
211
  }
200
212
  startHeartbeat() {
201
- logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: this.client.hasHeartbeat() });
213
+ logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: this.client?.hasHeartbeat() });
202
214
  if (!this.client || this.client.hasHeartbeat()) {
203
215
  return;
204
216
  }
@@ -248,7 +260,10 @@ export class Softphone extends EventEmitter {
248
260
  this.audioRingVolume = volume;
249
261
  }
250
262
  getCurrentCall() {
251
- return this.calls.find(call => call.isEstablished());
263
+ return this.getActiveCalls()[0];
264
+ }
265
+ getActiveCalls() {
266
+ return this.calls.filter(call => call.isEstablished());
252
267
  }
253
268
  getIncomingCalls() {
254
269
  return this.calls.filter(call => call.isRinging());
@@ -256,12 +271,21 @@ export class Softphone extends EventEmitter {
256
271
  get state() {
257
272
  return getState(this.softphoneActor);
258
273
  }
274
+ get user() {
275
+ return this.client?.userAgent?.contact?.uri?.user;
276
+ }
259
277
  getUserAgent() {
260
278
  return this.client?.config?.userAgentString || 'softphone';
261
279
  }
280
+ isRegistering() {
281
+ return this.state === States.REGISTERING;
282
+ }
262
283
  isRegistered() {
263
284
  return this.state === States.REGISTERED;
264
285
  }
286
+ isUnRegistered() {
287
+ return this.state === States.UNREGISTERED;
288
+ }
265
289
  _bindEvents() {
266
290
  this.client.on(this.client.INVITE, (sipSession) => {
267
291
  const call = new Call(sipSession, this);
@@ -280,7 +304,7 @@ export class Softphone extends EventEmitter {
280
304
  });
281
305
  this.client.on(this.client.ON_REINVITE, (sipCall, request, updatedCalleeName, updatedNumber, hadRemoteVideo) => {
282
306
  logger.info('softphone - on reinvite', {
283
- callId: sipCall.id,
307
+ callId: getSipCallId(sipCall),
284
308
  inviteId: request.callId,
285
309
  updatedCalleeName,
286
310
  updatedNumber,
@@ -320,18 +344,26 @@ export class Softphone extends EventEmitter {
320
344
  });
321
345
  this.client.on(this.client.UNREGISTERED, () => {
322
346
  logger.info('softphone - unregistered');
347
+ if (!can(this.softphoneActor, Actions.UNREGISTER)) {
348
+ logger.warn('softphone - cannot unregister', { state: this.state });
349
+ return;
350
+ }
351
+ this._sendAction(Actions.UNREGISTER);
323
352
  this.emit(EVENT_UNREGISTERED);
324
- this._sendAction(Actions.UNREGISTERED);
325
353
  });
326
354
  this.client.on(this.client.ON_DISCONNECTED, () => {
327
355
  logger.info('softphone - disconnected');
328
- this.emit(EVENT_DISCONNECTED);
356
+ if (!can(this.softphoneActor, Actions.TRANSPORT_CLOSED)) {
357
+ logger.warn('softphone - cannot disconnected', { state: this.state });
358
+ return;
359
+ }
329
360
  this._sendAction(Actions.TRANSPORT_CLOSED);
361
+ this.emit(EVENT_DISCONNECTED);
330
362
  });
331
363
  this.client.on(this.client.REGISTERED, () => {
332
- logger.info('softphone - registered', { state: getState(this.softphoneActor) });
364
+ logger.info('softphone - registered', { state: getState(this.softphoneActor), reinvite: this.shouldSendReinvite });
333
365
  if (!can(this.softphoneActor, Actions.REGISTER_DONE)) {
334
- logger.warn('softphone - registered but not in REGISTERING state', { state: getState(this.softphoneActor) });
366
+ logger.warn('softphone - registered but not in REGISTERING state', { state: this.state });
335
367
  return;
336
368
  }
337
369
  this.stopHeartbeat();
@@ -347,9 +379,13 @@ export class Softphone extends EventEmitter {
347
379
  }
348
380
  });
349
381
  this.client.on(this.client.CONNECTED, () => {
350
- logger.info('softphone - connected');
382
+ logger.info('softphone - connected', { state: this.state });
351
383
  this.stopHeartbeat();
352
384
  });
385
+ this.client.on(this.client.REGISTERING, () => {
386
+ logger.info('softphone - registering', { state: this.state });
387
+ this._sendAction(Actions.REGISTER);
388
+ });
353
389
  this.client.on(this.client.DISCONNECTED, () => {
354
390
  logger.info('softphone - disconnected');
355
391
  this.emit(EVENT_DISCONNECTED);
@@ -375,16 +411,21 @@ export class Softphone extends EventEmitter {
375
411
  });
376
412
  }
377
413
  _sendAction(action) {
414
+ const was = this.state;
378
415
  this.softphoneActor.send({ type: action });
416
+ logger.trace('softphone - send action', { action, was, state: this.state });
379
417
  }
380
418
  _getCall(sipCall) {
381
- return this.calls.find(call => call.id === sipCall.id);
419
+ return this.calls.find(call => call.id === getSipCallId(sipCall));
420
+ }
421
+ _getCallIds() {
422
+ return this.calls.map(call => call.id);
382
423
  }
383
424
  _onCallEvent(sipCall, eventName, ...args) {
384
- logger.warn('softphone - received call event', { eventName, sipId: sipCall.id });
425
+ logger.info('softphone - received call event', { eventName, sipId: getSipCallId(sipCall) });
385
426
  const call = this._getCall(sipCall);
386
427
  if (!call) {
387
- logger.warn('softphone - no call found to send the event', { eventName, sipId: sipCall.id });
428
+ logger.warn('softphone - no call found to send the event', { eventName, sipId: getSipCallId(sipCall), ids: this._getCallIds() });
388
429
  return;
389
430
  }
390
431
  // @ts-ignore