@wazo/sdk 0.41.0 → 0.41.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.
- package/dist/wazo-sdk.js +41913 -42
- package/esm/domain/Phone/WebRTCPhone.js +6 -5
- package/esm/domain/types.js +2 -1
- package/esm/index.js +1 -0
- 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/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/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/web-rtc-client.js +3 -1
- package/lib/domain/Phone/WebRTCPhone.js +6 -5
- package/lib/domain/types.js +36 -0
- package/lib/index.js +3 -0
- package/lib/simple/Auth.js +16 -2
- package/lib/simple/Configuration.js +6 -3
- package/lib/simple/Directory.js +3 -0
- package/lib/simple/Phone.js +3 -0
- 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 +1 -0
- package/lib/simple/room/Room.js +2 -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/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/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/web-rtc-client.js +3 -1
- package/package.json +1 -1
- package/src/domain/Phone/WebRTCPhone.ts +9 -8
- package/src/domain/types.ts +9 -0
- package/src/index.ts +1 -0
- 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/web-rtc-client.ts +3 -1
- package/src/websocket-client.ts +1 -1
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 {};
|
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) {
|