@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
@@ -29,7 +29,7 @@ import Emitter from './utils/Emitter';
29
29
  import ApiClient from './api-client';
30
30
  import IssueReporter from './service/IssueReporter';
31
31
  import Heartbeat from './utils/Heartbeat';
32
- import { getSipSessionId, makeURI, replaceLocalIpModifier, SIP_ID_LENGTH } from './utils/sdp';
32
+ import { getSipCallId, makeURI, replaceLocalIpModifier, SIP_ID_MIN_LENGTH } from './utils/sdp';
33
33
  import type { MediaConfig, UserAgentConfigOverrides, WebRtcConfig, IncomingResponse, PeerConnection, WazoSession, WazoTransport } from './domain/types';
34
34
  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';
35
35
 
@@ -166,7 +166,9 @@ export default class WebRTCClient extends Emitter {
166
166
 
167
167
  this._buildConfig(config, session).then((newConfig: WebRtcConfig) => {
168
168
  this.config = newConfig;
169
- this.userAgent = this.createUserAgent(uaConfigOverrides);
169
+ if (!this.userAgent) {
170
+ this.userAgent = this.createUserAgent(uaConfigOverrides);
171
+ }
170
172
  });
171
173
 
172
174
  this.audioOutputDeviceId = config.audioDeviceOutput;
@@ -316,7 +318,7 @@ export default class WebRTCClient extends Emitter {
316
318
  this.registerer.waitingToggle(false);
317
319
  }
318
320
 
319
- this.eventEmitter.emit(UNREGISTERED);
321
+ this.eventEmitter.emit(UNREGISTERED, error);
320
322
  }
321
323
  }
322
324
 
@@ -559,7 +561,7 @@ export default class WebRTCClient extends Emitter {
559
561
  }
560
562
 
561
563
  if (conference) {
562
- this.conferences[getSipSessionId(session)] = true;
564
+ this.conferences[getSipCallId(session)] = true;
563
565
  }
564
566
 
565
567
  const inviteOptions: InviterInviteOptions = {
@@ -654,7 +656,7 @@ export default class WebRTCClient extends Emitter {
654
656
 
655
657
  this._cleanupMedia(session);
656
658
 
657
- delete this.sipSessions[getSipSessionId(session)];
659
+ delete this.sipSessions[getSipCallId(session)];
658
660
  // Check if Invitation or Inviter (Invitation = incoming call)
659
661
  const isInviter = session instanceof Inviter;
660
662
 
@@ -680,7 +682,7 @@ export default class WebRTCClient extends Emitter {
680
682
 
681
683
  // Fetch and emit an event at `interval` with session network stats
682
684
  startNetworkMonitoring(session: WazoSession, interval = 1000): void {
683
- const sessionId = getSipSessionId(session);
685
+ const sessionId = getSipCallId(session);
684
686
  logger.info('starting network inspection', {
685
687
  id: sessionId,
686
688
  clientId: this.clientId,
@@ -690,7 +692,7 @@ export default class WebRTCClient extends Emitter {
690
692
  }
691
693
 
692
694
  stopNetworkMonitoring(session: WazoSession): void {
693
- const sessionId = getSipSessionId(session);
695
+ const sessionId = getSipCallId(session);
694
696
  const exists = (sessionId in this.networkMonitoringInterval);
695
697
  logger.info('stopping network inspection', {
696
698
  clientId: this.clientId,
@@ -839,7 +841,7 @@ export default class WebRTCClient extends Emitter {
839
841
  }
840
842
 
841
843
  hold(session: WazoSession, isConference = false, hadVideo = false): Promise<OutgoingInviteRequest | void> {
842
- const sessionId = getSipSessionId(session);
844
+ const sessionId = getSipCallId(session);
843
845
  const hasVideo = hadVideo || this.hasLocalVideo(sessionId);
844
846
  logger.info('sdk webrtc hold', {
845
847
  sessionId,
@@ -897,7 +899,7 @@ export default class WebRTCClient extends Emitter {
897
899
  }
898
900
 
899
901
  unhold(session: WazoSession, isConference = false): Promise<OutgoingInviteRequest | void> {
900
- const sessionId = getSipSessionId(session);
902
+ const sessionId = getSipCallId(session);
901
903
  const hasVideo = sessionId in this.heldSessions && this.heldSessions[sessionId].hasVideo;
902
904
  logger.info('sdk webrtc unhold', {
903
905
  sessionId,
@@ -915,7 +917,7 @@ export default class WebRTCClient extends Emitter {
915
917
 
916
918
  this.unmute(session);
917
919
 
918
- delete this.heldSessions[getSipSessionId(session)];
920
+ delete this.heldSessions[getSipCallId(session)];
919
921
  session.sessionDescriptionHandlerOptionsReInvite = {
920
922
  hold: false,
921
923
  conference: isConference,
@@ -944,7 +946,7 @@ export default class WebRTCClient extends Emitter {
944
946
  }
945
947
 
946
948
  isCallHeld(session: WazoSession): boolean {
947
- return getSipSessionId(session) in this.heldSessions;
949
+ return getSipCallId(session) in this.heldSessions;
948
950
  }
949
951
 
950
952
  isVideoRemotelyHeld(sessionId: string): boolean {
@@ -957,7 +959,7 @@ export default class WebRTCClient extends Emitter {
957
959
  }
958
960
 
959
961
  logger.info('Sending DTMF', {
960
- id: getSipSessionId(session),
962
+ id: getSipCallId(session),
961
963
  tone,
962
964
  });
963
965
  return session.sessionDescriptionHandler.sendDtmf(tone);
@@ -976,7 +978,7 @@ export default class WebRTCClient extends Emitter {
976
978
  transfer(session: WazoSession, target: string): void {
977
979
  this.hold(session);
978
980
  logger.info('Transfering a session', {
979
- id: getSipSessionId(session),
981
+ id: getSipCallId(session),
980
982
  target,
981
983
  });
982
984
  const options = {
@@ -1000,21 +1002,21 @@ export default class WebRTCClient extends Emitter {
1000
1002
  atxfer(session: WazoSession): Record<string, any> {
1001
1003
  this.hold(session);
1002
1004
  logger.info('webrtc transfer started', {
1003
- id: getSipSessionId(session),
1005
+ id: getSipCallId(session),
1004
1006
  });
1005
1007
  const result: Record<string, any> = {
1006
1008
  newSession: null,
1007
1009
  init: async (target: string) => {
1008
1010
  logger.info('webrtc transfer initialized', {
1009
- id: getSipSessionId(session),
1011
+ id: getSipCallId(session),
1010
1012
  target,
1011
1013
  });
1012
1014
  result.newSession = await this.call(target);
1013
1015
  },
1014
1016
  complete: () => {
1015
1017
  logger.info('webrtc transfer completed', {
1016
- id: getSipSessionId(session),
1017
- referId: getSipSessionId(result.newSession),
1018
+ id: getSipCallId(session),
1019
+ referId: getSipCallId(result.newSession),
1018
1020
  });
1019
1021
  session.refer(result.newSession);
1020
1022
  },
@@ -1213,7 +1215,7 @@ export default class WebRTCClient extends Emitter {
1213
1215
 
1214
1216
  const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
1215
1217
  const pc = sdh.peerConnection;
1216
- const sessionId = getSipSessionId(session);
1218
+ const sessionId = getSipCallId(session);
1217
1219
  const localStream = this.getLocalStream(sessionId);
1218
1220
  logger.info('changing video input device', {
1219
1221
  id,
@@ -1286,7 +1288,7 @@ export default class WebRTCClient extends Emitter {
1286
1288
  const desktop = newConstraints && newConstraints.desktop;
1287
1289
  logger.info('Sending reinvite', {
1288
1290
  clientId: this.clientId,
1289
- id: getSipSessionId(sipSession),
1291
+ id: getSipCallId(sipSession),
1290
1292
  newConstraints,
1291
1293
  conference,
1292
1294
  audioOnly,
@@ -1324,7 +1326,7 @@ export default class WebRTCClient extends Emitter {
1324
1326
  }
1325
1327
 
1326
1328
  logger.info('on re-INVITE accepted', {
1327
- id: getSipSessionId(sipSession),
1329
+ id: getSipCallId(sipSession),
1328
1330
  wasMuted,
1329
1331
  shouldDoScreenSharing,
1330
1332
  });
@@ -1464,7 +1466,7 @@ export default class WebRTCClient extends Emitter {
1464
1466
  onCallEnded(session: WazoSession): void {
1465
1467
  this._cleanupMedia(session);
1466
1468
 
1467
- delete this.sipSessions[getSipSessionId(session)];
1469
+ delete this.sipSessions[getSipCallId(session)];
1468
1470
 
1469
1471
  this._stopSendingStats(session);
1470
1472
 
@@ -1483,17 +1485,17 @@ export default class WebRTCClient extends Emitter {
1483
1485
  }
1484
1486
 
1485
1487
  storeSipSession(session: WazoSession): void {
1486
- const id = getSipSessionId(session);
1488
+ const id = getSipCallId(session);
1487
1489
  logger.info('storing sip session', { id, clientId: this.clientId });
1488
1490
 
1489
1491
  this.sipSessions[id] = session;
1490
1492
  }
1491
1493
 
1492
1494
  getSipSession(id: string): WazoSession | null | undefined {
1493
- return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_LENGTH)] : null;
1495
+ return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_MIN_LENGTH)] : null;
1494
1496
  }
1495
1497
 
1496
- getSipSessionIds(): string[] {
1498
+ getSipCallIds(): string[] {
1497
1499
  return Object.keys(this.sipSessions);
1498
1500
  }
1499
1501
 
@@ -1686,7 +1688,7 @@ export default class WebRTCClient extends Emitter {
1686
1688
 
1687
1689
  // Invitation and Inviter extends Session
1688
1690
  _setupSession(session: WazoSession): void {
1689
- const sipSessionId = getSipSessionId(session);
1691
+ const sipSessionId = getSipCallId(session);
1690
1692
 
1691
1693
  // When receiving an Invitation, the delegate is not defined.
1692
1694
  if (!session.delegate) {
@@ -1761,7 +1763,7 @@ export default class WebRTCClient extends Emitter {
1761
1763
  async _onProgress(session: WazoSession, early = false): Promise<void> {
1762
1764
  await this._setupMedias(session);
1763
1765
 
1764
- const sessionId = getSipSessionId(session).substr(0, 20);
1766
+ const sessionId = getSipCallId(session).substr(0, 20);
1765
1767
  updateRemoteStream(session);
1766
1768
  logger.info('progress received', {
1767
1769
  sessionId,
@@ -1829,7 +1831,7 @@ export default class WebRTCClient extends Emitter {
1829
1831
  }
1830
1832
 
1831
1833
  // Safari hack, because you cannot call .play() from a non user action
1832
- const sessionId = getSipSessionId(session);
1834
+ const sessionId = getSipCallId(session);
1833
1835
  const isConference = this.isConference(sessionId);
1834
1836
 
1835
1837
  if (sessionId in this.audioElements) {
@@ -1884,7 +1886,7 @@ export default class WebRTCClient extends Emitter {
1884
1886
  }
1885
1887
 
1886
1888
  _cleanupMedia(session?: WazoSession): void {
1887
- const sessionId = getSipSessionId(session);
1889
+ const sessionId = getSipCallId(session);
1888
1890
  const localStream = this.getLocalStream(sessionId);
1889
1891
 
1890
1892
  if (localStream) {
@@ -1910,7 +1912,7 @@ export default class WebRTCClient extends Emitter {
1910
1912
 
1911
1913
  if (this._hasAudio() && isWeb()) {
1912
1914
  if (session) {
1913
- cleanLocalElement(getSipSessionId(session));
1915
+ cleanLocalElement(getSipCallId(session));
1914
1916
  } else {
1915
1917
  Object.keys(this.audioElements).forEach(id => cleanLocalElement(id));
1916
1918
  }
@@ -1933,7 +1935,7 @@ export default class WebRTCClient extends Emitter {
1933
1935
  return;
1934
1936
  }
1935
1937
 
1936
- const sessionId = getSipSessionId(session);
1938
+ const sessionId = getSipCallId(session);
1937
1939
  getStats(pc, (result: Record<string, any>) => {
1938
1940
  const {
1939
1941
  results,
@@ -1950,7 +1952,7 @@ export default class WebRTCClient extends Emitter {
1950
1952
  }
1951
1953
 
1952
1954
  _stopSendingStats(session: WazoSession): void {
1953
- const sessionId = getSipSessionId(session);
1955
+ const sessionId = getSipCallId(session);
1954
1956
  logger.trace('Check for stopping stats', {
1955
1957
  sessionId,
1956
1958
  ids: Object.keys(this.statsIntervals),