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

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 (50) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/__voice__/call.test.js +1 -0
  3. package/esm/domain/Phone/CTIPhone.js +2 -2
  4. package/esm/index.js +3 -1
  5. package/esm/service/CallApi.js +4 -4
  6. package/esm/simple/index.js +2 -1
  7. package/esm/state-machine/call-state-machine.js +1 -1
  8. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  9. package/esm/types/index.d.ts +3 -1
  10. package/esm/types/index.d.ts.map +1 -1
  11. package/esm/types/service/CallApi.d.ts +5 -5
  12. package/esm/types/service/CallApi.d.ts.map +1 -1
  13. package/esm/types/simple/index.d.ts +3 -1
  14. package/esm/types/simple/index.d.ts.map +1 -1
  15. package/esm/types/state-machine/softphone-state-machine.d.ts +1 -1
  16. package/esm/types/voice/call.d.ts +10 -2
  17. package/esm/types/voice/call.d.ts.map +1 -1
  18. package/esm/types/voice/softphone.d.ts +4 -0
  19. package/esm/types/voice/softphone.d.ts.map +1 -1
  20. package/esm/voice/call.js +33 -8
  21. package/esm/voice/softphone.js +11 -2
  22. package/lib/__tests__/__voice__/call.test.js +1 -0
  23. package/lib/domain/Phone/CTIPhone.js +2 -2
  24. package/lib/index.js +7 -3
  25. package/lib/service/CallApi.js +2 -2
  26. package/lib/simple/index.js +2 -1
  27. package/lib/state-machine/call-state-machine.js +1 -1
  28. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  29. package/lib/types/index.d.ts +3 -1
  30. package/lib/types/index.d.ts.map +1 -1
  31. package/lib/types/service/CallApi.d.ts +5 -5
  32. package/lib/types/service/CallApi.d.ts.map +1 -1
  33. package/lib/types/simple/index.d.ts +3 -1
  34. package/lib/types/simple/index.d.ts.map +1 -1
  35. package/lib/types/state-machine/softphone-state-machine.d.ts +1 -1
  36. package/lib/types/voice/call.d.ts +10 -2
  37. package/lib/types/voice/call.d.ts.map +1 -1
  38. package/lib/types/voice/softphone.d.ts +4 -0
  39. package/lib/types/voice/softphone.d.ts.map +1 -1
  40. package/lib/voice/call.js +35 -9
  41. package/lib/voice/softphone.js +14 -2
  42. package/package.json +1 -1
  43. package/src/__tests__/__voice__/call.test.ts +1 -0
  44. package/src/domain/Phone/CTIPhone.ts +3 -2
  45. package/src/index.ts +4 -1
  46. package/src/service/CallApi.ts +7 -7
  47. package/src/simple/index.ts +2 -1
  48. package/src/state-machine/call-state-machine.ts +1 -1
  49. package/src/voice/call.ts +42 -10
  50. package/src/voice/softphone.ts +15 -2
package/src/voice/call.ts CHANGED
@@ -11,7 +11,8 @@ import type { IncomingRequestMessage } from 'sip.js/lib/core/messages/incoming-r
11
11
  import callStateMachine, { type ActionTypes, Actions, type EstablishedActionTypes, EstablishedActions, States, type StateTypes, EstablishedStates, type EstablishedStateTypes, type CallActorRef } from '../state-machine/call-state-machine';
12
12
  import { SipCall, PeerConnection } from '../domain/types';
13
13
  import ApiCall from '../domain/Call';
14
-
14
+ import newFrom from '../utils/new-from';
15
+ import updateFrom from '../utils/update-from';
15
16
  import IssueReporter from '../service/IssueReporter';
16
17
  import softphone, { EVENT_TERMINATE_SOUND, Softphone } from './softphone';
17
18
  import { getCallDisplayName, getCallNumber, getSipSessionId } from '../utils/sdp';
@@ -32,7 +33,8 @@ export type ReinviteOptions = {
32
33
  };
33
34
 
34
35
  // Events
35
- export const EVENT_CALL_ACCEPTED = 'accepted';
36
+ export const EVENT_CALL_REMOTLY_ACCEPTED = 'remotelyAccepted';
37
+ export const EVENT_CALL_LOCALLY_ACCEPTED = 'locallyAccepted';
36
38
  export const EVENT_CALL_CANCELED = 'canceled';
37
39
  export const EVENT_PROGRESS = 'progress';
38
40
  export const EVENT_EARLY_MEDIA = 'earlyMedia';
@@ -88,6 +90,10 @@ class Call extends EventEmitter {
88
90
 
89
91
  currentScreenShare: Record<string, any> | null;
90
92
 
93
+ static newFrom(call: Call) {
94
+ return newFrom(call, Call);
95
+ }
96
+
91
97
  static parseCall(apiCall: ApiCall): Call {
92
98
  const sipCall = {
93
99
  id: apiCall.sipCallId,
@@ -170,6 +176,8 @@ class Call extends EventEmitter {
170
176
  return this.phone.client.answer(this.sipCall as Invitation, options.withCamera).then(() => {
171
177
  logger.info('call - accepted', { id: this.id, ...options });
172
178
 
179
+ this.emit(EVENT_CALL_LOCALLY_ACCEPTED, this);
180
+
173
181
  return this.id;
174
182
  }).catch(e => {
175
183
  logger.error(e);
@@ -343,10 +351,26 @@ class Call extends EventEmitter {
343
351
  return this._hasEstablishedState(EstablishedStates.HELD);
344
352
  }
345
353
 
354
+ isEstablishing() {
355
+ return this.sipCall.state === SessionState.Establishing;
356
+ }
357
+
346
358
  isEstablished() {
347
359
  return States.ESTABLISHED in (this.state as Record<StateTypes, EstablishedStateTypes>);
348
360
  }
349
361
 
362
+ isRinging() {
363
+ return this.state === States.RINGING;
364
+ }
365
+
366
+ isOutgoing() {
367
+ return this.sipCall instanceof Invitation;
368
+ }
369
+
370
+ isIncoming() {
371
+ return !this.isOutgoing();
372
+ }
373
+
350
374
  isConference(): boolean {
351
375
  return (getPeerConnection(this.sipCall) as PeerConnection)?.sfu;
352
376
  }
@@ -355,7 +379,7 @@ class Call extends EventEmitter {
355
379
  assertState(this.callActor, States.ESTABLISHED);
356
380
  logger.info('call - transfer', { id: this.id, target });
357
381
 
358
- this.phone.client.transfer(this.sipCall, target);
382
+ return this.phone.client.transfer(this.sipCall, target);
359
383
  }
360
384
 
361
385
  atxfer(): Record<string, any> | null | undefined {
@@ -528,7 +552,7 @@ class Call extends EventEmitter {
528
552
 
529
553
  onAccepted() {
530
554
  this._sendAction(Actions.REMOTLY_ACCEPTED);
531
- this.emit(EVENT_CALL_ACCEPTED);
555
+ this.emit(EVENT_CALL_REMOTLY_ACCEPTED);
532
556
  }
533
557
 
534
558
  onProgress() {
@@ -595,14 +619,22 @@ class Call extends EventEmitter {
595
619
  return isVideoRemotelyHeld(this.sipCall);
596
620
  }
597
621
 
598
- isRinging() {
599
- return this.state === States.RINGING;
600
- }
601
-
602
622
  onReinvite(request: IncomingRequestMessage, updatedCalleeName: string, updatedNumber: string, hadRemoteVideo: boolean) {
603
623
  this.emit(EVENT_REINVITE, request, updatedCalleeName, updatedNumber, hadRemoteVideo);
604
624
  }
605
625
 
626
+ updateFrom(call: Call) {
627
+ updateFrom(this, call);
628
+ }
629
+
630
+ is(otherCall: Call) {
631
+ return otherCall && this.id && this.id === otherCall.id;
632
+ }
633
+
634
+ shouldAutoAnswer() {
635
+ return !!this.sipCall.request.getHeader('alert-info');
636
+ }
637
+
606
638
  get id() {
607
639
  return getSipSessionId(this.sipCall);
608
640
  }
@@ -613,7 +645,7 @@ class Call extends EventEmitter {
613
645
 
614
646
  private _hasEstablishedState(establishedState: EstablishedStateTypes) {
615
647
  const state = this.state as Record<StateTypes, EstablishedStateTypes>;
616
- return States.ESTABLISHED in state && state[States.ESTABLISHED] === establishedState;
648
+ return typeof state === 'object' && States.ESTABLISHED in state && state[States.ESTABLISHED] === establishedState;
617
649
  }
618
650
 
619
651
  private _bindEvents() {
@@ -630,7 +662,7 @@ class Call extends EventEmitter {
630
662
  };
631
663
  }
632
664
 
633
- this.sipCall.stateChange.addListener((newState: SessionState) => {
665
+ this.sipCall?.stateChange?.addListener((newState: SessionState) => {
634
666
  switch (newState) {
635
667
  case SessionState.Terminating:
636
668
  logger.info('call - terminating', { id: this.id });
@@ -44,6 +44,7 @@ export type CallOptions = {
44
44
  // If audioOnly is set to true, all video stream will be deactivated, even remotes ones.
45
45
  audioOnly?: boolean,
46
46
  conference?: boolean,
47
+ extraHeaders?: Record<string, any>,
47
48
  };
48
49
 
49
50
  const logger = IssueReporter.loggerFor('softphone');
@@ -107,6 +108,10 @@ export class Softphone extends EventEmitter {
107
108
  return this.connectWithCredentials(server, this.sipLine, session.displayName(), options);
108
109
  }
109
110
 
111
+ async hangupAllCalls() {
112
+ return Promise.all(this.calls.map(call => call.hangup()));
113
+ }
114
+
110
115
  async disconnect() {
111
116
  assertCan(this.softphoneActor, Actions.UNREGISTER);
112
117
  if (!this.client) {
@@ -114,7 +119,7 @@ export class Softphone extends EventEmitter {
114
119
  }
115
120
 
116
121
  // Terminate all calls
117
- await Promise.all(this.calls.map(call => call.hangup()));
122
+ await this.hangupAllCalls();
118
123
 
119
124
  return this.client.unregister();
120
125
  }
@@ -348,7 +353,11 @@ export class Softphone extends EventEmitter {
348
353
  }
349
354
 
350
355
  getCurrentCall(): Call | undefined {
351
- return this.calls.find(call => call.isEstablished());
356
+ return this.getActiveCalls()[0];
357
+ }
358
+
359
+ getActiveCalls(): Call[] {
360
+ return this.calls.filter(call => call.isEstablished());
352
361
  }
353
362
 
354
363
  getIncomingCalls(): Call[] {
@@ -359,6 +368,10 @@ export class Softphone extends EventEmitter {
359
368
  return getState(this.softphoneActor) as StateTypes;
360
369
  }
361
370
 
371
+ get user() {
372
+ return this.client?.userAgent?.contact?.uri?.user;
373
+ }
374
+
362
375
  getUserAgent() {
363
376
  return this.client?.config?.userAgentString || 'softphone';
364
377
  }