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

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 (58) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/__voice__/call.test.js +12 -0
  3. package/esm/checker/checks/webrtc.js +2 -2
  4. package/esm/domain/Phone/WebRTCPhone.js +30 -30
  5. package/esm/simple/Phone.js +3 -3
  6. package/esm/simple/room/Room.js +2 -2
  7. package/esm/simple/room/SipRoom.js +2 -2
  8. package/esm/state-machine/utils.js +1 -1
  9. package/esm/types/domain/Phone/WebRTCPhone.d.ts +1 -1
  10. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  11. package/esm/types/simple/Phone.d.ts +1 -1
  12. package/esm/types/simple/Phone.d.ts.map +1 -1
  13. package/esm/types/utils/sdp.d.ts +2 -2
  14. package/esm/types/utils/sdp.d.ts.map +1 -1
  15. package/esm/types/voice/softphone.d.ts +1 -0
  16. package/esm/types/voice/softphone.d.ts.map +1 -1
  17. package/esm/types/web-rtc-client.d.ts +1 -1
  18. package/esm/types/web-rtc-client.d.ts.map +1 -1
  19. package/esm/utils/sdp.js +5 -5
  20. package/esm/utils/webrtc.js +3 -3
  21. package/esm/voice/call.js +4 -4
  22. package/esm/voice/softphone.js +10 -5
  23. package/esm/web-rtc-client.js +33 -31
  24. package/lib/__tests__/__voice__/call.test.js +12 -0
  25. package/lib/checker/checks/webrtc.js +1 -1
  26. package/lib/domain/Phone/WebRTCPhone.js +29 -29
  27. package/lib/simple/Phone.js +2 -2
  28. package/lib/simple/room/Room.js +1 -1
  29. package/lib/simple/room/SipRoom.js +1 -1
  30. package/lib/state-machine/utils.js +1 -1
  31. package/lib/types/domain/Phone/WebRTCPhone.d.ts +1 -1
  32. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  33. package/lib/types/simple/Phone.d.ts +1 -1
  34. package/lib/types/simple/Phone.d.ts.map +1 -1
  35. package/lib/types/utils/sdp.d.ts +2 -2
  36. package/lib/types/utils/sdp.d.ts.map +1 -1
  37. package/lib/types/voice/softphone.d.ts +1 -0
  38. package/lib/types/voice/softphone.d.ts.map +1 -1
  39. package/lib/types/web-rtc-client.d.ts +1 -1
  40. package/lib/types/web-rtc-client.d.ts.map +1 -1
  41. package/lib/utils/sdp.js +7 -7
  42. package/lib/utils/webrtc.js +2 -2
  43. package/lib/voice/call.js +4 -3
  44. package/lib/voice/softphone.js +10 -5
  45. package/lib/web-rtc-client.js +32 -30
  46. package/package.json +1 -1
  47. package/src/__tests__/__voice__/call.test.ts +15 -0
  48. package/src/checker/checks/webrtc.ts +2 -2
  49. package/src/domain/Phone/WebRTCPhone.ts +30 -30
  50. package/src/simple/Phone.ts +3 -3
  51. package/src/simple/room/Room.ts +2 -2
  52. package/src/simple/room/SipRoom.ts +2 -2
  53. package/src/state-machine/utils.ts +1 -1
  54. package/src/utils/sdp.ts +5 -5
  55. package/src/utils/webrtc.ts +3 -3
  56. package/src/voice/call.ts +4 -4
  57. package/src/voice/softphone.ts +11 -5
  58. package/src/web-rtc-client.ts +33 -31
package/esm/voice/call.js CHANGED
@@ -8,7 +8,7 @@ import newFrom from '../utils/new-from';
8
8
  import updateFrom from '../utils/update-from';
9
9
  import IssueReporter from '../service/IssueReporter';
10
10
  import softphone, { EVENT_TERMINATE_SOUND } from './softphone';
11
- import { getCallDisplayName, getCallNumber, getSipSessionId } from '../utils/sdp';
11
+ import { getCallDisplayName, getCallNumber, getSipCallId } from '../utils/sdp';
12
12
  import { assertCan, assertState, getState } from '../state-machine/utils';
13
13
  import { downgradeToAudio, getLocalStream, getLocalVideoStream, getPeerConnection, getRemoteStream, getRemoteVideoStream, getStreamFromConstraints, getWebRtcStats, hasALocalVideoTrack, hasLocalVideo, hasRemoteVideo, isVideoMuted, isVideoRemotelyHeld, setLocalMediaStream, toggleVideo, upgradeToVideo } from '../utils/webrtc';
14
14
  const logger = IssueReporter.loggerFor('call');
@@ -254,7 +254,7 @@ class Call extends EventEmitter {
254
254
  return this.sipCall.state === SessionState.Establishing;
255
255
  }
256
256
  isEstablished() {
257
- return States.ESTABLISHED in this.state;
257
+ return typeof this.state === 'object' && States.ESTABLISHED in this.state;
258
258
  }
259
259
  isRinging() {
260
260
  return this.state === States.RINGING;
@@ -461,10 +461,10 @@ class Call extends EventEmitter {
461
461
  return otherCall && this.id && this.id === otherCall.id;
462
462
  }
463
463
  shouldAutoAnswer() {
464
- return !!this.sipCall.request.getHeader('alert-info');
464
+ return !!this.sipCall.request?.getHeader('alert-info');
465
465
  }
466
466
  get id() {
467
- return getSipSessionId(this.sipCall);
467
+ return getSipCallId(this.sipCall);
468
468
  }
469
469
  get state() {
470
470
  return getState(this.callActor);
@@ -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';
@@ -125,7 +126,7 @@ export class Softphone extends EventEmitter {
125
126
  logger.info('softphone - calling when registering, waiting for Softphone to be registered ...');
126
127
  await waitUntilState(this.softphoneActor, States.REGISTERED);
127
128
  }
128
- if (this.state !== States.UNREGISTERED) {
129
+ if (this.state !== States.REGISTERED) {
129
130
  throw new InvalidState(`Invalid state ${States.UNREGISTERED}`, States.UNREGISTERED);
130
131
  }
131
132
  // Hold other calls
@@ -134,6 +135,7 @@ export class Softphone extends EventEmitter {
134
135
  try {
135
136
  sipCall = this.client.call(options.params.To, options.withCamera, options.audioOnly, options.conference, options);
136
137
  const call = new Call(sipCall, this);
138
+ this.calls.push(call);
137
139
  this.emit(EVENT_OUTGOING, call);
138
140
  return call;
139
141
  }
@@ -289,7 +291,7 @@ export class Softphone extends EventEmitter {
289
291
  });
290
292
  this.client.on(this.client.ON_REINVITE, (sipCall, request, updatedCalleeName, updatedNumber, hadRemoteVideo) => {
291
293
  logger.info('softphone - on reinvite', {
292
- callId: sipCall.id,
294
+ callId: getSipCallId(sipCall),
293
295
  inviteId: request.callId,
294
296
  updatedCalleeName,
295
297
  updatedNumber,
@@ -387,13 +389,16 @@ export class Softphone extends EventEmitter {
387
389
  this.softphoneActor.send({ type: action });
388
390
  }
389
391
  _getCall(sipCall) {
390
- return this.calls.find(call => call.id === sipCall.id);
392
+ return this.calls.find(call => call.id === getSipCallId(sipCall));
393
+ }
394
+ _getCallIds() {
395
+ return this.calls.map(call => call.id);
391
396
  }
392
397
  _onCallEvent(sipCall, eventName, ...args) {
393
- logger.warn('softphone - received call event', { eventName, sipId: sipCall.id });
398
+ logger.info('softphone - received call event', { eventName, sipId: getSipCallId(sipCall) });
394
399
  const call = this._getCall(sipCall);
395
400
  if (!call) {
396
- logger.warn('softphone - no call found to send the event', { eventName, sipId: sipCall.id });
401
+ logger.warn('softphone - no call found to send the event', { eventName, sipId: getSipCallId(sipCall), ids: this._getCallIds() });
397
402
  return;
398
403
  }
399
404
  // @ts-ignore
@@ -17,7 +17,7 @@ import Emitter from './utils/Emitter';
17
17
  import ApiClient from './api-client';
18
18
  import IssueReporter from './service/IssueReporter';
19
19
  import Heartbeat from './utils/Heartbeat';
20
- import { getSipSessionId, makeURI, replaceLocalIpModifier, SIP_ID_LENGTH } from './utils/sdp';
20
+ import { getSipCallId, makeURI, replaceLocalIpModifier, SIP_ID_MIN_LENGTH } from './utils/sdp';
21
21
  import { cleanupStream, createUaOptions, fetchNetworkStats, getAudioConstraints, getLocalStream, getLocalTracks, getLocalVideoStream, getMediaConfiguration, getPeerConnection, getRemoteStream, getRemoteTracks, getRemoteVideoStream, getRemoteVideoStreamFromPc, getVideoConstraints, hasALocalVideoTrack, hasARemoteVideoTrack, hasAVideoTrack, hasLocalVideo, hasRemoteVideo, hasVideoTrack, isAudioOnly, isVideoRemotelyHeld, isWeb, sessionWantsToDoVideo, setLocalMediaStream, toggleAudio, toggleVideo, updateRemoteStream } from './utils/webrtc';
22
22
  const SEND_STATS_DELAY = 5000;
23
23
  const states = ['STATUS_NULL', 'STATUS_NEW', 'STATUS_CONNECTING', 'STATUS_CONNECTED', 'STATUS_COMPLETED'];
@@ -103,7 +103,9 @@ export default class WebRTCClient extends Emitter {
103
103
  this.skipRegister = config.skipRegister;
104
104
  this._buildConfig(config, session).then((newConfig) => {
105
105
  this.config = newConfig;
106
- this.userAgent = this.createUserAgent(uaConfigOverrides);
106
+ if (!this.userAgent) {
107
+ this.userAgent = this.createUserAgent(uaConfigOverrides);
108
+ }
107
109
  });
108
110
  this.audioOutputDeviceId = config.audioDeviceOutput;
109
111
  this.audioOutputVolume = config.audioOutputVolume || 1;
@@ -230,7 +232,7 @@ export default class WebRTCClient extends Emitter {
230
232
  // @ts-ignore: private
231
233
  this.registerer.waitingToggle(false);
232
234
  }
233
- this.eventEmitter.emit(UNREGISTERED);
235
+ this.eventEmitter.emit(UNREGISTERED, error);
234
236
  }
235
237
  }
236
238
  async register(tries = 0) {
@@ -435,7 +437,7 @@ export default class WebRTCClient extends Emitter {
435
437
  this._setupSession(session);
436
438
  }
437
439
  if (conference) {
438
- this.conferences[getSipSessionId(session)] = true;
440
+ this.conferences[getSipCallId(session)] = true;
439
441
  }
440
442
  const inviteOptions = {
441
443
  requestDelegate: {
@@ -514,7 +516,7 @@ export default class WebRTCClient extends Emitter {
514
516
  try {
515
517
  this._stopSendingStats(session);
516
518
  this._cleanupMedia(session);
517
- delete this.sipSessions[getSipSessionId(session)];
519
+ delete this.sipSessions[getSipCallId(session)];
518
520
  // Check if Invitation or Inviter (Invitation = incoming call)
519
521
  const isInviter = session instanceof Inviter;
520
522
  // @see github.com/onsip/SIP.js/blob/f11dfd584bc9788ccfc94e03034020672b738975/src/platform/web/simple-user/simple-user.ts#L1004
@@ -536,7 +538,7 @@ export default class WebRTCClient extends Emitter {
536
538
  }
537
539
  // Fetch and emit an event at `interval` with session network stats
538
540
  startNetworkMonitoring(session, interval = 1000) {
539
- const sessionId = getSipSessionId(session);
541
+ const sessionId = getSipCallId(session);
540
542
  logger.info('starting network inspection', {
541
543
  id: sessionId,
542
544
  clientId: this.clientId,
@@ -545,7 +547,7 @@ export default class WebRTCClient extends Emitter {
545
547
  this.networkMonitoringInterval[sessionId] = setInterval(() => this._fetchNetworkStats(sessionId), interval);
546
548
  }
547
549
  stopNetworkMonitoring(session) {
548
- const sessionId = getSipSessionId(session);
550
+ const sessionId = getSipCallId(session);
549
551
  const exists = (sessionId in this.networkMonitoringInterval);
550
552
  logger.info('stopping network inspection', {
551
553
  clientId: this.clientId,
@@ -669,7 +671,7 @@ export default class WebRTCClient extends Emitter {
669
671
  toggleVideo(session, true);
670
672
  }
671
673
  hold(session, isConference = false, hadVideo = false) {
672
- const sessionId = getSipSessionId(session);
674
+ const sessionId = getSipCallId(session);
673
675
  const hasVideo = hadVideo || this.hasLocalVideo(sessionId);
674
676
  logger.info('sdk webrtc hold', {
675
677
  sessionId,
@@ -717,7 +719,7 @@ export default class WebRTCClient extends Emitter {
717
719
  });
718
720
  }
719
721
  unhold(session, isConference = false) {
720
- const sessionId = getSipSessionId(session);
722
+ const sessionId = getSipCallId(session);
721
723
  const hasVideo = sessionId in this.heldSessions && this.heldSessions[sessionId].hasVideo;
722
724
  logger.info('sdk webrtc unhold', {
723
725
  sessionId,
@@ -732,7 +734,7 @@ export default class WebRTCClient extends Emitter {
732
734
  return Promise.resolve();
733
735
  }
734
736
  this.unmute(session);
735
- delete this.heldSessions[getSipSessionId(session)];
737
+ delete this.heldSessions[getSipCallId(session)];
736
738
  session.sessionDescriptionHandlerOptionsReInvite = {
737
739
  hold: false,
738
740
  conference: isConference,
@@ -757,7 +759,7 @@ export default class WebRTCClient extends Emitter {
757
759
  return this.heldSessions[sessionId];
758
760
  }
759
761
  isCallHeld(session) {
760
- return getSipSessionId(session) in this.heldSessions;
762
+ return getSipCallId(session) in this.heldSessions;
761
763
  }
762
764
  isVideoRemotelyHeld(sessionId) {
763
765
  return isVideoRemotelyHeld(this.heldSessions[sessionId]);
@@ -767,7 +769,7 @@ export default class WebRTCClient extends Emitter {
767
769
  return false;
768
770
  }
769
771
  logger.info('Sending DTMF', {
770
- id: getSipSessionId(session),
772
+ id: getSipCallId(session),
771
773
  tone,
772
774
  });
773
775
  return session.sessionDescriptionHandler.sendDtmf(tone);
@@ -784,7 +786,7 @@ export default class WebRTCClient extends Emitter {
784
786
  transfer(session, target) {
785
787
  this.hold(session);
786
788
  logger.info('Transfering a session', {
787
- id: getSipSessionId(session),
789
+ id: getSipCallId(session),
788
790
  target,
789
791
  });
790
792
  const options = {
@@ -807,21 +809,21 @@ export default class WebRTCClient extends Emitter {
807
809
  atxfer(session) {
808
810
  this.hold(session);
809
811
  logger.info('webrtc transfer started', {
810
- id: getSipSessionId(session),
812
+ id: getSipCallId(session),
811
813
  });
812
814
  const result = {
813
815
  newSession: null,
814
816
  init: async (target) => {
815
817
  logger.info('webrtc transfer initialized', {
816
- id: getSipSessionId(session),
818
+ id: getSipCallId(session),
817
819
  target,
818
820
  });
819
821
  result.newSession = await this.call(target);
820
822
  },
821
823
  complete: () => {
822
824
  logger.info('webrtc transfer completed', {
823
- id: getSipSessionId(session),
824
- referId: getSipSessionId(result.newSession),
825
+ id: getSipCallId(session),
826
+ referId: getSipCallId(result.newSession),
825
827
  });
826
828
  session.refer(result.newSession);
827
829
  },
@@ -988,7 +990,7 @@ export default class WebRTCClient extends Emitter {
988
990
  }
989
991
  const sdh = session.sessionDescriptionHandler;
990
992
  const pc = sdh.peerConnection;
991
- const sessionId = getSipSessionId(session);
993
+ const sessionId = getSipCallId(session);
992
994
  const localStream = this.getLocalStream(sessionId);
993
995
  logger.info('changing video input device', {
994
996
  id,
@@ -1049,7 +1051,7 @@ export default class WebRTCClient extends Emitter {
1049
1051
  const desktop = newConstraints && newConstraints.desktop;
1050
1052
  logger.info('Sending reinvite', {
1051
1053
  clientId: this.clientId,
1052
- id: getSipSessionId(sipSession),
1054
+ id: getSipCallId(sipSession),
1053
1055
  newConstraints,
1054
1056
  conference,
1055
1057
  audioOnly,
@@ -1083,7 +1085,7 @@ export default class WebRTCClient extends Emitter {
1083
1085
  sipSession.incomingInviteRequest.message.body = response.message.body;
1084
1086
  }
1085
1087
  logger.info('on re-INVITE accepted', {
1086
- id: getSipSessionId(sipSession),
1088
+ id: getSipCallId(sipSession),
1087
1089
  wasMuted,
1088
1090
  shouldDoScreenSharing,
1089
1091
  });
@@ -1194,7 +1196,7 @@ export default class WebRTCClient extends Emitter {
1194
1196
  }
1195
1197
  onCallEnded(session) {
1196
1198
  this._cleanupMedia(session);
1197
- delete this.sipSessions[getSipSessionId(session)];
1199
+ delete this.sipSessions[getSipCallId(session)];
1198
1200
  this._stopSendingStats(session);
1199
1201
  this.stopNetworkMonitoring(session);
1200
1202
  }
@@ -1207,14 +1209,14 @@ export default class WebRTCClient extends Emitter {
1207
1209
  this.userAgent.attemptReconnection();
1208
1210
  }
1209
1211
  storeSipSession(session) {
1210
- const id = getSipSessionId(session);
1212
+ const id = getSipCallId(session);
1211
1213
  logger.info('storing sip session', { id, clientId: this.clientId });
1212
1214
  this.sipSessions[id] = session;
1213
1215
  }
1214
1216
  getSipSession(id) {
1215
- return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_LENGTH)] : null;
1217
+ return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_MIN_LENGTH)] : null;
1216
1218
  }
1217
- getSipSessionIds() {
1219
+ getSipCallIds() {
1218
1220
  return Object.keys(this.sipSessions);
1219
1221
  }
1220
1222
  async updateLocalStream(sipSessionId, newStream) {
@@ -1369,7 +1371,7 @@ export default class WebRTCClient extends Emitter {
1369
1371
  }
1370
1372
  // Invitation and Inviter extends Session
1371
1373
  _setupSession(session) {
1372
- const sipSessionId = getSipSessionId(session);
1374
+ const sipSessionId = getSipCallId(session);
1373
1375
  // When receiving an Invitation, the delegate is not defined.
1374
1376
  if (!session.delegate) {
1375
1377
  session.delegate = {};
@@ -1432,7 +1434,7 @@ export default class WebRTCClient extends Emitter {
1432
1434
  }
1433
1435
  async _onProgress(session, early = false) {
1434
1436
  await this._setupMedias(session);
1435
- const sessionId = getSipSessionId(session).substr(0, 20);
1437
+ const sessionId = getSipCallId(session).substr(0, 20);
1436
1438
  updateRemoteStream(session);
1437
1439
  logger.info('progress received', {
1438
1440
  sessionId,
@@ -1486,7 +1488,7 @@ export default class WebRTCClient extends Emitter {
1486
1488
  return;
1487
1489
  }
1488
1490
  // Safari hack, because you cannot call .play() from a non user action
1489
- const sessionId = getSipSessionId(session);
1491
+ const sessionId = getSipCallId(session);
1490
1492
  const isConference = this.isConference(sessionId);
1491
1493
  if (sessionId in this.audioElements) {
1492
1494
  logger.info('html element already exists for session', {
@@ -1531,7 +1533,7 @@ export default class WebRTCClient extends Emitter {
1531
1533
  audioElement.play().catch(() => { });
1532
1534
  }
1533
1535
  _cleanupMedia(session) {
1534
- const sessionId = getSipSessionId(session);
1536
+ const sessionId = getSipCallId(session);
1535
1537
  const localStream = this.getLocalStream(sessionId);
1536
1538
  if (localStream) {
1537
1539
  cleanupStream(localStream);
@@ -1550,7 +1552,7 @@ export default class WebRTCClient extends Emitter {
1550
1552
  };
1551
1553
  if (this._hasAudio() && isWeb()) {
1552
1554
  if (session) {
1553
- cleanLocalElement(getSipSessionId(session));
1555
+ cleanLocalElement(getSipCallId(session));
1554
1556
  }
1555
1557
  else {
1556
1558
  Object.keys(this.audioElements).forEach(id => cleanLocalElement(id));
@@ -1570,7 +1572,7 @@ export default class WebRTCClient extends Emitter {
1570
1572
  if (!pc) {
1571
1573
  return;
1572
1574
  }
1573
- const sessionId = getSipSessionId(session);
1575
+ const sessionId = getSipCallId(session);
1574
1576
  getStats(pc, (result) => {
1575
1577
  const { results, internal, nomore, ...stats } = result;
1576
1578
  this.statsIntervals[sessionId] = nomore;
@@ -1581,7 +1583,7 @@ export default class WebRTCClient extends Emitter {
1581
1583
  }, SEND_STATS_DELAY);
1582
1584
  }
1583
1585
  _stopSendingStats(session) {
1584
- const sessionId = getSipSessionId(session);
1586
+ const sessionId = getSipCallId(session);
1585
1587
  logger.trace('Check for stopping stats', {
1586
1588
  sessionId,
1587
1589
  ids: Object.keys(this.statsIntervals),
@@ -126,4 +126,16 @@ describe('Call', () => {
126
126
  expect(softphone_1.default.client.hangup).toHaveBeenCalled();
127
127
  }));
128
128
  });
129
+ describe('state propagation', () => {
130
+ it('Should update the call state in events', (done) => {
131
+ const call = new call_1.default(sipCall, softphone_1.default);
132
+ // @ts-ignore: private method
133
+ call._sendAction(call_state_machine_1.Actions.MAKE_CALL);
134
+ call.on('remotelyAccepted', () => {
135
+ expect(call.state).toStrictEqual({ [call_state_machine_1.States.ESTABLISHED]: call_state_machine_1.EstablishedStates.ONGOING });
136
+ done();
137
+ });
138
+ call.onAccepted();
139
+ });
140
+ });
129
141
  });
@@ -43,7 +43,7 @@ exports.default = {
43
43
  });
44
44
  client.on(client.REGISTERED, () => {
45
45
  const sipSession = client.call('*10');
46
- if (!sipSession || !(0, sdp_1.getSipSessionId)(sipSession)) {
46
+ if (!sipSession || !(0, sdp_1.getSipCallId)(sipSession)) {
47
47
  return handleError('Unable to make call through WebRTC');
48
48
  }
49
49
  setTimeout(() => {
@@ -283,7 +283,7 @@ class WebRTCPhone extends Emitter_1.default {
283
283
  content: {
284
284
  type: exports.ON_MESSAGE_TRACK_UPDATED,
285
285
  update: isUpgrade ? 'upgrade' : 'downgrade',
286
- sipCallId: sipSession && (0, sdp_1.getSipSessionId)(sipSession),
286
+ sipCallId: sipSession && (0, sdp_1.getSipCallId)(sipSession),
287
287
  callId: callSession ? callSession.callId : null,
288
288
  number: callSession ? callSession.number : null,
289
289
  },
@@ -291,7 +291,7 @@ class WebRTCPhone extends Emitter_1.default {
291
291
  }, 2500);
292
292
  }
293
293
  _bindEvents(sipSession) {
294
- const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
294
+ const sipSessionId = (0, sdp_1.getSipCallId)(sipSession);
295
295
  if (sipSession instanceof api_1.Invitation) {
296
296
  // Monkey patch to know when canceled with the CANCEL message
297
297
  const onCancel = sipSession._onCancel.bind(sipSession);
@@ -345,7 +345,7 @@ class WebRTCPhone extends Emitter_1.default {
345
345
  const [stream] = event.streams;
346
346
  const kind = event && event.track && event.track.kind;
347
347
  logger.info('on track stream called on the peer connection', {
348
- callId: (0, sdp_1.getSipSessionId)(sipSession),
348
+ callId: (0, sdp_1.getSipCallId)(sipSession),
349
349
  streamId: stream ? stream.id : null,
350
350
  tracks: stream ? stream.getTracks() : null,
351
351
  kind,
@@ -375,9 +375,9 @@ class WebRTCPhone extends Emitter_1.default {
375
375
  }
376
376
  const screenTrack = screenShareStream.getVideoTracks()[0];
377
377
  const sipSession = this.currentSipSession;
378
- const pc = sipSession && this.client.getPeerConnection((0, sdp_1.getSipSessionId)(sipSession));
378
+ const pc = sipSession && this.client.getPeerConnection((0, sdp_1.getSipCallId)(sipSession));
379
379
  const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
380
- const localStream = sipSession && this.client.getLocalStream((0, sdp_1.getSipSessionId)(sipSession));
380
+ const localStream = sipSession && this.client.getLocalStream((0, sdp_1.getSipCallId)(sipSession));
381
381
  const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
382
382
  const hadVideo = !!videoTrack;
383
383
  // Stop local video tracks
@@ -442,19 +442,19 @@ class WebRTCPhone extends Emitter_1.default {
442
442
  }
443
443
  _onScreenSharing(screenStream, sipSession, callSession, hadVideo, desktop) {
444
444
  const screenTrack = screenStream.getVideoTracks()[0];
445
- const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
445
+ const sipSessionId = (0, sdp_1.getSipCallId)(sipSession);
446
446
  const pc = this.client.getPeerConnection(sipSessionId);
447
447
  const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
448
448
  logger.info('WebRTC phone - on screensharing', {
449
449
  hadVideo,
450
- id: (0, sdp_1.getSipSessionId)(sipSession),
450
+ id: (0, sdp_1.getSipCallId)(sipSession),
451
451
  screenTrack,
452
452
  });
453
453
  if (screenTrack) {
454
454
  screenTrack.onended = () => {
455
455
  logger.info('WebRTC phone - on screenshare ended', {
456
456
  hadVideo,
457
- id: (0, sdp_1.getSipSessionId)(sipSession),
457
+ id: (0, sdp_1.getSipCallId)(sipSession),
458
458
  screenTrack,
459
459
  });
460
460
  this.eventEmitter.emit(exports.ON_SHARE_SCREEN_ENDING, this._createCallSession(sipSession, callSession));
@@ -488,7 +488,7 @@ class WebRTCPhone extends Emitter_1.default {
488
488
  this.currentSipSession = sipSession;
489
489
  this.currentCallSession = callSession;
490
490
  this.eventEmitter.emit(exports.ON_TERMINATE_SOUND, callSession, 'call accepted');
491
- const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
491
+ const sipSessionId = (0, sdp_1.getSipCallId)(sipSession);
492
492
  if (sipSessionId) {
493
493
  this.removeIncomingSessions(sipSessionId);
494
494
  }
@@ -551,7 +551,7 @@ class WebRTCPhone extends Emitter_1.default {
551
551
  return this.currentSipSession && this.client.changeSessionVideoInputDevice(id, this.currentSipSession);
552
552
  }
553
553
  _onCallTerminated(sipSession) {
554
- const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
554
+ const sipSessionId = (0, sdp_1.getSipCallId)(sipSession);
555
555
  logger.info('WebRTC phone - on call terminated', {
556
556
  sipId: sipSession.id,
557
557
  sipSessionId,
@@ -643,7 +643,7 @@ class WebRTCPhone extends Emitter_1.default {
643
643
  if (!this.currentSipSession) {
644
644
  return false;
645
645
  }
646
- return this.currentSipSession && (0, sdp_1.getSipSessionId)(this.currentSipSession) === callSession.getId();
646
+ return this.currentSipSession && (0, sdp_1.getSipCallId)(this.currentSipSession) === callSession.getId();
647
647
  }
648
648
  hasVideo(callSession) {
649
649
  return this.client.hasVideo(callSession.getId());
@@ -677,7 +677,7 @@ class WebRTCPhone extends Emitter_1.default {
677
677
  logger.warn('no CallSession to accept.');
678
678
  return Promise.resolve(null);
679
679
  }
680
- const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
680
+ const sipSessionId = this.getSipCallIdFromCallSession(callSession);
681
681
  if (sipSessionId && !(sipSessionId in this.callSessions)) {
682
682
  logger.warn('Call session already ended or not found, can\'t accept it.', {
683
683
  sipSessionId,
@@ -709,7 +709,7 @@ class WebRTCPhone extends Emitter_1.default {
709
709
  const error = 'No CallSession found to accept.';
710
710
  logger.warn(error, {
711
711
  id: callSession ? callSession.getId() : 'n/a',
712
- ids: this.client.getSipSessionIds(),
712
+ ids: this.client.getSipCallIds(),
713
713
  });
714
714
  if (callSession) {
715
715
  this.eventEmitter.emit(exports.ON_CALL_ERROR, new Error(error), callSession);
@@ -801,7 +801,7 @@ class WebRTCPhone extends Emitter_1.default {
801
801
  if (!sipSession) {
802
802
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
803
803
  }
804
- const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
804
+ const sessionId = (0, sdp_1.getSipCallId)(sipSession);
805
805
  const hasVideo = this.client.hasLocalVideo(sessionId);
806
806
  logger.info('WebRTC hold sip session', {
807
807
  sipId: sipSession.id,
@@ -830,7 +830,7 @@ class WebRTCPhone extends Emitter_1.default {
830
830
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
831
831
  }
832
832
  const isConference = !!callSession && callSession.isConference();
833
- const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
833
+ const sessionId = (0, sdp_1.getSipCallId)(sipSession);
834
834
  logger.info('WebRTC unhold sip session', {
835
835
  sessionId,
836
836
  isConference,
@@ -1059,7 +1059,7 @@ class WebRTCPhone extends Emitter_1.default {
1059
1059
  console.error('Call is unknown to the WebRTC phone', callSession ? callSession.sipCallId : null, callSession ? callSession.callId : null);
1060
1060
  return false;
1061
1061
  }
1062
- const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
1062
+ const sipSessionId = (0, sdp_1.getSipCallId)(sipSession);
1063
1063
  logger.info('WebRTC hangup', {
1064
1064
  sipId: sipSession.id,
1065
1065
  sipSessionId,
@@ -1251,12 +1251,12 @@ class WebRTCPhone extends Emitter_1.default {
1251
1251
  // if `_createCallSession` is called too soon `hasVideo` will return false because the stream doesn't exists yet
1252
1252
  setTimeout(() => {
1253
1253
  // Update callSession
1254
- this._createCallSession(sipSession, this.callSessions[(0, sdp_1.getSipSessionId)(sipSession)]);
1254
+ this._createCallSession(sipSession, this.callSessions[(0, sdp_1.getSipCallId)(sipSession)]);
1255
1255
  this.eventEmitter.emit.apply(this.eventEmitter, [this.client.ON_REINVITE, ...args]);
1256
1256
  }, 2000);
1257
1257
  });
1258
1258
  this.client.on(this.client.ACCEPTED, (sipSession) => __awaiter(this, void 0, void 0, function* () {
1259
- const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
1259
+ const sessionId = (0, sdp_1.getSipCallId)(sipSession);
1260
1260
  const hasSession = (sessionId in this.callSessions);
1261
1261
  logger.info('WebRTC call accepted', {
1262
1262
  sipId: sessionId,
@@ -1283,7 +1283,7 @@ class WebRTCPhone extends Emitter_1.default {
1283
1283
  const callSession = this._createCallSession(session);
1284
1284
  // `_createCallSession` add the CallSession in `this.callSessions`.
1285
1285
  // so we have to remove it or `callCount` will always return 1 even if the call was rejected
1286
- delete this.callSessions[(0, sdp_1.getSipSessionId)(session)];
1286
+ delete this.callSessions[(0, sdp_1.getSipCallId)(session)];
1287
1287
  callSession.endTime = new Date();
1288
1288
  this.eventEmitter.emit(exports.ON_CALL_REJECTED, callSession);
1289
1289
  });
@@ -1300,7 +1300,7 @@ class WebRTCPhone extends Emitter_1.default {
1300
1300
  const callSession = this._createCallSession(session, null, {
1301
1301
  incoming: false,
1302
1302
  ringing: true,
1303
- callId: (0, sdp_1.getSipSessionId)(session),
1303
+ callId: (0, sdp_1.getSipCallId)(session),
1304
1304
  });
1305
1305
  this.eventEmitter.emit(exports.ON_PROGRESS, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
1306
1306
  });
@@ -1309,7 +1309,7 @@ class WebRTCPhone extends Emitter_1.default {
1309
1309
  const callSession = this._createCallSession(session, null, {
1310
1310
  incoming: false,
1311
1311
  ringing: true,
1312
- callId: (0, sdp_1.getSipSessionId)(session),
1312
+ callId: (0, sdp_1.getSipCallId)(session),
1313
1313
  });
1314
1314
  this.eventEmitter.emit(exports.ON_EARLY_MEDIA, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
1315
1315
  });
@@ -1366,12 +1366,12 @@ class WebRTCPhone extends Emitter_1.default {
1366
1366
  this.eventEmitter.emit(exports.ON_MESSAGE, message);
1367
1367
  });
1368
1368
  this.client.on(this.client.ON_NETWORK_STATS, (session, stats, previousStats) => {
1369
- const callSession = this.getCallSession((0, sdp_1.getSipSessionId)(session));
1369
+ const callSession = this.getCallSession((0, sdp_1.getSipCallId)(session));
1370
1370
  this.eventEmitter.emit(exports.ON_NETWORK_STATS, callSession, stats, previousStats);
1371
1371
  });
1372
1372
  // Used when upgrading directly in screenshare mode
1373
1373
  this.client.on(this.client.ON_SCREEN_SHARING_REINVITE, (sipSession, response, desktop) => {
1374
- const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
1374
+ const sipSessionId = (0, sdp_1.getSipCallId)(sipSession);
1375
1375
  const localStream = this.client.getLocalStream(sipSessionId);
1376
1376
  const callSession = this.callSessions[sipSessionId];
1377
1377
  logger.info('Updrading directly in screensharing mode', {
@@ -1383,10 +1383,10 @@ class WebRTCPhone extends Emitter_1.default {
1383
1383
  }
1384
1384
  // Find a corresponding sipSession from a CallSession
1385
1385
  findSipSession(callSession) {
1386
- const keys = this.client.getSipSessionIds();
1386
+ const keys = this.client.getSipCallIds();
1387
1387
  const keyIndex = keys.findIndex(sessionId => callSession && callSession.isId(sessionId));
1388
1388
  if (keyIndex === -1) {
1389
- const currentSipSessionId = this.currentSipSession ? (0, sdp_1.getSipSessionId)(this.currentSipSession) : this.client.getSipSessionIds()[0];
1389
+ const currentSipSessionId = this.currentSipSession ? (0, sdp_1.getSipCallId)(this.currentSipSession) : this.client.getSipCallIds()[0];
1390
1390
  return currentSipSessionId ? this.client.getSipSession(currentSipSessionId) : null;
1391
1391
  }
1392
1392
  return this.client.getSipSession(keys[keyIndex]);
@@ -1394,12 +1394,12 @@ class WebRTCPhone extends Emitter_1.default {
1394
1394
  getCallSession(sipSessionId) {
1395
1395
  return this.callSessions[sipSessionId];
1396
1396
  }
1397
- getSipSessionIdFromCallSession(callSession) {
1397
+ getSipCallIdFromCallSession(callSession) {
1398
1398
  const sipSession = this.findSipSession(callSession);
1399
- return sipSession ? (0, sdp_1.getSipSessionId)(sipSession) : null;
1399
+ return sipSession ? (0, sdp_1.getSipCallId)(sipSession) : null;
1400
1400
  }
1401
1401
  _updateCallSession(callSession) {
1402
- const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
1402
+ const sipSessionId = this.getSipCallIdFromCallSession(callSession);
1403
1403
  if (sipSessionId) {
1404
1404
  this.callSessions[sipSessionId] = callSession;
1405
1405
  }
@@ -1472,7 +1472,7 @@ class WebRTCPhone extends Emitter_1.default {
1472
1472
  const number = (0, sdp_1.getCallNumber)(sipSession);
1473
1473
  const displayName = (0, sdp_1.getCallDisplayName)(sipSession);
1474
1474
  const { state } = sipSession || {};
1475
- const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
1475
+ const sessionId = (0, sdp_1.getSipCallId)(sipSession);
1476
1476
  fromSession = fromSession || this.callSessions[sessionId];
1477
1477
  const callSession = new CallSession_1.default(Object.assign({ callId: fromSession && fromSession.callId, sipCallId: sessionId, sipStatus: state, displayName,
1478
1478
  // @ts-ignore: date / number
@@ -237,11 +237,11 @@ class Phone extends Emitter_1.default {
237
237
  stopNetworkMonitoring(callSession) {
238
238
  return this.phone ? this.phone.stopNetworkMonitoring(callSession) : null;
239
239
  }
240
- getSipSessionId(sipSession) {
240
+ getSipCallId(sipSession) {
241
241
  if (!sipSession || !this.phone) {
242
242
  return null;
243
243
  }
244
- return (0, sdp_1.getSipSessionId)(sipSession);
244
+ return (0, sdp_1.getSipCallId)(sipSession);
245
245
  }
246
246
  sendMessage(body, sipSession, contentType = 'text/plain') {
247
247
  const toSipSession = sipSession || this.getCurrentSipSession();
@@ -372,7 +372,7 @@ class Room extends Emitter_1.default {
372
372
  logger.info('on room audio stream');
373
373
  this.audioStream = stream;
374
374
  if (!this.roomAudioElement) {
375
- const sessionId = (0, sdp_1.getSipSessionId)((_b = index_1.default.Phone.phone) === null || _b === void 0 ? void 0 : _b.currentSipSession);
375
+ const sessionId = (0, sdp_1.getSipCallId)((_b = index_1.default.Phone.phone) === null || _b === void 0 ? void 0 : _b.currentSipSession);
376
376
  this.roomAudioElement = (yield ((_c = index_1.default.Phone.phone) === null || _c === void 0 ? void 0 : _c.createAudioElementFor(sessionId)));
377
377
  this.roomAudioElement.srcObject = stream;
378
378
  }
@@ -136,7 +136,7 @@ class SipRoom extends Room_1.default {
136
136
  }
137
137
  _getCurrentSipCallIs() {
138
138
  var _a;
139
- return (0, sdp_1.getSipSessionId)((_a = index_1.default.Phone.phone) === null || _a === void 0 ? void 0 : _a.currentSipSession);
139
+ return (0, sdp_1.getSipCallId)((_a = index_1.default.Phone.phone) === null || _a === void 0 ? void 0 : _a.currentSipSession);
140
140
  }
141
141
  }
142
142
  exports.default = SipRoom;
@@ -44,7 +44,7 @@ const assertCan = (actor, action) => {
44
44
  exports.assertCan = assertCan;
45
45
  const assertState = (actor, state) => {
46
46
  if (!(0, exports.hasState)(actor, state)) {
47
- const message = `Invalid state ${state}`;
47
+ const message = `Invalid state ${state}, has state ${(0, exports.getState)(actor)}`;
48
48
  logger.warn(message);
49
49
  throw new InvalidState_1.default(message, state);
50
50
  }
@@ -164,7 +164,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
164
164
  bindClientEvents(): void;
165
165
  findSipSession(callSession?: CallSession): WazoSession | null | undefined;
166
166
  getCallSession(sipSessionId: string): CallSession | null | undefined;
167
- getSipSessionIdFromCallSession(callSession: CallSession): string | null;
167
+ getSipCallIdFromCallSession(callSession: CallSession): string | null;
168
168
  _updateCallSession(callSession: CallSession): void;
169
169
  _onMessage(message: Message & {
170
170
  method?: string;