@wazo/sdk 0.43.6 → 1.0.0-alpha.1

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 (141) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/__voice__/call.test.js +72 -0
  3. package/esm/__tests__/__voice__/softphone.test.js +66 -0
  4. package/esm/checker/checks/webrtc.js +2 -1
  5. package/esm/domain/InvalidState.js +8 -0
  6. package/esm/domain/InvalidStateTransition.js +10 -0
  7. package/esm/domain/Phone/WebRTCPhone.js +33 -35
  8. package/esm/index.js +2 -0
  9. package/esm/simple/Phone.js +2 -1
  10. package/esm/simple/index.js +8 -2
  11. package/esm/simple/room/Room.js +2 -1
  12. package/esm/simple/room/SipRoom.js +2 -1
  13. package/esm/state-machine/call-state-machine.js +114 -0
  14. package/esm/state-machine/softphone-state-machine.js +39 -0
  15. package/esm/state-machine/utils.js +40 -0
  16. package/esm/types/__tests__/__voice__/call.test.d.ts +2 -0
  17. package/esm/types/__tests__/__voice__/call.test.d.ts.map +1 -0
  18. package/esm/types/__tests__/__voice__/softphone.test.d.ts +2 -0
  19. package/esm/types/__tests__/__voice__/softphone.test.d.ts.map +1 -0
  20. package/esm/types/checker/checks/webrtc.d.ts.map +1 -1
  21. package/esm/types/domain/InvalidState.d.ts +6 -0
  22. package/esm/types/domain/InvalidState.d.ts.map +1 -0
  23. package/esm/types/domain/InvalidStateTransition.d.ts +7 -0
  24. package/esm/types/domain/InvalidStateTransition.d.ts.map +1 -0
  25. package/esm/types/domain/Phone/WebRTCPhone.d.ts +0 -1
  26. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  27. package/esm/types/domain/types.d.ts +4 -0
  28. package/esm/types/domain/types.d.ts.map +1 -1
  29. package/esm/types/index.d.ts +2 -0
  30. package/esm/types/index.d.ts.map +1 -1
  31. package/esm/types/simple/Phone.d.ts.map +1 -1
  32. package/esm/types/simple/index.d.ts +7 -2
  33. package/esm/types/simple/index.d.ts.map +1 -1
  34. package/esm/types/simple/room/Room.d.ts.map +1 -1
  35. package/esm/types/simple/room/SipRoom.d.ts +1 -1
  36. package/esm/types/simple/room/SipRoom.d.ts.map +1 -1
  37. package/esm/types/state-machine/call-state-machine.d.ts +43 -0
  38. package/esm/types/state-machine/call-state-machine.d.ts.map +1 -0
  39. package/esm/types/state-machine/softphone-state-machine.d.ts +19 -0
  40. package/esm/types/state-machine/softphone-state-machine.d.ts.map +1 -0
  41. package/esm/types/state-machine/utils.d.ts +9 -0
  42. package/esm/types/state-machine/utils.d.ts.map +1 -0
  43. package/esm/types/utils/sdp.d.ts +6 -0
  44. package/esm/types/utils/sdp.d.ts.map +1 -1
  45. package/esm/types/utils/sip-logger.d.ts +4 -0
  46. package/esm/types/utils/sip-logger.d.ts.map +1 -0
  47. package/esm/types/utils/webrtc.d.ts +40 -0
  48. package/esm/types/utils/webrtc.d.ts.map +1 -1
  49. package/esm/types/voice/call.d.ts +110 -0
  50. package/esm/types/voice/call.d.ts.map +1 -0
  51. package/esm/types/voice/softphone.d.ts +77 -0
  52. package/esm/types/voice/softphone.d.ts.map +1 -0
  53. package/esm/types/web-rtc-client.d.ts +1 -36
  54. package/esm/types/web-rtc-client.d.ts.map +1 -1
  55. package/esm/utils/sdp.js +26 -0
  56. package/esm/utils/sip-logger.js +32 -0
  57. package/esm/utils/webrtc.js +465 -0
  58. package/esm/voice/call.js +527 -0
  59. package/esm/voice/softphone.js +347 -0
  60. package/esm/web-rtc-client.js +86 -584
  61. package/lib/__tests__/__voice__/call.test.js +86 -0
  62. package/lib/__tests__/__voice__/softphone.test.js +80 -0
  63. package/lib/checker/checks/webrtc.js +2 -1
  64. package/lib/domain/InvalidState.js +9 -0
  65. package/lib/domain/InvalidStateTransition.js +10 -0
  66. package/lib/domain/Phone/WebRTCPhone.js +33 -35
  67. package/lib/index.js +6 -2
  68. package/lib/simple/Phone.js +2 -1
  69. package/lib/simple/index.js +6 -0
  70. package/lib/simple/room/Room.js +4 -3
  71. package/lib/simple/room/SipRoom.js +2 -1
  72. package/lib/state-machine/call-state-machine.js +120 -0
  73. package/lib/state-machine/softphone-state-machine.js +42 -0
  74. package/lib/state-machine/utils.js +52 -0
  75. package/lib/types/__tests__/__voice__/call.test.d.ts +2 -0
  76. package/lib/types/__tests__/__voice__/call.test.d.ts.map +1 -0
  77. package/lib/types/__tests__/__voice__/softphone.test.d.ts +2 -0
  78. package/lib/types/__tests__/__voice__/softphone.test.d.ts.map +1 -0
  79. package/lib/types/checker/checks/webrtc.d.ts.map +1 -1
  80. package/lib/types/domain/InvalidState.d.ts +6 -0
  81. package/lib/types/domain/InvalidState.d.ts.map +1 -0
  82. package/lib/types/domain/InvalidStateTransition.d.ts +7 -0
  83. package/lib/types/domain/InvalidStateTransition.d.ts.map +1 -0
  84. package/lib/types/domain/Phone/WebRTCPhone.d.ts +0 -1
  85. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  86. package/lib/types/domain/types.d.ts +4 -0
  87. package/lib/types/domain/types.d.ts.map +1 -1
  88. package/lib/types/index.d.ts +2 -0
  89. package/lib/types/index.d.ts.map +1 -1
  90. package/lib/types/simple/Phone.d.ts.map +1 -1
  91. package/lib/types/simple/index.d.ts +7 -2
  92. package/lib/types/simple/index.d.ts.map +1 -1
  93. package/lib/types/simple/room/Room.d.ts.map +1 -1
  94. package/lib/types/simple/room/SipRoom.d.ts +1 -1
  95. package/lib/types/simple/room/SipRoom.d.ts.map +1 -1
  96. package/lib/types/state-machine/call-state-machine.d.ts +43 -0
  97. package/lib/types/state-machine/call-state-machine.d.ts.map +1 -0
  98. package/lib/types/state-machine/softphone-state-machine.d.ts +19 -0
  99. package/lib/types/state-machine/softphone-state-machine.d.ts.map +1 -0
  100. package/lib/types/state-machine/utils.d.ts +9 -0
  101. package/lib/types/state-machine/utils.d.ts.map +1 -0
  102. package/lib/types/utils/sdp.d.ts +6 -0
  103. package/lib/types/utils/sdp.d.ts.map +1 -1
  104. package/lib/types/utils/sip-logger.d.ts +4 -0
  105. package/lib/types/utils/sip-logger.d.ts.map +1 -0
  106. package/lib/types/utils/webrtc.d.ts +40 -0
  107. package/lib/types/utils/webrtc.d.ts.map +1 -1
  108. package/lib/types/voice/call.d.ts +110 -0
  109. package/lib/types/voice/call.d.ts.map +1 -0
  110. package/lib/types/voice/softphone.d.ts +77 -0
  111. package/lib/types/voice/softphone.d.ts.map +1 -0
  112. package/lib/types/web-rtc-client.d.ts +1 -36
  113. package/lib/types/web-rtc-client.d.ts.map +1 -1
  114. package/lib/utils/sdp.js +27 -1
  115. package/lib/utils/sip-logger.js +37 -0
  116. package/lib/utils/webrtc.js +521 -1
  117. package/lib/voice/call.js +577 -0
  118. package/lib/voice/softphone.js +375 -0
  119. package/lib/web-rtc-client.js +89 -601
  120. package/package.json +3 -2
  121. package/src/__tests__/__voice__/call.test.ts +90 -0
  122. package/src/__tests__/__voice__/softphone.test.ts +82 -0
  123. package/src/checker/checks/webrtc.ts +2 -1
  124. package/src/domain/InvalidState.ts +13 -0
  125. package/src/domain/InvalidStateTransition.ts +17 -0
  126. package/src/domain/Phone/WebRTCPhone.ts +34 -36
  127. package/src/domain/types.ts +6 -1
  128. package/src/index.ts +2 -0
  129. package/src/simple/Phone.ts +2 -1
  130. package/src/simple/index.ts +9 -2
  131. package/src/simple/room/Room.ts +2 -1
  132. package/src/simple/room/SipRoom.ts +2 -1
  133. package/src/state-machine/call-state-machine.ts +131 -0
  134. package/src/state-machine/softphone-state-machine.ts +49 -0
  135. package/src/state-machine/utils.ts +53 -0
  136. package/src/utils/sdp.ts +36 -0
  137. package/src/utils/sip-logger.ts +40 -0
  138. package/src/utils/webrtc.ts +571 -0
  139. package/src/voice/call.ts +713 -0
  140. package/src/voice/softphone.ts +485 -0
  141. package/src/web-rtc-client.ts +90 -690
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ /* eslint-disable no-underscore-dangle */
16
+ const sip_js_1 = require("sip.js");
17
+ const softphone_1 = __importDefault(require("../../voice/softphone"));
18
+ const call_1 = __importDefault(require("../../voice/call"));
19
+ const call_state_machine_1 = require("../../state-machine/call-state-machine");
20
+ const softphone_state_machine_1 = require("../../state-machine/softphone-state-machine");
21
+ const InvalidStateTransition_1 = __importDefault(require("../../domain/InvalidStateTransition"));
22
+ const uaOptions = {
23
+ logBuiltinEnabled: false,
24
+ transportOptions: {
25
+ traceSip: false,
26
+ wsServers: 'ws://localhost',
27
+ },
28
+ };
29
+ jest.mock('../..', () => ({
30
+ __esModule: true,
31
+ default: {
32
+ Auth: {
33
+ getHost: jest.fn(() => 'my-stack.io'),
34
+ getSession: jest.fn(() => ({
35
+ displayName: () => 'John Doe',
36
+ primaryWebRtcLine: () => ({}),
37
+ })),
38
+ },
39
+ },
40
+ }));
41
+ jest.mock('../../web-rtc-client', () => jest.fn().mockImplementation(() => ({
42
+ answer: jest.fn(() => Promise.resolve()),
43
+ hangup: jest.fn(() => Promise.resolve()),
44
+ register: jest.fn(() => Promise.resolve()),
45
+ setOnHeartbeatTimeout: jest.fn(() => Promise.resolve()),
46
+ setOnHeartbeatCallback: jest.fn(() => Promise.resolve()),
47
+ on: jest.fn(),
48
+ })));
49
+ const ua = new sip_js_1.UserAgent(uaOptions);
50
+ const sipCall = new sip_js_1.Inviter(ua, sip_js_1.UserAgent.makeURI('sip:1234@my.stack.io'));
51
+ softphone_1.default.connect();
52
+ softphone_1.default._sendAction(softphone_state_machine_1.Actions.REGISTER_DONE);
53
+ const invalidStateTransition = (state, action) => new InvalidStateTransition_1.default(`Invalid state transition from ${state} with action ${action}`, state, action);
54
+ describe('Call', () => {
55
+ describe('accept', () => {
56
+ it('Should throw an error when accepting a not ringing call', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ const call = new call_1.default(sipCall, softphone_1.default);
58
+ yield expect(call.accept()).rejects.toThrowError(invalidStateTransition(call_state_machine_1.States.IDLE, call_state_machine_1.Actions.ACCEPT));
59
+ }));
60
+ it.only('Should throw an error when the softphone is not registered', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ const call = new call_1.default(sipCall, softphone_1.default);
62
+ call._sendAction(call_state_machine_1.Actions.INCOMING_CALL);
63
+ softphone_1.default._sendAction(softphone_state_machine_1.Actions.TRANSPORT_CLOSED);
64
+ yield expect(call.accept()).rejects.toThrowError(invalidStateTransition(call_state_machine_1.States.RINGING, call_state_machine_1.Actions.ACCEPT));
65
+ }));
66
+ it('Should not throw an error when accepting a not ringing call', () => __awaiter(void 0, void 0, void 0, function* () {
67
+ const call = new call_1.default(sipCall, softphone_1.default);
68
+ call._sendAction(call_state_machine_1.Actions.INCOMING_CALL);
69
+ yield call.accept();
70
+ expect(softphone_1.default.client.answer).toHaveBeenCalled();
71
+ }));
72
+ });
73
+ describe('hangup', () => {
74
+ it('Should throw an error when terminating a non established call', () => __awaiter(void 0, void 0, void 0, function* () {
75
+ const call = new call_1.default(sipCall, softphone_1.default);
76
+ yield expect(call.hangup()).rejects.toThrowError(invalidStateTransition(call_state_machine_1.States.IDLE, call_state_machine_1.Actions.HANGUP));
77
+ }));
78
+ it('Should not throw an error when terminating an established call', () => __awaiter(void 0, void 0, void 0, function* () {
79
+ const call = new call_1.default(sipCall, softphone_1.default);
80
+ call._sendAction(call_state_machine_1.Actions.MAKE_CALL);
81
+ call._sendAction(call_state_machine_1.Actions.REMOTLY_ACCEPTED);
82
+ yield call.hangup();
83
+ expect(softphone_1.default.client.hangup).toHaveBeenCalled();
84
+ }));
85
+ });
86
+ });
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const softphone_1 = require("../../voice/softphone");
16
+ const softphone_state_machine_1 = require("../../state-machine/softphone-state-machine");
17
+ const __1 = __importDefault(require("../.."));
18
+ const InvalidStateTransition_1 = __importDefault(require("../../domain/InvalidStateTransition"));
19
+ const server = 'my.stack.io';
20
+ const displayName = 'John Doe';
21
+ const webRtcLine = {};
22
+ const session = {
23
+ uuid: '1234',
24
+ displayName: jest.fn(() => displayName),
25
+ primaryWebRtcLine: jest.fn(() => webRtcLine),
26
+ };
27
+ jest.mock('../..', () => ({
28
+ __esModule: true,
29
+ default: {
30
+ Auth: {
31
+ getHost: jest.fn(() => server),
32
+ getSession: jest.fn(() => session),
33
+ },
34
+ },
35
+ }));
36
+ jest.mock('../../web-rtc-client', () => jest.fn().mockImplementation(() => ({
37
+ register: jest.fn(() => Promise.resolve()),
38
+ unregister: jest.fn(() => Promise.resolve()),
39
+ setOnHeartbeatTimeout: jest.fn(() => Promise.resolve()),
40
+ setOnHeartbeatCallback: jest.fn(() => Promise.resolve()),
41
+ on: jest.fn(),
42
+ INVITE: 'invite',
43
+ })));
44
+ const invalidStateTransition = (state, action) => new InvalidStateTransition_1.default(`Invalid state transition from ${state} with action ${action}`, state, action);
45
+ describe('Softphone', () => {
46
+ describe('connect', () => {
47
+ it('Should retrieve information from Wazo.Auth', () => {
48
+ const instance = new softphone_1.Softphone();
49
+ jest.spyOn(instance, 'connectWithCredentials');
50
+ instance.connect({});
51
+ expect(__1.default.Auth.getHost).toHaveBeenCalled();
52
+ expect(__1.default.Auth.getSession).toHaveBeenCalled();
53
+ expect(instance.connectWithCredentials).toHaveBeenCalledWith(server, webRtcLine, displayName, { userUuid: session.uuid });
54
+ expect(instance.client.on).toHaveBeenCalledWith('invite', expect.anything());
55
+ });
56
+ it('Should throw an error when already connected', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ const instance = new softphone_1.Softphone();
58
+ instance.softphoneActor.send({ type: softphone_state_machine_1.Actions.REGISTER });
59
+ yield expect(instance.connect({})).rejects.toThrowError(invalidStateTransition(softphone_state_machine_1.States.REGISTERING, softphone_state_machine_1.Actions.REGISTER));
60
+ }));
61
+ it('Should not allow to register twice', () => __awaiter(void 0, void 0, void 0, function* () {
62
+ const instance = new softphone_1.Softphone();
63
+ instance.connect({});
64
+ yield expect(instance.connect({})).rejects.toThrowError(invalidStateTransition(softphone_state_machine_1.States.REGISTERING, softphone_state_machine_1.Actions.REGISTER));
65
+ }));
66
+ });
67
+ describe('disconnect', () => {
68
+ it('Should throw an error when not connected', () => __awaiter(void 0, void 0, void 0, function* () {
69
+ const instance = new softphone_1.Softphone();
70
+ yield expect(instance.disconnect()).rejects.toThrowError(invalidStateTransition(softphone_state_machine_1.States.UNREGISTERED, softphone_state_machine_1.Actions.UNREGISTER));
71
+ }));
72
+ it('Should unregister the client', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const instance = new softphone_1.Softphone();
74
+ instance.connect({});
75
+ instance.softphoneActor.send({ type: softphone_state_machine_1.Actions.REGISTER_DONE });
76
+ yield instance.disconnect();
77
+ expect(instance.client.unregister).toHaveBeenCalled();
78
+ }));
79
+ });
80
+ });
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  /* global MediaStream */
16
+ const sdp_1 = require("../../utils/sdp");
16
17
  const web_rtc_client_1 = __importDefault(require("../../web-rtc-client"));
17
18
  exports.default = {
18
19
  name: 'WebRTC',
@@ -42,7 +43,7 @@ exports.default = {
42
43
  });
43
44
  client.on(client.REGISTERED, () => {
44
45
  const sipSession = client.call('*10');
45
- if (!sipSession || !client.getSipSessionId(sipSession)) {
46
+ if (!sipSession || !(0, sdp_1.getSipSessionId)(sipSession)) {
46
47
  return handleError('Unable to make call through WebRTC');
47
48
  }
48
49
  setTimeout(() => {
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class InvalidState extends Error {
4
+ constructor(message, state) {
5
+ super(message);
6
+ this.state = state;
7
+ }
8
+ }
9
+ exports.default = InvalidState;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class InvalidStateTransition extends Error {
4
+ constructor(message, action, state) {
5
+ super(message);
6
+ this.action = action;
7
+ this.state = state;
8
+ }
9
+ }
10
+ exports.default = InvalidStateTransition;
@@ -18,6 +18,8 @@ const api_1 = require("sip.js/lib/api");
18
18
  const CallSession_1 = __importDefault(require("../CallSession"));
19
19
  const Emitter_1 = __importDefault(require("../../utils/Emitter"));
20
20
  const IssueReporter_1 = __importDefault(require("../../service/IssueReporter"));
21
+ const sdp_1 = require("../../utils/sdp");
22
+ const webrtc_1 = require("../../utils/webrtc");
21
23
  exports.ON_USER_AGENT = 'onUserAgent';
22
24
  exports.ON_REGISTERED = 'onRegistered';
23
25
  exports.ON_UNREGISTERED = 'onUnRegistered';
@@ -220,7 +222,7 @@ class WebRTCPhone extends Emitter_1.default {
220
222
  id: callSession ? callSession.getId() : null,
221
223
  withMessage,
222
224
  });
223
- this.client.downgradeToAudio(sipSession);
225
+ (0, webrtc_1.downgradeToAudio)(sipSession);
224
226
  if (callSession) {
225
227
  callSession.cameraEnabled = false;
226
228
  this._updateCallSession(callSession);
@@ -246,7 +248,7 @@ class WebRTCPhone extends Emitter_1.default {
246
248
  const desktop = constraints && constraints.desktop;
247
249
  const options = sipSession.sessionDescriptionHandlerOptionsReInvite;
248
250
  const wasAudioOnly = options === null || options === void 0 ? void 0 : options.audioOnly;
249
- const newStream = yield this.client.upgradeToVideo(sipSession, constraints, isConference);
251
+ const newStream = yield (0, webrtc_1.upgradeToVideo)(sipSession, constraints, isConference);
250
252
  if (callSession) {
251
253
  callSession.cameraEnabled = true;
252
254
  this._updateCallSession(callSession);
@@ -280,16 +282,15 @@ class WebRTCPhone extends Emitter_1.default {
280
282
  content: {
281
283
  type: exports.ON_MESSAGE_TRACK_UPDATED,
282
284
  update: isUpgrade ? 'upgrade' : 'downgrade',
283
- sipCallId: sipSession && this.getSipSessionId(sipSession),
285
+ sipCallId: sipSession && (0, sdp_1.getSipSessionId)(sipSession),
284
286
  callId: callSession ? callSession.callId : null,
285
287
  number: callSession ? callSession.number : null,
286
- callerNumber: callSession ? callSession.callerNumber : null,
287
288
  },
288
289
  }));
289
290
  }, 2500);
290
291
  }
291
292
  _bindEvents(sipSession) {
292
- const sipSessionId = this.getSipSessionId(sipSession);
293
+ const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
293
294
  if (sipSession instanceof api_1.Invitation) {
294
295
  // Monkey patch to know when canceled with the CANCEL message
295
296
  const onCancel = sipSession._onCancel.bind(sipSession);
@@ -343,7 +344,7 @@ class WebRTCPhone extends Emitter_1.default {
343
344
  const [stream] = event.streams;
344
345
  const kind = event && event.track && event.track.kind;
345
346
  logger.info('on track stream called on the peer connection', {
346
- callId: this.getSipSessionId(sipSession),
347
+ callId: (0, sdp_1.getSipSessionId)(sipSession),
347
348
  streamId: stream ? stream.id : null,
348
349
  tracks: stream ? stream.getTracks() : null,
349
350
  kind,
@@ -367,15 +368,15 @@ class WebRTCPhone extends Emitter_1.default {
367
368
  constraints,
368
369
  id: callSession ? callSession.getId() : null,
369
370
  });
370
- const screenShareStream = yield this.client.getStreamFromConstraints(constraints);
371
+ const screenShareStream = yield (0, webrtc_1.getStreamFromConstraints)(constraints);
371
372
  if (!screenShareStream) {
372
373
  throw new Error(`Can't create media stream for screensharing with: ${JSON.stringify(constraints)}`);
373
374
  }
374
375
  const screenTrack = screenShareStream.getVideoTracks()[0];
375
376
  const sipSession = this.currentSipSession;
376
- const pc = sipSession && this.client.getPeerConnection(this.getSipSessionId(sipSession));
377
+ const pc = sipSession && this.client.getPeerConnection((0, sdp_1.getSipSessionId)(sipSession));
377
378
  const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
378
- const localStream = sipSession && this.client.getLocalStream(this.getSipSessionId(sipSession));
379
+ const localStream = sipSession && this.client.getLocalStream((0, sdp_1.getSipSessionId)(sipSession));
379
380
  const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
380
381
  const hadVideo = !!videoTrack;
381
382
  // Stop local video tracks
@@ -440,19 +441,19 @@ class WebRTCPhone extends Emitter_1.default {
440
441
  }
441
442
  _onScreenSharing(screenStream, sipSession, callSession, hadVideo, desktop) {
442
443
  const screenTrack = screenStream.getVideoTracks()[0];
443
- const sipSessionId = this.getSipSessionId(sipSession);
444
+ const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
444
445
  const pc = this.client.getPeerConnection(sipSessionId);
445
446
  const sender = pc && pc.getSenders && pc.getSenders().find((s) => s && s.track && s.track.kind === 'video');
446
447
  logger.info('WebRTC phone - on screensharing', {
447
448
  hadVideo,
448
- id: this.getSipSessionId(sipSession),
449
+ id: (0, sdp_1.getSipSessionId)(sipSession),
449
450
  screenTrack,
450
451
  });
451
452
  if (screenTrack) {
452
453
  screenTrack.onended = () => {
453
454
  logger.info('WebRTC phone - on screenshare ended', {
454
455
  hadVideo,
455
- id: this.getSipSessionId(sipSession),
456
+ id: (0, sdp_1.getSipSessionId)(sipSession),
456
457
  screenTrack,
457
458
  });
458
459
  this.eventEmitter.emit(exports.ON_SHARE_SCREEN_ENDING, this._createCallSession(sipSession, callSession));
@@ -465,7 +466,7 @@ class WebRTCPhone extends Emitter_1.default {
465
466
  sipSessionId,
466
467
  desktop,
467
468
  };
468
- this.client.setLocalMediaStream(this.getSipSessionId(sipSession), screenStream);
469
+ (0, webrtc_1.setLocalMediaStream)(sipSession, screenStream);
469
470
  this.eventEmitter.emit(exports.ON_SHARE_SCREEN_STARTED, this._createCallSession(sipSession, callSession, {
470
471
  screensharing: true,
471
472
  }), screenStream);
@@ -486,7 +487,7 @@ class WebRTCPhone extends Emitter_1.default {
486
487
  this.currentSipSession = sipSession;
487
488
  this.currentCallSession = callSession;
488
489
  this.eventEmitter.emit(exports.ON_TERMINATE_SOUND, callSession, 'call accepted');
489
- const sipSessionId = this.getSipSessionId(sipSession);
490
+ const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
490
491
  if (sipSessionId) {
491
492
  this.removeIncomingSessions(sipSessionId);
492
493
  }
@@ -549,7 +550,7 @@ class WebRTCPhone extends Emitter_1.default {
549
550
  return this.currentSipSession && this.client.changeSessionVideoInputDevice(id, this.currentSipSession);
550
551
  }
551
552
  _onCallTerminated(sipSession) {
552
- const sipSessionId = this.getSipSessionId(sipSession);
553
+ const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
553
554
  logger.info('WebRTC phone - on call terminated', {
554
555
  sipId: sipSession.id,
555
556
  sipSessionId,
@@ -641,7 +642,7 @@ class WebRTCPhone extends Emitter_1.default {
641
642
  if (!this.currentSipSession) {
642
643
  return false;
643
644
  }
644
- return this.currentSipSession && this.getSipSessionId(this.currentSipSession) === callSession.getId();
645
+ return this.currentSipSession && (0, sdp_1.getSipSessionId)(this.currentSipSession) === callSession.getId();
645
646
  }
646
647
  hasVideo(callSession) {
647
648
  return this.client.hasVideo(callSession.getId());
@@ -799,7 +800,7 @@ class WebRTCPhone extends Emitter_1.default {
799
800
  if (!sipSession) {
800
801
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
801
802
  }
802
- const sessionId = this.getSipSessionId(sipSession);
803
+ const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
803
804
  const hasVideo = this.client.hasLocalVideo(sessionId);
804
805
  logger.info('WebRTC hold sip session', {
805
806
  sipId: sipSession.id,
@@ -812,7 +813,7 @@ class WebRTCPhone extends Emitter_1.default {
812
813
  }
813
814
  // Downgrade to audio if needed
814
815
  if (hasVideo) {
815
- yield this.client.downgradeToAudio(sipSession);
816
+ yield (0, webrtc_1.downgradeToAudio)(sipSession);
816
817
  }
817
818
  const isConference = !!callSession && callSession.isConference();
818
819
  const promise = this.client.hold(sipSession, isConference, hasVideo);
@@ -828,7 +829,7 @@ class WebRTCPhone extends Emitter_1.default {
828
829
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
829
830
  }
830
831
  const isConference = !!callSession && callSession.isConference();
831
- const sessionId = this.getSipSessionId(sipSession);
832
+ const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
832
833
  logger.info('WebRTC unhold sip session', {
833
834
  sessionId,
834
835
  isConference,
@@ -844,7 +845,7 @@ class WebRTCPhone extends Emitter_1.default {
844
845
  screen: wasScreensharing,
845
846
  desktop: wasDesktop,
846
847
  };
847
- yield this.client.upgradeToVideo(sipSession, constraints, isConference);
848
+ yield (0, webrtc_1.upgradeToVideo)(sipSession, constraints, isConference);
848
849
  }
849
850
  const onScreenSharing = (stream) => {
850
851
  const hadVideo = this.lastScreenShare && this.lastScreenShare.hadVideo;
@@ -1057,7 +1058,7 @@ class WebRTCPhone extends Emitter_1.default {
1057
1058
  console.error('Call is unknown to the WebRTC phone', callSession ? callSession.sipCallId : null, callSession ? callSession.callId : null);
1058
1059
  return false;
1059
1060
  }
1060
- const sipSessionId = this.getSipSessionId(sipSession);
1061
+ const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
1061
1062
  logger.info('WebRTC hangup', {
1062
1063
  sipId: sipSession.id,
1063
1064
  sipSessionId,
@@ -1077,7 +1078,7 @@ class WebRTCPhone extends Emitter_1.default {
1077
1078
  getStats(callSession) {
1078
1079
  return __awaiter(this, void 0, void 0, function* () {
1079
1080
  const sipSession = this.findSipSession(callSession);
1080
- return sipSession ? this.client.getStats(sipSession) : null;
1081
+ return sipSession ? (0, webrtc_1.getWebRtcStats)(sipSession) : null;
1081
1082
  });
1082
1083
  }
1083
1084
  startNetworkMonitoring(callSession, interval = 1000) {
@@ -1249,12 +1250,12 @@ class WebRTCPhone extends Emitter_1.default {
1249
1250
  // if `_createCallSession` is called too soon `hasVideo` will return false because the stream doesn't exists yet
1250
1251
  setTimeout(() => {
1251
1252
  // Update callSession
1252
- this._createCallSession(sipSession, this.callSessions[this.getSipSessionId(sipSession)]);
1253
+ this._createCallSession(sipSession, this.callSessions[(0, sdp_1.getSipSessionId)(sipSession)]);
1253
1254
  this.eventEmitter.emit.apply(this.eventEmitter, [this.client.ON_REINVITE, ...args]);
1254
1255
  }, 2000);
1255
1256
  });
1256
1257
  this.client.on(this.client.ACCEPTED, (sipSession) => __awaiter(this, void 0, void 0, function* () {
1257
- const sessionId = this.getSipSessionId(sipSession);
1258
+ const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
1258
1259
  const hasSession = (sessionId in this.callSessions);
1259
1260
  logger.info('WebRTC call accepted', {
1260
1261
  sipId: sessionId,
@@ -1281,7 +1282,7 @@ class WebRTCPhone extends Emitter_1.default {
1281
1282
  const callSession = this._createCallSession(session);
1282
1283
  // `_createCallSession` add the CallSession in `this.callSessions`.
1283
1284
  // so we have to remove it or `callCount` will always return 1 even if the call was rejected
1284
- delete this.callSessions[this.getSipSessionId(session)];
1285
+ delete this.callSessions[(0, sdp_1.getSipSessionId)(session)];
1285
1286
  callSession.endTime = new Date();
1286
1287
  this.eventEmitter.emit(exports.ON_CALL_REJECTED, callSession);
1287
1288
  });
@@ -1298,7 +1299,7 @@ class WebRTCPhone extends Emitter_1.default {
1298
1299
  const callSession = this._createCallSession(session, null, {
1299
1300
  incoming: false,
1300
1301
  ringing: true,
1301
- callId: this.getSipSessionId(session),
1302
+ callId: (0, sdp_1.getSipSessionId)(session),
1302
1303
  });
1303
1304
  this.eventEmitter.emit(exports.ON_PROGRESS, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
1304
1305
  });
@@ -1307,7 +1308,7 @@ class WebRTCPhone extends Emitter_1.default {
1307
1308
  const callSession = this._createCallSession(session, null, {
1308
1309
  incoming: false,
1309
1310
  ringing: true,
1310
- callId: this.getSipSessionId(session),
1311
+ callId: (0, sdp_1.getSipSessionId)(session),
1311
1312
  });
1312
1313
  this.eventEmitter.emit(exports.ON_EARLY_MEDIA, callSession, this.audioOutputDeviceId, this.audioOutputVolume);
1313
1314
  });
@@ -1364,12 +1365,12 @@ class WebRTCPhone extends Emitter_1.default {
1364
1365
  this.eventEmitter.emit(exports.ON_MESSAGE, message);
1365
1366
  });
1366
1367
  this.client.on(this.client.ON_NETWORK_STATS, (session, stats, previousStats) => {
1367
- const callSession = this.getCallSession(this.getSipSessionId(session));
1368
+ const callSession = this.getCallSession((0, sdp_1.getSipSessionId)(session));
1368
1369
  this.eventEmitter.emit(exports.ON_NETWORK_STATS, callSession, stats, previousStats);
1369
1370
  });
1370
1371
  // Used when upgrading directly in screenshare mode
1371
1372
  this.client.on(this.client.ON_SCREEN_SHARING_REINVITE, (sipSession, response, desktop) => {
1372
- const sipSessionId = this.getSipSessionId(sipSession);
1373
+ const sipSessionId = (0, sdp_1.getSipSessionId)(sipSession);
1373
1374
  const localStream = this.client.getLocalStream(sipSessionId);
1374
1375
  const callSession = this.callSessions[sipSessionId];
1375
1376
  logger.info('Updrading directly in screensharing mode', {
@@ -1384,7 +1385,7 @@ class WebRTCPhone extends Emitter_1.default {
1384
1385
  const keys = this.client.getSipSessionIds();
1385
1386
  const keyIndex = keys.findIndex(sessionId => callSession && callSession.isId(sessionId));
1386
1387
  if (keyIndex === -1) {
1387
- const currentSipSessionId = this.currentSipSession ? this.getSipSessionId(this.currentSipSession) : this.client.getSipSessionIds()[0];
1388
+ const currentSipSessionId = this.currentSipSession ? (0, sdp_1.getSipSessionId)(this.currentSipSession) : this.client.getSipSessionIds()[0];
1388
1389
  return currentSipSessionId ? this.client.getSipSession(currentSipSessionId) : null;
1389
1390
  }
1390
1391
  return this.client.getSipSession(keys[keyIndex]);
@@ -1392,12 +1393,9 @@ class WebRTCPhone extends Emitter_1.default {
1392
1393
  getCallSession(sipSessionId) {
1393
1394
  return this.callSessions[sipSessionId];
1394
1395
  }
1395
- getSipSessionId(sipSession) {
1396
- return this.client.getSipSessionId(sipSession);
1397
- }
1398
1396
  getSipSessionIdFromCallSession(callSession) {
1399
1397
  const sipSession = this.findSipSession(callSession);
1400
- return sipSession ? this.getSipSessionId(sipSession) : null;
1398
+ return sipSession ? (0, sdp_1.getSipSessionId)(sipSession) : null;
1401
1399
  }
1402
1400
  _updateCallSession(callSession) {
1403
1401
  const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
@@ -1475,7 +1473,7 @@ class WebRTCPhone extends Emitter_1.default {
1475
1473
  // @ts-ignore: private
1476
1474
  const number = identity ? identity.uri._normal.user : null;
1477
1475
  const { state, } = sipSession || {};
1478
- const sessionId = this.getSipSessionId(sipSession);
1476
+ const sessionId = (0, sdp_1.getSipSessionId)(sipSession);
1479
1477
  fromSession = fromSession || this.callSessions[sessionId];
1480
1478
  const callSession = new CallSession_1.default(Object.assign({ callId: fromSession && fromSession.callId, sipCallId: sessionId, sipStatus: state, displayName: identity ? identity.displayName || number : number,
1481
1479
  // @ts-ignore: date / number
package/lib/index.js CHANGED
@@ -17,8 +17,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.WazoApiClient = exports.WebRTCClient = exports.SOCKET_EVENTS = exports.WebSocketClient = exports.AdHocAPIConference = exports.CallApi = exports.setIsMobile = exports.setOnRefreshTokenError = exports.setOnRefreshToken = exports.setCurrentServer = exports.setApiToken = exports.getApiClient = exports.SipLine = exports.MeetingAuthorization = exports.MeetingStatus = exports.ApiRequester = exports.Checker = exports.DebugDevice = exports.Meeting = exports.CTIPhone = exports.WebRTCPhone = exports.CallerID = exports.SwitchboardCall = exports.IndirectTransfer = exports.CallSession = exports.Room = exports.Relocation = exports.Voicemail = exports.Session = exports.LINE_STATE = exports.PROFILE_STATE = exports.Profile = exports.NotificationOptions = exports.Line = exports.Incall = exports.FORWARD_KEYS = exports.ForwardOption = exports.Features = exports.COUNTRIES = exports.Contact = exports.ChatRoom = exports.ChatMessage = exports.Recording = exports.CallLog = exports.Call = exports.SFUNotAvailableError = exports.ServerError = exports.BadResponse = exports.IssueReporter = exports.Emitter = void 0;
21
- exports.SessionDescriptionHandler = exports.ExternalApp = exports.Agent = void 0;
20
+ exports.SOCKET_EVENTS = exports.WebSocketClient = exports.AdHocAPIConference = exports.CallApi = exports.setIsMobile = exports.setOnRefreshTokenError = exports.setOnRefreshToken = exports.setCurrentServer = exports.setApiToken = exports.getApiClient = exports.SipLine = exports.MeetingAuthorization = exports.MeetingStatus = exports.ApiRequester = exports.Checker = exports.DebugDevice = exports.Meeting = exports.CTIPhone = exports.WebRTCPhone = exports.CallerID = exports.SwitchboardCall = exports.IndirectTransfer = exports.CallSession = exports.Room = exports.Relocation = exports.Voicemail = exports.Session = exports.LINE_STATE = exports.PROFILE_STATE = exports.Profile = exports.NotificationOptions = exports.Line = exports.Incall = exports.FORWARD_KEYS = exports.ForwardOption = exports.Features = exports.COUNTRIES = exports.Contact = exports.ChatRoom = exports.ChatMessage = exports.Recording = exports.CallLog = exports.Call = exports.SFUNotAvailableError = exports.InvalidState = exports.InvalidStateTransition = exports.ServerError = exports.BadResponse = exports.IssueReporter = exports.Emitter = void 0;
21
+ exports.SessionDescriptionHandler = exports.ExternalApp = exports.Agent = exports.WazoApiClient = exports.WebRTCClient = void 0;
22
22
  const index_1 = __importDefault(require("./simple/index"));
23
23
  var Emitter_1 = require("./utils/Emitter");
24
24
  Object.defineProperty(exports, "Emitter", { enumerable: true, get: function () { return __importDefault(Emitter_1).default; } });
@@ -28,6 +28,10 @@ var BadResponse_1 = require("./domain/BadResponse");
28
28
  Object.defineProperty(exports, "BadResponse", { enumerable: true, get: function () { return __importDefault(BadResponse_1).default; } });
29
29
  var ServerError_1 = require("./domain/ServerError");
30
30
  Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return __importDefault(ServerError_1).default; } });
31
+ var InvalidStateTransition_1 = require("./domain/InvalidStateTransition");
32
+ Object.defineProperty(exports, "InvalidStateTransition", { enumerable: true, get: function () { return __importDefault(InvalidStateTransition_1).default; } });
33
+ var InvalidState_1 = require("./domain/InvalidState");
34
+ Object.defineProperty(exports, "InvalidState", { enumerable: true, get: function () { return __importDefault(InvalidState_1).default; } });
31
35
  var SFUNotAvailableError_1 = require("./domain/SFUNotAvailableError");
32
36
  Object.defineProperty(exports, "SFUNotAvailableError", { enumerable: true, get: function () { return __importDefault(SFUNotAvailableError_1).default; } });
33
37
  var Call_1 = require("./domain/Call");
@@ -45,6 +45,7 @@ const IssueReporter_1 = __importDefault(require("../service/IssueReporter"));
45
45
  const Emitter_1 = __importDefault(require("../utils/Emitter"));
46
46
  const index_1 = __importDefault(require("./index"));
47
47
  const SFUNotAvailableError_1 = __importDefault(require("../domain/SFUNotAvailableError"));
48
+ const sdp_1 = require("../utils/sdp");
48
49
  const logger = IssueReporter_1.default.loggerFor('simple-phone');
49
50
  const sipLogger = IssueReporter_1.default.loggerFor('sip.js');
50
51
  const protocolLogger = IssueReporter_1.default.loggerFor('sip');
@@ -239,7 +240,7 @@ class Phone extends Emitter_1.default {
239
240
  if (!sipSession || !this.phone) {
240
241
  return null;
241
242
  }
242
- return this.phone.getSipSessionId(sipSession);
243
+ return (0, sdp_1.getSipSessionId)(sipSession);
243
244
  }
244
245
  sendMessage(body, sipSession, contentType = 'text/plain') {
245
246
  const toSipSession = sipSession || this.getCurrentSipSession();
@@ -68,6 +68,8 @@ const IssueReporter_1 = __importDefault(require("../service/IssueReporter"));
68
68
  const Features_1 = __importDefault(require("../domain/Features"));
69
69
  const Meeting_1 = __importDefault(require("../domain/Meeting"));
70
70
  const Checker_1 = __importDefault(require("../checker/Checker"));
71
+ const softphone_1 = __importDefault(require("../voice/softphone"));
72
+ const call_1 = __importDefault(require("../voice/call"));
71
73
  const Wazo = {
72
74
  Auth: Auth_1.default,
73
75
  Phone: Phone_1.default,
@@ -87,6 +89,10 @@ const Wazo = {
87
89
  loggerFor: IssueReporter_1.default.loggerFor.bind(IssueReporter_1.default),
88
90
  Features: Features_1.default,
89
91
  Checker: Checker_1.default,
92
+ Voice: {
93
+ Softphone: softphone_1.default,
94
+ Call: call_1.default,
95
+ },
90
96
  // Domain
91
97
  domain: {
92
98
  BadResponse: BadResponse_1.default,
@@ -19,6 +19,7 @@ const Emitter_1 = __importDefault(require("../../utils/Emitter"));
19
19
  const index_1 = __importDefault(require("../index"));
20
20
  const RemoteParticipant_1 = __importDefault(require("./RemoteParticipant"));
21
21
  const IssueReporter_1 = __importDefault(require("../../service/IssueReporter"));
22
+ const sdp_1 = require("../../utils/sdp");
22
23
  exports.SIGNAL_TYPE_PARTICIPANT_UPDATE = 'signal/PARTICIPANT_UPDATE';
23
24
  exports.SIGNAL_TYPE_PARTICIPANT_REQUEST = 'signal/PARTICIPANT_REQUEST';
24
25
  const logger = IssueReporter_1.default.loggerFor('sdk-room');
@@ -367,12 +368,12 @@ class Room extends Emitter_1.default {
367
368
  // This allow to map msid with the non parsed (eg without the `stripVideo` modifier) SDP
368
369
  index_1.default.Phone.phone.on(index_1.default.Phone.phone.client.ON_REINVITE, this._boundOnReinvite);
369
370
  this.on(this.ON_AUDIO_STREAM, (stream) => __awaiter(this, void 0, void 0, function* () {
370
- var _b, _c, _d;
371
+ var _b, _c;
371
372
  logger.info('on room audio stream');
372
373
  this.audioStream = stream;
373
374
  if (!this.roomAudioElement) {
374
- const sessionId = (_b = index_1.default.Phone.phone) === null || _b === void 0 ? void 0 : _b.getSipSessionId((_c = index_1.default.Phone.phone) === null || _c === void 0 ? void 0 : _c.currentSipSession);
375
- this.roomAudioElement = (yield ((_d = index_1.default.Phone.phone) === null || _d === void 0 ? void 0 : _d.createAudioElementFor(sessionId)));
375
+ const sessionId = (0, sdp_1.getSipSessionId)((_b = index_1.default.Phone.phone) === null || _b === void 0 ? void 0 : _b.currentSipSession);
376
+ this.roomAudioElement = (yield ((_c = index_1.default.Phone.phone) === null || _c === void 0 ? void 0 : _c.createAudioElementFor(sessionId)));
376
377
  this.roomAudioElement.srcObject = stream;
377
378
  }
378
379
  else {
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const IssueReporter_1 = __importDefault(require("../../service/IssueReporter"));
16
16
  const index_1 = __importDefault(require("../index"));
17
17
  const Room_1 = __importDefault(require("./Room"));
18
+ const sdp_1 = require("../../utils/sdp");
18
19
  const logger = IssueReporter_1.default.loggerFor('sdk-sip-room');
19
20
  class SipRoom extends Room_1.default {
20
21
  static connect(_a) {
@@ -135,7 +136,7 @@ class SipRoom extends Room_1.default {
135
136
  }
136
137
  _getCurrentSipCallIs() {
137
138
  var _a;
138
- return index_1.default.Phone.getSipSessionId((_a = index_1.default.Phone.phone) === null || _a === void 0 ? void 0 : _a.currentSipSession);
139
+ return (0, sdp_1.getSipSessionId)((_a = index_1.default.Phone.phone) === null || _a === void 0 ? void 0 : _a.currentSipSession);
139
140
  }
140
141
  }
141
142
  exports.default = SipRoom;