@wazo/sdk 0.41.0 → 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.
- package/dist/wazo-sdk.js +4 -4
- package/esm/__tests__/api-client.test.js +15 -5
- package/esm/domain/Phone/WebRTCPhone.js +6 -5
- package/esm/domain/types.js +2 -1
- package/esm/index.js +1 -0
- package/esm/service/__tests__/IssueReporter.test.js +5 -1
- package/esm/simple/Auth.js +16 -2
- package/esm/simple/Configuration.js +5 -4
- package/esm/simple/Directory.js +2 -1
- package/esm/simple/Phone.js +2 -1
- package/esm/simple/Websocket.js +2 -1
- package/esm/simple/__tests__/Auth.test.js +111 -0
- package/esm/simple/index.js +1 -0
- package/esm/simple/room/Participant.js +1 -0
- package/esm/simple/room/Room.js +2 -1
- package/esm/types/domain/Phone/WebRTCPhone.d.ts +1 -1
- package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/esm/types/domain/types.d.ts +80 -0
- package/esm/types/domain/types.d.ts.map +1 -1
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.d.ts.map +1 -1
- package/esm/types/service/getApiClient.d.ts.map +1 -1
- package/esm/types/simple/Auth.d.ts +51 -1
- package/esm/types/simple/Auth.d.ts.map +1 -1
- package/esm/types/simple/Configuration.d.ts +5 -1
- package/esm/types/simple/Configuration.d.ts.map +1 -1
- package/esm/types/simple/Directory.d.ts +5 -1
- package/esm/types/simple/Directory.d.ts.map +1 -1
- package/esm/types/simple/Phone.d.ts +117 -1
- package/esm/types/simple/Phone.d.ts.map +1 -1
- package/esm/types/simple/Websocket.d.ts +19 -1
- package/esm/types/simple/Websocket.d.ts.map +1 -1
- package/esm/types/simple/__tests__/Auth.test.d.ts +2 -0
- package/esm/types/simple/__tests__/Auth.test.d.ts.map +1 -0
- package/esm/types/simple/index.d.ts +5 -5
- package/esm/types/simple/index.d.ts.map +1 -1
- package/esm/types/simple/room/Participant.d.ts.map +1 -1
- package/esm/types/simple/room/Room.d.ts +11 -11
- package/esm/types/simple/room/Room.d.ts.map +1 -1
- package/esm/types/simple/room/SipRoom.d.ts +1 -1
- package/esm/types/utils/array.d.ts.map +1 -1
- package/esm/types/web-rtc-client.d.ts +1 -1
- package/esm/types/web-rtc-client.d.ts.map +1 -1
- package/esm/types/websocket-client.d.ts +6 -6
- package/esm/types/websocket-client.d.ts.map +1 -1
- package/esm/utils/__tests__/api-requester.test.js +19 -15
- package/esm/web-rtc-client.js +3 -1
- package/esm/websocket-client.js +1 -1
- package/lib/__tests__/api-client.test.js +15 -5
- package/lib/checker/Checker.js +2 -2
- package/lib/domain/Phone/WebRTCPhone.js +17 -16
- package/lib/domain/types.js +36 -0
- package/lib/index.js +3 -0
- package/lib/service/CallApi.js +4 -4
- package/lib/service/__tests__/IssueReporter.test.js +5 -1
- package/lib/simple/Auth.js +21 -7
- package/lib/simple/Configuration.js +6 -3
- package/lib/simple/Directory.js +3 -0
- package/lib/simple/Phone.js +12 -9
- package/lib/simple/Websocket.js +3 -0
- package/lib/simple/__tests__/Auth.test.js +145 -0
- package/lib/simple/index.js +1 -0
- package/lib/simple/room/Participant.js +3 -2
- package/lib/simple/room/Room.js +10 -9
- package/lib/simple/room/SipRoom.js +2 -2
- package/lib/simple/utils.js +1 -1
- package/lib/types/domain/Phone/WebRTCPhone.d.ts +1 -1
- package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/lib/types/domain/types.d.ts +80 -0
- package/lib/types/domain/types.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/service/getApiClient.d.ts.map +1 -1
- package/lib/types/simple/Auth.d.ts +51 -1
- package/lib/types/simple/Auth.d.ts.map +1 -1
- package/lib/types/simple/Configuration.d.ts +5 -1
- package/lib/types/simple/Configuration.d.ts.map +1 -1
- package/lib/types/simple/Directory.d.ts +5 -1
- package/lib/types/simple/Directory.d.ts.map +1 -1
- package/lib/types/simple/Phone.d.ts +117 -1
- package/lib/types/simple/Phone.d.ts.map +1 -1
- package/lib/types/simple/Websocket.d.ts +19 -1
- package/lib/types/simple/Websocket.d.ts.map +1 -1
- package/lib/types/simple/__tests__/Auth.test.d.ts +2 -0
- package/lib/types/simple/__tests__/Auth.test.d.ts.map +1 -0
- package/lib/types/simple/index.d.ts +5 -5
- package/lib/types/simple/index.d.ts.map +1 -1
- package/lib/types/simple/room/Participant.d.ts.map +1 -1
- package/lib/types/simple/room/Room.d.ts +11 -11
- package/lib/types/simple/room/Room.d.ts.map +1 -1
- package/lib/types/simple/room/SipRoom.d.ts +1 -1
- package/lib/types/utils/array.d.ts.map +1 -1
- package/lib/types/web-rtc-client.d.ts +1 -1
- package/lib/types/web-rtc-client.d.ts.map +1 -1
- package/lib/types/websocket-client.d.ts +6 -6
- package/lib/types/websocket-client.d.ts.map +1 -1
- package/lib/utils/__tests__/api-requester.test.js +19 -15
- package/lib/utils/api-requester.js +2 -2
- package/lib/web-rtc-client.js +25 -27
- package/lib/websocket-client.js +1 -1
- package/package.json +23 -20
- package/src/__tests__/api-client.test.ts +15 -5
- package/src/domain/Phone/WebRTCPhone.ts +9 -8
- package/src/domain/types.ts +9 -0
- package/src/index.ts +1 -0
- package/src/service/__tests__/IssueReporter.test.ts +5 -1
- package/src/simple/Auth.ts +25 -6
- package/src/simple/Configuration.ts +5 -4
- package/src/simple/Directory.ts +2 -1
- package/src/simple/Phone.ts +2 -1
- package/src/simple/Websocket.ts +4 -2
- package/src/simple/__tests__/Auth.test.ts +123 -0
- package/src/simple/index.ts +1 -0
- package/src/simple/room/Participant.ts +3 -1
- package/src/simple/room/Room.ts +4 -3
- package/src/types/global.d.ts +11 -5
- package/src/utils/__tests__/api-requester.test.ts +20 -16
- package/src/web-rtc-client.ts +3 -1
- package/src/websocket-client.ts +2 -2
package/src/domain/types.ts
CHANGED
|
@@ -3,6 +3,13 @@ import { SessionDescriptionHandlerFactoryOptions } from 'sip.js/lib/platform/web
|
|
|
3
3
|
import type { IncomingResponse as SipIncomingResponse } from 'sip.js/lib/core/messages/incoming-response';
|
|
4
4
|
import { Transport } from 'sip.js/lib/api';
|
|
5
5
|
import WazoSessionDescriptionHandler from '../lib/WazoSessionDescriptionHandler';
|
|
6
|
+
import { Websocket } from '../simple/Websocket';
|
|
7
|
+
import * as WebSocketClient from '../websocket-client';
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
SOCKET_EVENTS,
|
|
11
|
+
...OTHER_EVENTS
|
|
12
|
+
} = WebSocketClient;
|
|
6
13
|
|
|
7
14
|
type GenericObject = Record<string, any>;
|
|
8
15
|
|
|
@@ -312,3 +319,5 @@ export type SearchableQueryParams = QueryParams & {
|
|
|
312
319
|
export type UuidSearchableQueryParams = SearchableQueryParams & {
|
|
313
320
|
uuid?: string;
|
|
314
321
|
};
|
|
322
|
+
|
|
323
|
+
export type WebsocketType = Websocket & typeof SOCKET_EVENTS & typeof OTHER_EVENTS;
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,7 @@ export { default as WebRTCClient } from './web-rtc-client';
|
|
|
48
48
|
export { default as WazoApiClient } from './api-client';
|
|
49
49
|
export { default as Agent, AgentResponse, AgentArguments } from './domain/Agent';
|
|
50
50
|
export { default as ExternalApp } from './domain/ExternalApp';
|
|
51
|
+
export { default as SessionDescriptionHandler } from './lib/WazoSessionDescriptionHandler';
|
|
51
52
|
export * from './types/WebSocketMessage';
|
|
52
53
|
export * from './utils/PhoneNumberUtil';
|
|
53
54
|
export * from './domain/types';
|
|
@@ -24,7 +24,11 @@ describe('IssueReporter', () => {
|
|
|
24
24
|
});
|
|
25
25
|
beforeEach(() => {
|
|
26
26
|
jest.resetAllMocks();
|
|
27
|
-
|
|
27
|
+
Object.defineProperty(global, 'fetch', {
|
|
28
|
+
value: jest.fn(() => ({
|
|
29
|
+
catch: () => {},
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
28
32
|
});
|
|
29
33
|
afterAll(() => {
|
|
30
34
|
console.log = oldLog;
|
package/src/simple/Auth.ts
CHANGED
|
@@ -24,9 +24,10 @@ export class InvalidSubscription extends Error {}
|
|
|
24
24
|
export class InvalidAuthorization extends Error {}
|
|
25
25
|
export class NoTenantIdError extends Error {}
|
|
26
26
|
export class NoDomainNameError extends Error {}
|
|
27
|
+
|
|
27
28
|
const logger = IssueReporter.loggerFor('simple-auth');
|
|
28
29
|
|
|
29
|
-
class Auth {
|
|
30
|
+
export class Auth {
|
|
30
31
|
clientId: string;
|
|
31
32
|
|
|
32
33
|
expiration: number;
|
|
@@ -39,11 +40,11 @@ class Auth {
|
|
|
39
40
|
|
|
40
41
|
session: Session | null;
|
|
41
42
|
|
|
42
|
-
onRefreshTokenCallback
|
|
43
|
+
onRefreshTokenCallback?: (token: string, session: Session) => void;
|
|
43
44
|
|
|
44
|
-
onRefreshTokenCallbackError
|
|
45
|
+
onRefreshTokenCallbackError?: (error: any) => void;
|
|
45
46
|
|
|
46
|
-
onHostFromHeadersCallback
|
|
47
|
+
onHostFromHeadersCallback?: (stackHostFromHeaders: string) => void;
|
|
47
48
|
|
|
48
49
|
authenticated: boolean;
|
|
49
50
|
|
|
@@ -55,6 +56,8 @@ class Auth {
|
|
|
55
56
|
|
|
56
57
|
usingEdgeServer: boolean | undefined;
|
|
57
58
|
|
|
59
|
+
onSetUsingEdgeServer?: (usingEdgeServer: boolean) => void;
|
|
60
|
+
|
|
58
61
|
constructor() {
|
|
59
62
|
this.expiration = DETAULT_EXPIRATION;
|
|
60
63
|
this.authenticated = false;
|
|
@@ -162,11 +165,16 @@ class Auth {
|
|
|
162
165
|
return this._onAuthenticated(rawSession as Session);
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
async validateToken(token: string, refreshToken
|
|
168
|
+
async validateToken(token: string, refreshToken?: string, headerUserUuid?: string): Promise<Session | undefined | null> {
|
|
166
169
|
if (!token) {
|
|
167
170
|
return;
|
|
168
171
|
}
|
|
169
172
|
|
|
173
|
+
if (this.usingEdgeServer && typeof headerUserUuid === 'string') {
|
|
174
|
+
logger.info('using edge server, setting user UUID header', { headerUserUuid });
|
|
175
|
+
this.setHttpUserUuidHeader(headerUserUuid);
|
|
176
|
+
}
|
|
177
|
+
|
|
170
178
|
if (refreshToken) {
|
|
171
179
|
setRefreshToken(refreshToken);
|
|
172
180
|
}
|
|
@@ -212,10 +220,15 @@ class Auth {
|
|
|
212
220
|
setFetchOptions({});
|
|
213
221
|
}
|
|
214
222
|
|
|
215
|
-
setOnHostFromHeaders(callback: (
|
|
223
|
+
setOnHostFromHeaders(callback: (hostFromHeaders: string) => void) {
|
|
216
224
|
this.onHostFromHeadersCallback = callback;
|
|
217
225
|
}
|
|
218
226
|
|
|
227
|
+
setOnSetUsingEdgeServer(callback: (usingEdgeServer: boolean) => void) {
|
|
228
|
+
logger.info('setting onSetUsingEdgeServer callback', { callback: typeof callback === 'function' });
|
|
229
|
+
this.onSetUsingEdgeServer = callback;
|
|
230
|
+
}
|
|
231
|
+
|
|
219
232
|
setOnRefreshToken(callback: (...args: Array<any>) => any) {
|
|
220
233
|
this.onRefreshTokenCallback = callback;
|
|
221
234
|
}
|
|
@@ -366,6 +379,11 @@ class Auth {
|
|
|
366
379
|
this.usingEdgeServer = false;
|
|
367
380
|
logger.info('Setting usingEdgeServer to FALSE', { justification: e });
|
|
368
381
|
}
|
|
382
|
+
|
|
383
|
+
if (typeof this.onSetUsingEdgeServer === 'function') {
|
|
384
|
+
logger.info('calling onSetUsingEdgeServer', { usingEdgeServer: this.usingEdgeServer });
|
|
385
|
+
this.onSetUsingEdgeServer(this.usingEdgeServer);
|
|
386
|
+
}
|
|
369
387
|
}
|
|
370
388
|
|
|
371
389
|
async _onAuthenticated(rawSession: Session): Promise<Session | null> {
|
|
@@ -437,4 +455,5 @@ if (!global.wazoAuthInstance) {
|
|
|
437
455
|
global.wazoAuthInstance = new Auth();
|
|
438
456
|
}
|
|
439
457
|
|
|
458
|
+
// @ts-ignore: Circular definition of import alias 'default'.
|
|
440
459
|
export default global.wazoAuthInstance;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Wazo from '.';
|
|
2
2
|
import getApiClient from '../service/getApiClient';
|
|
3
3
|
import Profile from '../domain/Profile';
|
|
4
4
|
|
|
5
|
-
class Configuration {
|
|
5
|
+
export class Configuration {
|
|
6
6
|
async getCurrentUser(): Promise<Profile> {
|
|
7
|
-
const session = Auth.getSession();
|
|
8
|
-
return getApiClient().confd.getUser(session ? session.uuid : '');
|
|
7
|
+
const session = Wazo.Auth.getSession();
|
|
8
|
+
return getApiClient().confd.getUser(`${session ? session.uuid : ''}`);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
}
|
|
@@ -14,4 +14,5 @@ if (!global.wazoConfigurationInstance) {
|
|
|
14
14
|
global.wazoConfigurationInstance = new Configuration();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// @ts-ignore: Circular definition of import alias 'default'.
|
|
17
18
|
export default global.wazoConfigurationInstance;
|
package/src/simple/Directory.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Contact from '../domain/Contact';
|
|
2
2
|
import getApiClient from '../service/getApiClient';
|
|
3
3
|
|
|
4
|
-
class Directory {
|
|
4
|
+
export class Directory {
|
|
5
5
|
async findMultipleContactsByNumber(numbers: string[], fields?: Record<string, any>): Promise<Contact[]> {
|
|
6
6
|
return getApiClient().dird.findMultipleContactsByNumber(numbers, fields);
|
|
7
7
|
}
|
|
@@ -12,4 +12,5 @@ if (!global.wazoDirectoryInstance) {
|
|
|
12
12
|
global.wazoDirectoryInstance = new Directory();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// @ts-ignore: Circular definition of import alias 'default'.
|
|
15
16
|
export default global.wazoDirectoryInstance;
|
package/src/simple/Phone.ts
CHANGED
|
@@ -18,7 +18,7 @@ const sipLogger = IssueReporter.loggerFor('sip.js');
|
|
|
18
18
|
const protocolLogger = IssueReporter.loggerFor('sip');
|
|
19
19
|
const protocolDebugMessages = ['Received WebSocket text message:', 'Sending WebSocket message:'];
|
|
20
20
|
|
|
21
|
-
class Phone extends Emitter {
|
|
21
|
+
export class Phone extends Emitter {
|
|
22
22
|
client: WazoWebRTCClient;
|
|
23
23
|
|
|
24
24
|
phone: WebRTCPhone | null | undefined;
|
|
@@ -527,4 +527,5 @@ if (!global.wazoTelephonyInstance) {
|
|
|
527
527
|
global.wazoTelephonyInstance = new Phone();
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
+
// @ts-ignore: Circular definition of import alias 'default'.
|
|
530
531
|
export default global.wazoTelephonyInstance;
|
package/src/simple/Websocket.ts
CHANGED
|
@@ -3,6 +3,7 @@ import WazoWebSocketClient, * as WebSocketClient from '../websocket-client';
|
|
|
3
3
|
import Emitter from '../utils/Emitter';
|
|
4
4
|
import IssueReporter from '../service/IssueReporter';
|
|
5
5
|
import { obfuscateToken } from '../utils/string';
|
|
6
|
+
import { WebsocketType } from '../domain/types';
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
SOCKET_EVENTS,
|
|
@@ -11,7 +12,7 @@ const {
|
|
|
11
12
|
const ALL_EVENTS = [...Object.values(SOCKET_EVENTS), ...Object.values(OTHER_EVENTS)];
|
|
12
13
|
const logger = IssueReporter.loggerFor('simple-ws-client');
|
|
13
14
|
|
|
14
|
-
class Websocket extends Emitter {
|
|
15
|
+
export class Websocket extends Emitter {
|
|
15
16
|
ws: WazoWebSocketClient | null | undefined;
|
|
16
17
|
|
|
17
18
|
eventLists: string[];
|
|
@@ -99,7 +100,8 @@ class Websocket extends Emitter {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
if (!global.wazoWebsocketInstance) {
|
|
102
|
-
global.wazoWebsocketInstance = new Websocket();
|
|
103
|
+
global.wazoWebsocketInstance = new Websocket() as WebsocketType;
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
// @ts-ignore: Circular definition of import alias 'default'.
|
|
105
107
|
export default global.wazoWebsocketInstance;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import getApiClient, { setRefreshToken } from '../../service/getApiClient';
|
|
2
|
+
import { Auth as AuthClass } from '../Auth';
|
|
3
|
+
|
|
4
|
+
const Auth = new AuthClass();
|
|
5
|
+
const TOKEN = 'some-token';
|
|
6
|
+
const REFRESH_TOKEN = 'some-refresh-token';
|
|
7
|
+
const USER_UUID = 'some-user-uuid';
|
|
8
|
+
|
|
9
|
+
jest.mock('../../service/getApiClient');
|
|
10
|
+
|
|
11
|
+
describe('simple/Auth', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
const authenticate = jest.fn();
|
|
14
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
15
|
+
auth: {
|
|
16
|
+
authenticate,
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.restoreAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('validateToken', () => {
|
|
26
|
+
it('should return undefined if nullish', async () => {
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
const result = await Auth.validateToken(null);
|
|
29
|
+
expect(result).toEqual(undefined);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should set refresh token if provided', async () => {
|
|
33
|
+
await Auth.validateToken(TOKEN, REFRESH_TOKEN);
|
|
34
|
+
expect(setRefreshToken).toHaveBeenCalledWith(REFRESH_TOKEN);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should set user uuid header when using edge server', async () => {
|
|
38
|
+
Auth.usingEdgeServer = true;
|
|
39
|
+
const setHttpUserUuidHeader = jest.spyOn(Auth, 'setHttpUserUuidHeader');
|
|
40
|
+
await Auth.validateToken(TOKEN, undefined, USER_UUID);
|
|
41
|
+
expect(setHttpUserUuidHeader).toHaveBeenCalledWith(USER_UUID);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should NOT set user uuid header when NOT using edge server', async () => {
|
|
45
|
+
Auth.usingEdgeServer = false;
|
|
46
|
+
const setHttpUserUuidHeader = jest.spyOn(Auth, 'setHttpUserUuidHeader');
|
|
47
|
+
await Auth.validateToken(TOKEN, undefined, USER_UUID);
|
|
48
|
+
expect(setHttpUserUuidHeader).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('checkHttpUserUuidHeader', () => {
|
|
52
|
+
it('should return undefined if UUID is null', async () => {
|
|
53
|
+
const result = await Auth.checkHttpUserUuidHeader(null);
|
|
54
|
+
expect(result).toEqual(undefined);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should set user UUID header on successful HEAD call', async () => {
|
|
58
|
+
const head = jest.fn(() => Promise.resolve({ headers: { get: () => null } }));
|
|
59
|
+
const setHttpUserUuidHeader = jest.spyOn(Auth, 'setHttpUserUuidHeader');
|
|
60
|
+
Auth.onSetUsingEdgeServer = jest.fn();
|
|
61
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
62
|
+
client: {
|
|
63
|
+
head,
|
|
64
|
+
},
|
|
65
|
+
}));
|
|
66
|
+
await Auth.checkHttpUserUuidHeader(USER_UUID);
|
|
67
|
+
expect(head).toHaveBeenCalled();
|
|
68
|
+
expect(setHttpUserUuidHeader).toHaveBeenCalledWith(USER_UUID);
|
|
69
|
+
expect(Auth.usingEdgeServer).toEqual(true);
|
|
70
|
+
expect(Auth.onSetUsingEdgeServer).toHaveBeenCalledWith(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should NOT set user UUID header on failed HEAD call', async () => {
|
|
74
|
+
const head = jest.fn(() => Promise.reject());
|
|
75
|
+
const setHttpUserUuidHeader = jest.spyOn(Auth, 'setHttpUserUuidHeader');
|
|
76
|
+
Auth.onSetUsingEdgeServer = jest.fn();
|
|
77
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
78
|
+
client: {
|
|
79
|
+
head,
|
|
80
|
+
},
|
|
81
|
+
}));
|
|
82
|
+
await Auth.checkHttpUserUuidHeader(USER_UUID);
|
|
83
|
+
expect(head).toHaveBeenCalled();
|
|
84
|
+
expect(setHttpUserUuidHeader).not.toHaveBeenCalled();
|
|
85
|
+
expect(Auth.usingEdgeServer).toEqual(false);
|
|
86
|
+
expect(Auth.onSetUsingEdgeServer).toHaveBeenCalledWith(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should set user UUID header on mobile when header is present', async () => {
|
|
90
|
+
Auth.mobile = true;
|
|
91
|
+
const head = jest.fn(() => Promise.resolve({ headers: { get: () => 'X-User-UUID: something' } }));
|
|
92
|
+
const setHttpUserUuidHeader = jest.spyOn(Auth, 'setHttpUserUuidHeader');
|
|
93
|
+
Auth.onSetUsingEdgeServer = jest.fn();
|
|
94
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
95
|
+
client: {
|
|
96
|
+
head,
|
|
97
|
+
},
|
|
98
|
+
}));
|
|
99
|
+
await Auth.checkHttpUserUuidHeader(USER_UUID);
|
|
100
|
+
expect(head).toHaveBeenCalled();
|
|
101
|
+
expect(setHttpUserUuidHeader).toHaveBeenCalledWith(USER_UUID);
|
|
102
|
+
expect(Auth.usingEdgeServer).toEqual(true);
|
|
103
|
+
expect(Auth.onSetUsingEdgeServer).toHaveBeenCalledWith(true);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should NOT set user UUID header on mobile when header is NOT present', async () => {
|
|
107
|
+
Auth.mobile = true;
|
|
108
|
+
const head = jest.fn(() => Promise.resolve({ headers: { get: () => 'something' } }));
|
|
109
|
+
const setHttpUserUuidHeader = jest.spyOn(Auth, 'setHttpUserUuidHeader');
|
|
110
|
+
Auth.onSetUsingEdgeServer = jest.fn();
|
|
111
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
112
|
+
client: {
|
|
113
|
+
head,
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
116
|
+
await Auth.checkHttpUserUuidHeader(USER_UUID);
|
|
117
|
+
expect(head).toHaveBeenCalled();
|
|
118
|
+
expect(setHttpUserUuidHeader).not.toHaveBeenCalled();
|
|
119
|
+
expect(Auth.usingEdgeServer).toEqual(false);
|
|
120
|
+
expect(Auth.onSetUsingEdgeServer).toHaveBeenCalledWith(false);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
package/src/simple/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Emitter from '../../utils/Emitter';
|
|
2
2
|
import IssueReporter from '../../service/IssueReporter';
|
|
3
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
3
4
|
import Phone from '../Phone';
|
|
4
5
|
import Room, { SIGNAL_TYPE_PARTICIPANT_UPDATE } from './Room';
|
|
5
6
|
import Contact from '../../domain/Contact';
|
|
6
7
|
import getApiClient from '../../service/getApiClient';
|
|
7
8
|
import Stream from './Stream';
|
|
9
|
+
import type CallSession from '../../domain/CallSession';
|
|
8
10
|
|
|
9
11
|
const logger = IssueReporter.loggerFor('room');
|
|
10
12
|
|
|
@@ -362,7 +364,7 @@ class Participant extends Emitter {
|
|
|
362
364
|
|
|
363
365
|
if (sendReinvite && !this.streams.length && Phone.phone) {
|
|
364
366
|
// eslint-disable-next-line no-underscore-dangle
|
|
365
|
-
Phone.phone._sendReinviteMessage(this.room?.callSession, false);
|
|
367
|
+
Phone.phone._sendReinviteMessage(this.room?.callSession as CallSession, false);
|
|
366
368
|
}
|
|
367
369
|
|
|
368
370
|
this.room?.sendSignal({
|
package/src/simple/room/Room.ts
CHANGED
|
@@ -25,7 +25,7 @@ type ConnectArgs = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
class Room extends Emitter {
|
|
28
|
-
callSession
|
|
28
|
+
callSession?: CallSession;
|
|
29
29
|
|
|
30
30
|
name: string;
|
|
31
31
|
|
|
@@ -189,6 +189,7 @@ class Room extends Emitter {
|
|
|
189
189
|
|
|
190
190
|
if (!room) {
|
|
191
191
|
await Wazo.Phone.connect({
|
|
192
|
+
// @ts-ignore: Property 'audio' is missing
|
|
192
193
|
media: constraints,
|
|
193
194
|
});
|
|
194
195
|
const withCamera = constraints && !!constraints.video;
|
|
@@ -260,7 +261,7 @@ class Room extends Emitter {
|
|
|
260
261
|
async disconnect() {
|
|
261
262
|
logger.info('disconnection to room called');
|
|
262
263
|
await Wazo.Phone.hangup(this.callSession as CallSession);
|
|
263
|
-
this.callSession =
|
|
264
|
+
this.callSession = undefined;
|
|
264
265
|
this.eventEmitter.emit(this.ON_DISCONNECTED, this);
|
|
265
266
|
this.connected = false;
|
|
266
267
|
this.unbind();
|
|
@@ -497,7 +498,7 @@ class Room extends Emitter {
|
|
|
497
498
|
|
|
498
499
|
if (!this.roomAudioElement) {
|
|
499
500
|
const sessionId = Wazo.Phone.phone?.getSipSessionId(Wazo.Phone.phone?.currentSipSession as WazoSession);
|
|
500
|
-
this.roomAudioElement = Wazo.Phone.phone?.createAudioElementFor(sessionId as string);
|
|
501
|
+
this.roomAudioElement = Wazo.Phone.phone?.createAudioElementFor(sessionId as string) as HTMLAudioElement;
|
|
501
502
|
this.roomAudioElement.srcObject = stream;
|
|
502
503
|
} else {
|
|
503
504
|
this.roomAudioElement.srcObject = stream;
|
package/src/types/global.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/* eslint-disable vars-on-top */
|
|
2
2
|
/* eslint-disable no-var */
|
|
3
3
|
|
|
4
|
+
import { WebsocketType } from '../domain/types';
|
|
5
|
+
import { Auth } from '../simple/Auth';
|
|
6
|
+
import { Configuration } from '../simple/Configuration';
|
|
7
|
+
import { Directory } from '../simple/Directory';
|
|
8
|
+
import { Phone } from '../simple/Phone';
|
|
9
|
+
|
|
4
10
|
declare global {
|
|
5
11
|
var Wazo;
|
|
6
12
|
var wazoClients;
|
|
@@ -17,11 +23,11 @@ declare global {
|
|
|
17
23
|
var wazoRequestApiTimeout;
|
|
18
24
|
var wazoFetchOptions;
|
|
19
25
|
var wazoCurrentServer;
|
|
20
|
-
var wazoAuthInstance;
|
|
21
|
-
var wazoConfigurationInstance;
|
|
22
|
-
var wazoDirectoryInstance;
|
|
23
|
-
var wazoTelephonyInstance;
|
|
24
|
-
var wazoWebsocketInstance;
|
|
26
|
+
var wazoAuthInstance: Auth;
|
|
27
|
+
var wazoConfigurationInstance: Configuration;
|
|
28
|
+
var wazoDirectoryInstance: Directory;
|
|
29
|
+
var wazoTelephonyInstance: Phone;
|
|
30
|
+
var wazoWebsocketInstance: WebsocketType;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
export {};
|
|
@@ -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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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,
|
package/src/web-rtc-client.ts
CHANGED
|
@@ -550,13 +550,14 @@ export default class WebRTCClient extends Emitter {
|
|
|
550
550
|
});
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
call(number: string, enableVideo?: boolean, audioOnly = false, conference = false): WazoSession | null {
|
|
553
|
+
call(number: string, enableVideo?: boolean, audioOnly = false, conference = false, options = {}): WazoSession | null {
|
|
554
554
|
logger.info('sdk webrtc creating call', {
|
|
555
555
|
clientId: this.clientId,
|
|
556
556
|
number,
|
|
557
557
|
enableVideo,
|
|
558
558
|
audioOnly,
|
|
559
559
|
conference,
|
|
560
|
+
options,
|
|
560
561
|
});
|
|
561
562
|
const inviterOptions: Record<string, any> = {
|
|
562
563
|
sessionDescriptionHandlerOptionsReInvite: {
|
|
@@ -564,6 +565,7 @@ export default class WebRTCClient extends Emitter {
|
|
|
564
565
|
audioOnly,
|
|
565
566
|
},
|
|
566
567
|
earlyMedia: true,
|
|
568
|
+
...options,
|
|
567
569
|
};
|
|
568
570
|
|
|
569
571
|
if (audioOnly) {
|
package/src/websocket-client.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const SOCKET_EVENTS = {
|
|
|
15
15
|
ON_CLOSE: 'onclose',
|
|
16
16
|
INITIALIZED: 'initialized',
|
|
17
17
|
ON_AUTH_FAILED: 'on_auth_failed',
|
|
18
|
-
};
|
|
18
|
+
} as const;
|
|
19
19
|
type Arguments = {
|
|
20
20
|
host: string;
|
|
21
21
|
token: string;
|
|
@@ -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) {
|