@wazo/sdk 1.0.0-alpha.5 → 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 +3 -3
  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 +2 -2
  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 +3 -3
  57. package/src/voice/softphone.ts +11 -5
  58. package/src/web-rtc-client.ts +33 -31
@@ -12,7 +12,7 @@ import WazoWebRTCClient from '../../web-rtc-client';
12
12
  import Emitter from '../../utils/Emitter';
13
13
  import IssueReporter from '../../service/IssueReporter';
14
14
  import { PeerConnection, WazoSession } from '../types';
15
- import { getCallDisplayName, getCallNumber, getSipSessionId } from '../../utils/sdp';
15
+ import { getCallDisplayName, getCallNumber, getSipCallId } from '../../utils/sdp';
16
16
  import { downgradeToAudio, getStreamFromConstraints, getWebRtcStats, setLocalMediaStream, upgradeToVideo } from '../../utils/webrtc';
17
17
 
18
18
  export const ON_USER_AGENT = 'onUserAgent';
@@ -360,7 +360,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
360
360
  content: {
361
361
  type: ON_MESSAGE_TRACK_UPDATED,
362
362
  update: isUpgrade ? 'upgrade' : 'downgrade',
363
- sipCallId: sipSession && getSipSessionId(sipSession),
363
+ sipCallId: sipSession && getSipCallId(sipSession),
364
364
  callId: callSession ? callSession.callId : null,
365
365
  number: callSession ? callSession.number : null,
366
366
  },
@@ -369,7 +369,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
369
369
  }
370
370
 
371
371
  _bindEvents(sipSession: WazoSession) {
372
- const sipSessionId = getSipSessionId(sipSession);
372
+ const sipSessionId = getSipCallId(sipSession);
373
373
 
374
374
  if (sipSession instanceof Invitation) {
375
375
  // Monkey patch to know when canceled with the CANCEL message
@@ -437,7 +437,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
437
437
  const [stream] = event.streams;
438
438
  const kind = event && event.track && event.track.kind;
439
439
  logger.info('on track stream called on the peer connection', {
440
- callId: getSipSessionId(sipSession),
440
+ callId: getSipCallId(sipSession),
441
441
  streamId: stream ? stream.id : null,
442
442
  tracks: stream ? stream.getTracks() : null,
443
443
  kind,
@@ -472,9 +472,9 @@ export default class WebRTCPhone extends Emitter implements Phone {
472
472
 
473
473
  const screenTrack = screenShareStream.getVideoTracks()[0];
474
474
  const sipSession = this.currentSipSession;
475
- const pc = sipSession && this.client.getPeerConnection(getSipSessionId(sipSession));
475
+ const pc = sipSession && this.client.getPeerConnection(getSipCallId(sipSession));
476
476
  const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
477
- const localStream = sipSession && this.client.getLocalStream(getSipSessionId(sipSession));
477
+ const localStream = sipSession && this.client.getLocalStream(getSipCallId(sipSession));
478
478
  const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
479
479
  const hadVideo = !!videoTrack;
480
480
 
@@ -549,12 +549,12 @@ export default class WebRTCPhone extends Emitter implements Phone {
549
549
 
550
550
  _onScreenSharing(screenStream: MediaStream, sipSession: WazoSession, callSession: CallSession | null | undefined, hadVideo: boolean, desktop?: boolean | null | undefined) {
551
551
  const screenTrack = screenStream.getVideoTracks()[0];
552
- const sipSessionId = getSipSessionId(sipSession);
552
+ const sipSessionId = getSipCallId(sipSession);
553
553
  const pc = this.client.getPeerConnection(sipSessionId);
554
554
  const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
555
555
  logger.info('WebRTC phone - on screensharing', {
556
556
  hadVideo,
557
- id: getSipSessionId(sipSession),
557
+ id: getSipCallId(sipSession),
558
558
  screenTrack,
559
559
  });
560
560
 
@@ -562,7 +562,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
562
562
  screenTrack.onended = () => {
563
563
  logger.info('WebRTC phone - on screenshare ended', {
564
564
  hadVideo,
565
- id: getSipSessionId(sipSession),
565
+ id: getSipCallId(sipSession),
566
566
  screenTrack,
567
567
  });
568
568
  this.eventEmitter.emit(ON_SHARE_SCREEN_ENDING, this._createCallSession(sipSession, callSession));
@@ -602,7 +602,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
602
602
  this.currentSipSession = sipSession;
603
603
  this.currentCallSession = callSession;
604
604
  this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call accepted');
605
- const sipSessionId = getSipSessionId(sipSession);
605
+ const sipSessionId = getSipCallId(sipSession);
606
606
 
607
607
  if (sipSessionId) {
608
608
  this.removeIncomingSessions(sipSessionId);
@@ -674,7 +674,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
674
674
  }
675
675
 
676
676
  _onCallTerminated(sipSession: WazoSession): boolean {
677
- const sipSessionId = getSipSessionId(sipSession);
677
+ const sipSessionId = getSipCallId(sipSession);
678
678
 
679
679
  logger.info('WebRTC phone - on call terminated', {
680
680
  sipId: sipSession.id,
@@ -788,7 +788,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
788
788
  return false;
789
789
  }
790
790
 
791
- return this.currentSipSession && getSipSessionId(this.currentSipSession) === callSession.getId();
791
+ return this.currentSipSession && getSipCallId(this.currentSipSession) === callSession.getId();
792
792
  }
793
793
 
794
794
  hasVideo(callSession: CallSession): boolean {
@@ -831,7 +831,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
831
831
  return Promise.resolve(null);
832
832
  }
833
833
 
834
- const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
834
+ const sipSessionId = this.getSipCallIdFromCallSession(callSession);
835
835
 
836
836
  if (sipSessionId && !(sipSessionId in this.callSessions)) {
837
837
  logger.warn('Call session already ended or not found, can\'t accept it.', {
@@ -872,7 +872,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
872
872
 
873
873
  logger.warn(error, {
874
874
  id: callSession ? callSession.getId() : 'n/a',
875
- ids: this.client.getSipSessionIds(),
875
+ ids: this.client.getSipCallIds(),
876
876
  });
877
877
 
878
878
  if (callSession) {
@@ -980,7 +980,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
980
980
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
981
981
  }
982
982
 
983
- const sessionId = getSipSessionId(sipSession);
983
+ const sessionId = getSipCallId(sipSession);
984
984
  const hasVideo = this.client.hasLocalVideo(sessionId);
985
985
  logger.info('WebRTC hold sip session', {
986
986
  sipId: sipSession.id,
@@ -1014,7 +1014,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1014
1014
  }
1015
1015
 
1016
1016
  const isConference = !!callSession && callSession.isConference();
1017
- const sessionId = getSipSessionId(sipSession);
1017
+ const sessionId = getSipCallId(sipSession);
1018
1018
  logger.info('WebRTC unhold sip session', {
1019
1019
  sessionId,
1020
1020
  isConference,
@@ -1296,7 +1296,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1296
1296
  console.error('Call is unknown to the WebRTC phone', callSession ? callSession.sipCallId : null, callSession ? callSession.callId : null);
1297
1297
  return false;
1298
1298
  }
1299
- const sipSessionId = getSipSessionId(sipSession);
1299
+ const sipSessionId = getSipCallId(sipSession);
1300
1300
 
1301
1301
  logger.info('WebRTC hangup', {
1302
1302
  sipId: sipSession.id,
@@ -1527,13 +1527,13 @@ export default class WebRTCPhone extends Emitter implements Phone {
1527
1527
  // if `_createCallSession` is called too soon `hasVideo` will return false because the stream doesn't exists yet
1528
1528
  setTimeout(() => {
1529
1529
  // Update callSession
1530
- this._createCallSession(sipSession, this.callSessions[getSipSessionId(sipSession)]);
1530
+ this._createCallSession(sipSession, this.callSessions[getSipCallId(sipSession)]);
1531
1531
 
1532
1532
  this.eventEmitter.emit.apply(this.eventEmitter, [this.client.ON_REINVITE, ...args]);
1533
1533
  }, 2000);
1534
1534
  });
1535
1535
  this.client.on(this.client.ACCEPTED, async (sipSession: WazoSession) => {
1536
- const sessionId = getSipSessionId(sipSession);
1536
+ const sessionId = getSipCallId(sipSession);
1537
1537
  const hasSession = (sessionId in this.callSessions);
1538
1538
  logger.info('WebRTC call accepted', {
1539
1539
  sipId: sessionId,
@@ -1565,7 +1565,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1565
1565
 
1566
1566
  // `_createCallSession` add the CallSession in `this.callSessions`.
1567
1567
  // so we have to remove it or `callCount` will always return 1 even if the call was rejected
1568
- delete this.callSessions[getSipSessionId(session)];
1568
+ delete this.callSessions[getSipCallId(session)];
1569
1569
 
1570
1570
  callSession.endTime = new Date();
1571
1571
 
@@ -1585,7 +1585,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1585
1585
  const callSession = this._createCallSession(session, null, {
1586
1586
  incoming: false,
1587
1587
  ringing: true,
1588
- callId: getSipSessionId(session),
1588
+ callId: getSipCallId(session),
1589
1589
  });
1590
1590
 
1591
1591
  this.eventEmitter.emit(ON_PROGRESS, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
@@ -1596,7 +1596,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1596
1596
  const callSession = this._createCallSession(session, null, {
1597
1597
  incoming: false,
1598
1598
  ringing: true,
1599
- callId: getSipSessionId(session),
1599
+ callId: getSipCallId(session),
1600
1600
  });
1601
1601
 
1602
1602
  this.eventEmitter.emit(ON_EARLY_MEDIA, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
@@ -1657,12 +1657,12 @@ export default class WebRTCPhone extends Emitter implements Phone {
1657
1657
  this.eventEmitter.emit(ON_MESSAGE, message);
1658
1658
  });
1659
1659
  this.client.on(this.client.ON_NETWORK_STATS, (session, stats, previousStats) => {
1660
- const callSession = this.getCallSession(getSipSessionId(session));
1660
+ const callSession = this.getCallSession(getSipCallId(session));
1661
1661
  this.eventEmitter.emit(ON_NETWORK_STATS, callSession, stats, previousStats);
1662
1662
  });
1663
1663
  // Used when upgrading directly in screenshare mode
1664
1664
  this.client.on(this.client.ON_SCREEN_SHARING_REINVITE, (sipSession: WazoSession, response: any, desktop: boolean) => {
1665
- const sipSessionId = getSipSessionId(sipSession);
1665
+ const sipSessionId = getSipCallId(sipSession);
1666
1666
  const localStream = this.client.getLocalStream(sipSessionId);
1667
1667
  const callSession = this.callSessions[sipSessionId];
1668
1668
  logger.info('Updrading directly in screensharing mode', {
@@ -1676,11 +1676,11 @@ export default class WebRTCPhone extends Emitter implements Phone {
1676
1676
 
1677
1677
  // Find a corresponding sipSession from a CallSession
1678
1678
  findSipSession(callSession?: CallSession): WazoSession | null | undefined {
1679
- const keys = this.client.getSipSessionIds();
1679
+ const keys = this.client.getSipCallIds();
1680
1680
  const keyIndex = keys.findIndex(sessionId => callSession && callSession.isId(sessionId));
1681
1681
 
1682
1682
  if (keyIndex === -1) {
1683
- const currentSipSessionId = this.currentSipSession ? getSipSessionId(this.currentSipSession) : this.client.getSipSessionIds()[0];
1683
+ const currentSipSessionId = this.currentSipSession ? getSipCallId(this.currentSipSession) : this.client.getSipCallIds()[0];
1684
1684
  return currentSipSessionId ? this.client.getSipSession(currentSipSessionId) : null;
1685
1685
  }
1686
1686
 
@@ -1691,13 +1691,13 @@ export default class WebRTCPhone extends Emitter implements Phone {
1691
1691
  return this.callSessions[sipSessionId];
1692
1692
  }
1693
1693
 
1694
- getSipSessionIdFromCallSession(callSession: CallSession): string | null {
1694
+ getSipCallIdFromCallSession(callSession: CallSession): string | null {
1695
1695
  const sipSession = this.findSipSession(callSession);
1696
- return sipSession ? getSipSessionId(sipSession) : null;
1696
+ return sipSession ? getSipCallId(sipSession) : null;
1697
1697
  }
1698
1698
 
1699
1699
  _updateCallSession(callSession: CallSession): void {
1700
- const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
1700
+ const sipSessionId = this.getSipCallIdFromCallSession(callSession);
1701
1701
 
1702
1702
  if (sipSessionId) {
1703
1703
  this.callSessions[sipSessionId] = callSession;
@@ -1788,7 +1788,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1788
1788
  const number = getCallNumber(sipSession);
1789
1789
  const displayName = getCallDisplayName(sipSession);
1790
1790
  const { state } = sipSession || {};
1791
- const sessionId = getSipSessionId(sipSession);
1791
+ const sessionId = getSipCallId(sipSession);
1792
1792
 
1793
1793
  fromSession = fromSession || this.callSessions[sessionId];
1794
1794
  const callSession = new CallSession({
@@ -12,7 +12,7 @@ import Emitter from '../utils/Emitter';
12
12
  import Wazo from './index';
13
13
  import SFUNotAvailableError from '../domain/SFUNotAvailableError';
14
14
  import { WazoSession, WebRtcConfig } from '../domain/types';
15
- import { getSipSessionId } from '../utils/sdp';
15
+ import { getSipCallId } from '../utils/sdp';
16
16
 
17
17
  const logger = IssueReporter.loggerFor('simple-phone');
18
18
  const sipLogger = IssueReporter.loggerFor('sip.js');
@@ -330,11 +330,11 @@ export class Phone extends Emitter {
330
330
  return this.phone ? this.phone.stopNetworkMonitoring(callSession) : null;
331
331
  }
332
332
 
333
- getSipSessionId(sipSession: WazoSession): string | null | undefined {
333
+ getSipCallId(sipSession: WazoSession): string | null | undefined {
334
334
  if (!sipSession || !this.phone) {
335
335
  return null;
336
336
  }
337
- return getSipSessionId(sipSession);
337
+ return getSipCallId(sipSession);
338
338
  }
339
339
 
340
340
  sendMessage(body: string, sipSession?: WazoSession, contentType = 'text/plain'): void {
@@ -10,7 +10,7 @@ import RemoteParticipant from './RemoteParticipant';
10
10
  import IssueReporter from '../../service/IssueReporter';
11
11
  import LocalParticipant from './LocalParticipant';
12
12
  import { PeerConnection, WazoSession } from '../../domain/types';
13
- import { getSipSessionId } from '../../utils/sdp';
13
+ import { getSipCallId } from '../../utils/sdp';
14
14
 
15
15
  export const SIGNAL_TYPE_PARTICIPANT_UPDATE = 'signal/PARTICIPANT_UPDATE';
16
16
  export const SIGNAL_TYPE_PARTICIPANT_REQUEST = 'signal/PARTICIPANT_REQUEST';
@@ -498,7 +498,7 @@ class Room extends Emitter {
498
498
  this.audioStream = stream;
499
499
 
500
500
  if (!this.roomAudioElement) {
501
- const sessionId = getSipSessionId(Wazo.Phone.phone?.currentSipSession as WazoSession);
501
+ const sessionId = getSipCallId(Wazo.Phone.phone?.currentSipSession as WazoSession);
502
502
  this.roomAudioElement = await Wazo.Phone.phone?.createAudioElementFor(sessionId as string) as HTMLAudioElement;
503
503
  this.roomAudioElement.srcObject = stream;
504
504
  } else {
@@ -4,7 +4,7 @@ import IssueReporter from '../../service/IssueReporter';
4
4
  import Wazo from '../index';
5
5
  import Room from './Room';
6
6
  import { WazoSession } from '../../domain/types';
7
- import { getSipSessionId } from '../../utils/sdp';
7
+ import { getSipCallId } from '../../utils/sdp';
8
8
 
9
9
  const logger = IssueReporter.loggerFor('sdk-sip-room');
10
10
 
@@ -157,7 +157,7 @@ class SipRoom extends Room {
157
157
  }
158
158
 
159
159
  _getCurrentSipCallIs() {
160
- return getSipSessionId(Wazo.Phone.phone?.currentSipSession as WazoSession);
160
+ return getSipCallId(Wazo.Phone.phone?.currentSipSession as WazoSession);
161
161
  }
162
162
 
163
163
  }
@@ -45,7 +45,7 @@ export const assertCan = (actor: SoftphoneActorRef | CallActorRef, action: Softp
45
45
 
46
46
  export const assertState = (actor: SoftphoneActorRef | CallActorRef, state: SoftphoneStates | CallStates): void => {
47
47
  if (!hasState(actor, state)) {
48
- const message = `Invalid state ${state}`;
48
+ const message = `Invalid state ${state}, has state ${getState(actor)}`;
49
49
  logger.warn(message);
50
50
 
51
51
  throw new InvalidState(message, state);
package/src/utils/sdp.ts CHANGED
@@ -6,7 +6,7 @@ import { URI } from 'sip.js/lib/grammar/uri';
6
6
 
7
7
  import type { SipCall } from '../domain/types';
8
8
 
9
- export const SIP_ID_LENGTH = 36;
9
+ export const SIP_ID_MIN_LENGTH = 20;
10
10
 
11
11
  export type Candidate = {
12
12
  foundation: string;
@@ -147,25 +147,25 @@ export const addIcesInAllBundles = (sdp: string) => {
147
147
  return sdpParser.write(parsedSdp);
148
148
  };
149
149
 
150
- export const getSipSessionId = (sipSession: SipCall | null | undefined): string => {
150
+ export const getSipCallId = (sipSession: SipCall | null | undefined): string => {
151
151
  if (!sipSession) {
152
152
  return '';
153
153
  }
154
154
 
155
155
  const message = sipSession.message as Partial<{ callId?: string }>;
156
156
  if (message?.callId) {
157
- return message.callId.substring(0, SIP_ID_LENGTH);
157
+ return message.callId.substring(0, SIP_ID_MIN_LENGTH);
158
158
  }
159
159
 
160
160
  // For Inviter
161
161
  // @ts-ignore: private
162
162
  if (sipSession instanceof Inviter && sipSession.outgoingRequestMessage) {
163
163
  // @ts-ignore: private
164
- return sipSession.outgoingRequestMessage.callId.substring(0, SIP_ID_LENGTH);
164
+ return sipSession.outgoingRequestMessage.callId.substring(0, SIP_ID_MIN_LENGTH);
165
165
  }
166
166
 
167
167
  // For Invitation
168
- return (sipSession.id || '').substring(0, SIP_ID_LENGTH);
168
+ return (sipSession.id || '').substring(0, SIP_ID_MIN_LENGTH);
169
169
  };
170
170
 
171
171
  // We need to replace 0.0.0.0 to 127.0.0.1 in the sdp to avoid MOH during a createOffer.
@@ -7,7 +7,7 @@ import { stripVideo } from 'sip.js/lib/platform/web';
7
7
 
8
8
  import WazoSessionDescriptionHandler, { wazoMediaStreamFactory } from '../lib/WazoSessionDescriptionHandler';
9
9
  import { SipCall, PeerConnection, UserAgentOptions, WebRtcConfig, UserAgentConfigOverrides } from '../domain/types';
10
- import { getVideoDirection, hasAnActiveVideo, makeURI, replaceLocalIpModifier } from './sdp';
10
+ import { getSipCallId, getVideoDirection, hasAnActiveVideo, makeURI, replaceLocalIpModifier } from './sdp';
11
11
  import IssueReporter from '../service/IssueReporter';
12
12
  import { lastIndexOf } from './array';
13
13
 
@@ -274,7 +274,7 @@ export const cleanupStream = (stream: MediaStream): void => {
274
274
 
275
275
  export const setLocalMediaStream = (sipCall: SipCall, newStream: MediaStream): void => {
276
276
  logger.info('setting local media stream', {
277
- id: sipCall.id,
277
+ id: getSipCallId(sipCall),
278
278
  tracks: newStream ? newStream.getTracks() : null,
279
279
  });
280
280
 
@@ -290,7 +290,7 @@ export const updateRemoteStream = (sipCall: SipCall, allTracks = true): void =>
290
290
  const pc = getPeerConnection(sipCall);
291
291
 
292
292
  logger.info('Updating remote stream', {
293
- id: sipCall.id,
293
+ id: getSipCallId(sipCall),
294
294
  tracks: remoteStream ? remoteStream.getTracks() : null,
295
295
  receiverTracks: pc && pc.getReceivers ? pc.getReceivers().map((receiver) => receiver.track) : null,
296
296
  });
package/src/voice/call.ts CHANGED
@@ -15,7 +15,7 @@ import newFrom from '../utils/new-from';
15
15
  import updateFrom from '../utils/update-from';
16
16
  import IssueReporter from '../service/IssueReporter';
17
17
  import softphone, { EVENT_TERMINATE_SOUND, Softphone } from './softphone';
18
- import { getCallDisplayName, getCallNumber, getSipSessionId } from '../utils/sdp';
18
+ import { getCallDisplayName, getCallNumber, getSipCallId } from '../utils/sdp';
19
19
  import { assertCan, assertState, getState } from '../state-machine/utils';
20
20
  import { downgradeToAudio, getLocalStream, getLocalVideoStream, getPeerConnection, getRemoteStream, getRemoteVideoStream, getStreamFromConstraints, getWebRtcStats, hasALocalVideoTrack, hasLocalVideo, hasRemoteVideo, isVideoMuted, isVideoRemotelyHeld, setLocalMediaStream, toggleVideo, upgradeToVideo } from '../utils/webrtc';
21
21
 
@@ -356,7 +356,7 @@ class Call extends EventEmitter {
356
356
  }
357
357
 
358
358
  isEstablished() {
359
- return States.ESTABLISHED in (this.state as Record<StateTypes, EstablishedStateTypes>);
359
+ return typeof this.state === 'object' && States.ESTABLISHED in (this.state as Record<StateTypes, EstablishedStateTypes>);
360
360
  }
361
361
 
362
362
  isRinging() {
@@ -636,7 +636,7 @@ class Call extends EventEmitter {
636
636
  }
637
637
 
638
638
  get id() {
639
- return getSipSessionId(this.sipCall);
639
+ return getSipCallId(this.sipCall);
640
640
  }
641
641
 
642
642
  get state(): StateTypes | Record<StateTypes, EstablishedStateTypes> {
@@ -16,6 +16,7 @@ import IssueReporter from '../service/IssueReporter';
16
16
  import configureLogger from '../utils/sip-logger';
17
17
  import Call from './call';
18
18
  import { assertCan, can, getState, waitUntilState } from '../state-machine/utils';
19
+ import { getSipCallId } from '../utils/sdp';
19
20
 
20
21
  export const EVENT_INCOMING = 'incoming';
21
22
  export const EVENT_OUTGOING = 'outgoing';
@@ -194,7 +195,7 @@ export class Softphone extends EventEmitter {
194
195
  await waitUntilState(this.softphoneActor, States.REGISTERED);
195
196
  }
196
197
 
197
- if (this.state !== States.UNREGISTERED) {
198
+ if (this.state !== States.REGISTERED) {
198
199
  throw new InvalidState(`Invalid state ${States.UNREGISTERED}`, States.UNREGISTERED);
199
200
  }
200
201
 
@@ -207,6 +208,7 @@ export class Softphone extends EventEmitter {
207
208
  sipCall = this.client.call(options.params.To, options.withCamera, options.audioOnly, options.conference, options) as SipCall;
208
209
  const call = new Call(sipCall, this);
209
210
 
211
+ this.calls.push(call);
210
212
  this.emit(EVENT_OUTGOING, call);
211
213
 
212
214
  return call;
@@ -401,7 +403,7 @@ export class Softphone extends EventEmitter {
401
403
 
402
404
  this.client.on(this.client.ON_REINVITE, (sipCall: SipCall, request: IncomingRequestMessage, updatedCalleeName: string, updatedNumber: string, hadRemoteVideo: boolean) => {
403
405
  logger.info('softphone - on reinvite', {
404
- callId: sipCall.id,
406
+ callId: getSipCallId(sipCall),
405
407
  inviteId: request.callId,
406
408
  updatedCalleeName,
407
409
  updatedNumber,
@@ -530,15 +532,19 @@ export class Softphone extends EventEmitter {
530
532
  }
531
533
 
532
534
  private _getCall(sipCall: SipCall): Call | undefined {
533
- return this.calls.find(call => call.id === sipCall.id);
535
+ return this.calls.find(call => call.id === getSipCallId(sipCall));
536
+ }
537
+
538
+ private _getCallIds(): string[] {
539
+ return this.calls.map(call => call.id);
534
540
  }
535
541
 
536
542
  private _onCallEvent(sipCall: SipCall, eventName: string, ...args: any[]) {
537
- logger.warn('softphone - received call event', { eventName, sipId: sipCall.id });
543
+ logger.info('softphone - received call event', { eventName, sipId: getSipCallId(sipCall) });
538
544
 
539
545
  const call = this._getCall(sipCall);
540
546
  if (!call) {
541
- logger.warn('softphone - no call found to send the event', { eventName, sipId: sipCall.id });
547
+ logger.warn('softphone - no call found to send the event', { eventName, sipId: getSipCallId(sipCall), ids: this._getCallIds() });
542
548
  return;
543
549
  }
544
550