@wazo/sdk 0.41.1 → 0.41.2

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.
@@ -249,8 +249,8 @@ class WebRTCClient extends Emitter_1.default {
249
249
  return this.register();
250
250
  }
251
251
  onDisconnect(error) {
252
- var _a;
253
252
  return __awaiter(this, void 0, void 0, function* () {
253
+ var _a;
254
254
  logger.info('sdk webrtc disconnected', { method: 'delegate.onConnect', clientId: this.clientId, error });
255
255
  this.connectionPromise = null;
256
256
  // The UA will attempt to reconnect automatically when an error occurred
@@ -266,9 +266,9 @@ class WebRTCClient extends Emitter_1.default {
266
266
  }
267
267
  });
268
268
  }
269
- register(tries = 0) {
270
- var _a;
271
- return __awaiter(this, void 0, void 0, function* () {
269
+ register() {
270
+ return __awaiter(this, arguments, void 0, function* (tries = 0) {
271
+ var _a;
272
272
  const logInfo = {
273
273
  clientId: this.clientId,
274
274
  userAgent: !!this.userAgent,
@@ -449,14 +449,10 @@ class WebRTCClient extends Emitter_1.default {
449
449
  conference,
450
450
  options,
451
451
  });
452
- const inviterOptions = {
453
- sessionDescriptionHandlerOptionsReInvite: {
452
+ const inviterOptions = Object.assign({ sessionDescriptionHandlerOptionsReInvite: {
454
453
  conference,
455
454
  audioOnly,
456
- },
457
- earlyMedia: true,
458
- options,
459
- };
455
+ }, earlyMedia: true }, options);
460
456
  if (audioOnly) {
461
457
  inviterOptions.sessionDescriptionHandlerModifiersReInvite = [modifiers_1.stripVideo];
462
458
  }
@@ -576,8 +572,8 @@ class WebRTCClient extends Emitter_1.default {
576
572
  });
577
573
  }
578
574
  getStats(session) {
579
- var _a;
580
575
  return __awaiter(this, void 0, void 0, function* () {
576
+ var _a;
581
577
  const pc = (_a = session.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.peerConnection;
582
578
  if (!pc) {
583
579
  return null;
@@ -628,8 +624,8 @@ class WebRTCClient extends Emitter_1.default {
628
624
  }
629
625
  });
630
626
  }
631
- close(force = false) {
632
- return __awaiter(this, void 0, void 0, function* () {
627
+ close() {
628
+ return __awaiter(this, arguments, void 0, function* (force = false) {
633
629
  logger.info('sdk webrtc closing client', {
634
630
  clientId: this.clientId,
635
631
  userAgent: !!this.userAgent,
@@ -817,8 +813,8 @@ class WebRTCClient extends Emitter_1.default {
817
813
  }
818
814
  // Returns true if a re-INVITE is required
819
815
  upgradeToVideo(session, constraints, isConference) {
820
- var _a, _b;
821
816
  return __awaiter(this, void 0, void 0, function* () {
817
+ var _a, _b;
822
818
  const pc = (_a = session.sessionDescriptionHandler) === null || _a === void 0 ? void 0 : _a.peerConnection;
823
819
  // Check if a video sender already exists
824
820
  let videoSender;
@@ -875,8 +871,8 @@ class WebRTCClient extends Emitter_1.default {
875
871
  localStream.removeTrack(videoTrack);
876
872
  });
877
873
  }
878
- getStreamFromConstraints(constraints, conference = false) {
879
- return __awaiter(this, void 0, void 0, function* () {
874
+ getStreamFromConstraints(constraints_1) {
875
+ return __awaiter(this, arguments, void 0, function* (constraints, conference = false) {
880
876
  const video = constraints && constraints.video;
881
877
  const { constraints: newConstraints, } = this.getMediaConfiguration(video, conference, constraints);
882
878
  let newStream = null;
@@ -2032,9 +2028,9 @@ class WebRTCClient extends Emitter_1.default {
2032
2028
  _makeURI(target) {
2033
2029
  return user_agent_1.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
2034
2030
  }
2035
- _disconnectTransport(force = false) {
2036
- var _a;
2037
- return __awaiter(this, void 0, void 0, function* () {
2031
+ _disconnectTransport() {
2032
+ return __awaiter(this, arguments, void 0, function* (force = false) {
2033
+ var _a;
2038
2034
  const transport = (_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.transport;
2039
2035
  if (force && transport) {
2040
2036
  // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
@@ -2155,8 +2151,8 @@ class WebRTCClient extends Emitter_1.default {
2155
2151
  }
2156
2152
  });
2157
2153
  }
2158
- _accept(session, options = {}) {
2159
- return __awaiter(this, void 0, void 0, function* () {
2154
+ _accept(session_1) {
2155
+ return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2160
2156
  if (session.state === session_state_1.SessionState.Terminated || session.state === session_state_1.SessionState.Terminating) {
2161
2157
  const error = 'Trying to accept a terminated sipSession.';
2162
2158
  logger.warn(error, { state: session.state, sessionId: session.id });
@@ -2181,8 +2177,8 @@ class WebRTCClient extends Emitter_1.default {
2181
2177
  }
2182
2178
  });
2183
2179
  }
2184
- _reject(session, options = {}) {
2185
- return __awaiter(this, void 0, void 0, function* () {
2180
+ _reject(session_1) {
2181
+ return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2186
2182
  if (session.state !== session_state_1.SessionState.Initial && session.state !== session_state_1.SessionState.Establishing) {
2187
2183
  logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: session.id });
2188
2184
  return;
@@ -2200,8 +2196,8 @@ class WebRTCClient extends Emitter_1.default {
2200
2196
  }
2201
2197
  });
2202
2198
  }
2203
- _cancel(session, options = {}) {
2204
- return __awaiter(this, void 0, void 0, function* () {
2199
+ _cancel(session_1) {
2200
+ return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2205
2201
  if (session.state !== session_state_1.SessionState.Initial && session.state !== session_state_1.SessionState.Establishing) {
2206
2202
  logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: session.id });
2207
2203
  return;
@@ -2214,8 +2210,8 @@ class WebRTCClient extends Emitter_1.default {
2214
2210
  }
2215
2211
  });
2216
2212
  }
2217
- _bye(session, options = {}) {
2218
- return __awaiter(this, void 0, void 0, function* () {
2213
+ _bye(session_1) {
2214
+ return __awaiter(this, arguments, void 0, function* (session, options = {}) {
2219
2215
  if (session.state !== session_state_1.SessionState.Established) {
2220
2216
  logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: session.id });
2221
2217
  return null;
@@ -220,7 +220,7 @@ class WebSocketClient extends Emitter_1.default {
220
220
  logger.warn('Trying to close an already closed websocket, bailing.', { url: this._getUrl() });
221
221
  return;
222
222
  }
223
- this.socket.close();
223
+ this.socket.close(1000);
224
224
  this.initialized = false;
225
225
  if (force) {
226
226
  this.host = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.41.1",
3
+ "version": "0.41.2",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -51,26 +51,26 @@
51
51
  "fstream": "^1.0.12",
52
52
  "getstats": "wazo-platform/getStats#fix_stats_mobile",
53
53
  "google-libphonenumber": "^3.2.32",
54
- "js-base64": "^3.7.5",
54
+ "js-base64": "^3.7.7",
55
55
  "json-to-graphql-query": "^2.2.5",
56
- "jsrsasign": "^11.0.0",
57
- "moment": "^2.29.1",
56
+ "jsrsasign": "^11.1.0",
57
+ "moment": "^2.30.1",
58
58
  "reconnecting-websocket": "^4.4.0",
59
- "sdp-transform": "^2.14.1",
59
+ "sdp-transform": "^2.14.2",
60
60
  "sip.js": "^0.21.2",
61
61
  "webrtc-adapter": "^8.2.3"
62
62
  },
63
63
  "devDependencies": {
64
- "@babel/core": "^7.22.8",
65
- "@babel/preset-env": "^7.22.7",
66
- "@babel/preset-typescript": "^7.22.5",
67
- "@rollup/plugin-commonjs": "^25.0.2",
68
- "@rollup/plugin-json": "^6.0.0",
69
- "@rollup/plugin-node-resolve": "^15.1.0",
70
- "@rollup/plugin-terser": "^0.4.3",
71
- "@rollup/plugin-typescript": "^11.1.2",
72
- "@types/events": "^3.0.0",
73
- "@types/google-libphonenumber": "^7.4.23",
64
+ "@babel/core": "^7.24.4",
65
+ "@babel/preset-env": "^7.24.4",
66
+ "@babel/preset-typescript": "^7.24.1",
67
+ "@rollup/plugin-commonjs": "^25.0.7",
68
+ "@rollup/plugin-json": "^6.1.0",
69
+ "@rollup/plugin-node-resolve": "^15.2.3",
70
+ "@rollup/plugin-terser": "^0.4.4",
71
+ "@rollup/plugin-typescript": "^11.1.6",
72
+ "@types/events": "^3.0.3",
73
+ "@types/google-libphonenumber": "^7.4.30",
74
74
  "@types/jest": "^29.5.2",
75
75
  "@types/jsrsasign": "^10.5.8",
76
76
  "@types/node": "^20.4.0",
@@ -79,20 +79,23 @@
79
79
  "@typescript-eslint/parser": "^5.61.0",
80
80
  "babel-core": "^7.0.0-bridge.0",
81
81
  "babel-eslint": "10.1.0",
82
- "babel-loader": "^9.1.2",
82
+ "babel-loader": "^9.1.3",
83
83
  "eslint": "^8.44.0",
84
84
  "eslint-config-airbnb-base": "^15.0.0",
85
85
  "eslint-config-airbnb-typescript": "^17.0.0",
86
86
  "eslint-config-prettier": "^8.8.0",
87
- "eslint-plugin-import": "^2.27.5",
87
+ "eslint-plugin-import": "^2.29.1",
88
88
  "eslint-plugin-prettier": "^4.2.1",
89
89
  "jest": "^29.6.1",
90
90
  "jsonlint": "^1.6.3",
91
91
  "prettier-eslint-cli": "^7.1.0",
92
- "rimraf": "^5.0.1",
92
+ "rimraf": "^5.0.5",
93
93
  "rollup": "^3.26.2",
94
- "ts-jest": "^29.1.1",
95
- "typescript": "^5.1.6"
94
+ "ts-jest": "^29.1.2",
95
+ "typescript": "^5.4.5"
96
+ },
97
+ "resolutions": {
98
+ "underscore": "1.12.1"
96
99
  },
97
100
  "engines": {
98
101
  "node": ">=18.0.0"
@@ -87,7 +87,9 @@ client.setToken(token);
87
87
  describe('With correct API results', () => {
88
88
  beforeEach(() => {
89
89
  jest.resetModules();
90
- global.fetch = jest.fn(() => Promise.resolve(mockedJson)) as any;
90
+ Object.defineProperty(global, 'fetch', {
91
+ value: jest.fn(() => Promise.resolve(mockedJson) as any),
92
+ });
91
93
  });
92
94
 
93
95
  describe('logIn test', () => {
@@ -135,7 +137,9 @@ describe('With correct API results', () => {
135
137
  describe('With unAuthorized API results', () => {
136
138
  beforeEach(() => {
137
139
  jest.resetModules();
138
- global.fetch = jest.fn(() => Promise.resolve(mockedUnAuthorized)) as any;
140
+ Object.defineProperty(global, 'fetch', {
141
+ value: jest.fn(() => Promise.resolve(mockedUnAuthorized) as any),
142
+ });
139
143
  });
140
144
 
141
145
  describe('checkLogin test', () => {
@@ -157,7 +161,9 @@ describe('With unAuthorized API results', () => {
157
161
  describe('With not found API results', () => {
158
162
  beforeEach(() => {
159
163
  jest.resetModules();
160
- global.fetch = jest.fn(() => Promise.resolve(mockedNotFound)) as any;
164
+ Object.defineProperty(global, 'fetch', {
165
+ value: jest.fn(() => Promise.resolve(mockedNotFound) as any),
166
+ });
161
167
  });
162
168
 
163
169
  describe('fetchVoicemail test', () => {
@@ -192,7 +198,9 @@ describe('With not found API results', () => {
192
198
  describe('With erroneous text API results', () => {
193
199
  beforeEach(() => {
194
200
  jest.resetModules();
195
- global.fetch = jest.fn(() => Promise.resolve(mockedTextError)) as any;
201
+ Object.defineProperty(global, 'fetch', {
202
+ value: jest.fn(() => Promise.resolve(mockedTextError) as any),
203
+ });
196
204
  });
197
205
 
198
206
  it('throw an exception when the response is >= 500', async () => {
@@ -217,7 +225,9 @@ describe('With erroneous text API results', () => {
217
225
  describe('With erroneous json API results', () => {
218
226
  beforeEach(() => {
219
227
  jest.resetModules();
220
- global.fetch = jest.fn(() => Promise.resolve(mockedJsonError)) as any;
228
+ Object.defineProperty(global, 'fetch', {
229
+ value: jest.fn(() => Promise.resolve(mockedJsonError) as any),
230
+ });
221
231
  });
222
232
 
223
233
  it('throw an exception when the response is >= 500', async () => {
@@ -24,7 +24,11 @@ describe('IssueReporter', () => {
24
24
  });
25
25
  beforeEach(() => {
26
26
  jest.resetAllMocks();
27
- jest.spyOn(global, 'fetch');
27
+ Object.defineProperty(global, 'fetch', {
28
+ value: jest.fn(() => ({
29
+ catch: () => {},
30
+ })),
31
+ });
28
32
  });
29
33
  afterAll(() => {
30
34
  console.log = oldLog;
@@ -79,12 +79,14 @@ describe('Retrieving headers', () => {
79
79
  });
80
80
  describe('Calling fetch', () => {
81
81
  it('should call fetch without body but query string in get method', async () => {
82
- global.fetch = jest.fn(() => Promise.resolve({
83
- json: () => Promise.resolve({}),
84
- headers: {
85
- get: () => '',
86
- },
87
- })) as any;
82
+ Object.defineProperty(global, 'fetch', {
83
+ value: jest.fn(() => Promise.resolve({
84
+ json: () => Promise.resolve({}),
85
+ headers: {
86
+ get: () => '',
87
+ },
88
+ }) as any),
89
+ });
88
90
 
89
91
  await new ApiRequester({
90
92
  server,
@@ -107,17 +109,19 @@ describe('Calling fetch', () => {
107
109
  describe('With a refresh token', () => {
108
110
  it('should retry the call with a new token', async () => {
109
111
  let calls = 0;
112
+ Object.defineProperty(global, 'fetch', {
113
+ value: jest.fn(() => {
114
+ calls++;
115
+ return Promise.resolve({
116
+ headers: {
117
+ get: () => 'application/json',
118
+ },
119
+ status: calls === 1 ? 401 : 200,
120
+ json: () => Promise.resolve({}),
121
+ } as any);
122
+ }),
123
+ });
110
124
 
111
- global.fetch = jest.fn(() => {
112
- calls++;
113
- return Promise.resolve({
114
- headers: {
115
- get: () => 'application/json',
116
- },
117
- status: calls === 1 ? 401 : 200,
118
- json: () => Promise.resolve({}),
119
- });
120
- }) as any;
121
125
  const requester = new ApiRequester({
122
126
  server,
123
127
  agent: null,
@@ -565,7 +565,7 @@ export default class WebRTCClient extends Emitter {
565
565
  audioOnly,
566
566
  },
567
567
  earlyMedia: true,
568
- options,
568
+ ...options,
569
569
  };
570
570
 
571
571
  if (audioOnly) {
@@ -277,7 +277,7 @@ class WebSocketClient extends Emitter {
277
277
  return;
278
278
  }
279
279
 
280
- this.socket.close();
280
+ this.socket.close(1000);
281
281
  this.initialized = false;
282
282
 
283
283
  if (force) {