@wazo/sdk 1.0.0-alpha.2 → 1.0.0-alpha.20
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/README.md +16 -7
- package/dist/wazo-sdk.js +2 -2
- package/esm/__tests__/__voice__/call.test.js +52 -3
- package/esm/api/auth.js +3 -0
- package/esm/checker/checks/webrtc.js +2 -2
- package/esm/domain/CallLog.js +2 -3
- package/esm/domain/Phone/CTIPhone.js +2 -2
- package/esm/domain/Phone/WebRTCPhone.js +59 -57
- package/esm/index.js +3 -1
- package/esm/service/CallApi.js +4 -4
- package/esm/simple/Auth.js +13 -3
- package/esm/simple/Phone.js +5 -5
- package/esm/simple/index.js +2 -1
- package/esm/simple/room/Room.js +2 -2
- package/esm/simple/room/SipRoom.js +2 -2
- package/esm/state-machine/call-state-machine.js +34 -19
- package/esm/state-machine/softphone-state-machine.js +1 -2
- package/esm/state-machine/utils.js +10 -4
- package/esm/types/api/auth.d.ts +3 -0
- package/esm/types/api/auth.d.ts.map +1 -1
- package/esm/types/checker/checks/index.d.ts +1 -1
- package/esm/types/checker/checks/webrtc-transport.d.ts +2 -2
- package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -1
- package/esm/types/domain/CallLog.d.ts.map +1 -1
- package/esm/types/domain/CallSession.d.ts +3 -3
- package/esm/types/domain/CallSession.d.ts.map +1 -1
- package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
- package/esm/types/domain/Phone/WebRTCPhone.d.ts +22 -22
- package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/esm/types/domain/types.d.ts +0 -4
- package/esm/types/domain/types.d.ts.map +1 -1
- package/esm/types/index.d.ts +3 -1
- package/esm/types/index.d.ts.map +1 -1
- package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +3 -3
- package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
- package/esm/types/service/CallApi.d.ts +5 -5
- package/esm/types/service/CallApi.d.ts.map +1 -1
- package/esm/types/simple/Auth.d.ts +6 -1
- package/esm/types/simple/Auth.d.ts.map +1 -1
- package/esm/types/simple/Phone.d.ts +8 -8
- package/esm/types/simple/Phone.d.ts.map +1 -1
- package/esm/types/simple/index.d.ts +3 -1
- package/esm/types/simple/index.d.ts.map +1 -1
- package/esm/types/state-machine/call-state-machine.d.ts +12 -1
- package/esm/types/state-machine/call-state-machine.d.ts.map +1 -1
- package/esm/types/state-machine/softphone-state-machine.d.ts +1 -2
- package/esm/types/state-machine/softphone-state-machine.d.ts.map +1 -1
- package/esm/types/state-machine/utils.d.ts +1 -1
- package/esm/types/state-machine/utils.d.ts.map +1 -1
- package/esm/types/utils/sdp.d.ts +1 -2
- package/esm/types/utils/sdp.d.ts.map +1 -1
- package/esm/types/utils/update-from.d.ts +1 -1
- package/esm/types/utils/update-from.d.ts.map +1 -1
- package/esm/types/utils/webrtc.d.ts.map +1 -1
- package/esm/types/voice/call.d.ts +15 -3
- package/esm/types/voice/call.d.ts.map +1 -1
- package/esm/types/voice/softphone.d.ts +7 -0
- package/esm/types/voice/softphone.d.ts.map +1 -1
- package/esm/types/web-rtc-client.d.ts +39 -38
- package/esm/types/web-rtc-client.d.ts.map +1 -1
- package/esm/utils/sdp.js +16 -9
- package/esm/utils/update-from.js +2 -2
- package/esm/utils/webrtc.js +10 -4
- package/esm/voice/call.js +86 -28
- package/esm/voice/softphone.js +58 -17
- package/esm/web-rtc-client.js +67 -58
- package/lib/__tests__/__voice__/call.test.js +51 -2
- package/lib/api/auth.js +3 -0
- package/lib/checker/checks/webrtc.js +1 -1
- package/lib/domain/CallLog.js +2 -3
- package/lib/domain/Phone/CTIPhone.js +2 -2
- package/lib/domain/Phone/WebRTCPhone.js +58 -56
- package/lib/index.js +7 -3
- package/lib/service/CallApi.js +2 -2
- package/lib/simple/Auth.js +15 -3
- package/lib/simple/Phone.js +2 -2
- package/lib/simple/index.js +2 -1
- package/lib/simple/room/Room.js +1 -1
- package/lib/simple/room/SipRoom.js +1 -1
- package/lib/state-machine/call-state-machine.js +35 -20
- package/lib/state-machine/softphone-state-machine.js +1 -2
- package/lib/state-machine/utils.js +10 -4
- package/lib/types/api/auth.d.ts +3 -0
- package/lib/types/api/auth.d.ts.map +1 -1
- package/lib/types/checker/checks/index.d.ts +1 -1
- package/lib/types/checker/checks/webrtc-transport.d.ts +2 -2
- package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -1
- package/lib/types/domain/CallLog.d.ts.map +1 -1
- package/lib/types/domain/CallSession.d.ts +3 -3
- package/lib/types/domain/CallSession.d.ts.map +1 -1
- package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
- package/lib/types/domain/Phone/WebRTCPhone.d.ts +22 -22
- package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
- package/lib/types/domain/types.d.ts +0 -4
- package/lib/types/domain/types.d.ts.map +1 -1
- package/lib/types/index.d.ts +3 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +3 -3
- package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
- package/lib/types/service/CallApi.d.ts +5 -5
- package/lib/types/service/CallApi.d.ts.map +1 -1
- package/lib/types/simple/Auth.d.ts +6 -1
- package/lib/types/simple/Auth.d.ts.map +1 -1
- package/lib/types/simple/Phone.d.ts +8 -8
- package/lib/types/simple/Phone.d.ts.map +1 -1
- package/lib/types/simple/index.d.ts +3 -1
- package/lib/types/simple/index.d.ts.map +1 -1
- package/lib/types/state-machine/call-state-machine.d.ts +12 -1
- package/lib/types/state-machine/call-state-machine.d.ts.map +1 -1
- package/lib/types/state-machine/softphone-state-machine.d.ts +1 -2
- package/lib/types/state-machine/softphone-state-machine.d.ts.map +1 -1
- package/lib/types/state-machine/utils.d.ts +1 -1
- package/lib/types/state-machine/utils.d.ts.map +1 -1
- package/lib/types/utils/sdp.d.ts +1 -2
- package/lib/types/utils/sdp.d.ts.map +1 -1
- package/lib/types/utils/update-from.d.ts +1 -1
- package/lib/types/utils/update-from.d.ts.map +1 -1
- package/lib/types/utils/webrtc.d.ts.map +1 -1
- package/lib/types/voice/call.d.ts +15 -3
- package/lib/types/voice/call.d.ts.map +1 -1
- package/lib/types/voice/softphone.d.ts +7 -0
- package/lib/types/voice/softphone.d.ts.map +1 -1
- package/lib/types/web-rtc-client.d.ts +39 -38
- package/lib/types/web-rtc-client.d.ts.map +1 -1
- package/lib/utils/sdp.js +17 -10
- package/lib/utils/update-from.js +2 -2
- package/lib/utils/webrtc.js +11 -4
- package/lib/voice/call.js +89 -27
- package/lib/voice/softphone.js +62 -17
- package/lib/web-rtc-client.js +66 -57
- package/package.json +1 -1
- package/src/__tests__/__voice__/call.test.ts +61 -3
- package/src/api/auth.ts +5 -0
- package/src/checker/checks/webrtc-transport.ts +2 -2
- package/src/checker/checks/webrtc.ts +2 -2
- package/src/domain/CallLog.ts +2 -3
- package/src/domain/CallSession.ts +3 -3
- package/src/domain/Phone/CTIPhone.ts +3 -2
- package/src/domain/Phone/WebRTCPhone.ts +87 -85
- package/src/domain/__tests__/CallSession.test.ts +4 -0
- package/src/domain/types.ts +0 -5
- package/src/index.ts +4 -1
- package/src/lib/WazoSessionDescriptionHandler.ts +3 -3
- package/src/service/CallApi.ts +7 -7
- package/src/simple/Auth.ts +15 -3
- package/src/simple/Phone.ts +11 -11
- package/src/simple/index.ts +2 -1
- package/src/simple/room/Room.ts +3 -3
- package/src/simple/room/SipRoom.ts +3 -3
- package/src/state-machine/call-state-machine.ts +38 -19
- package/src/state-machine/softphone-state-machine.ts +1 -2
- package/src/state-machine/utils.ts +12 -4
- package/src/utils/sdp.ts +18 -11
- package/src/utils/update-from.ts +2 -2
- package/src/utils/webrtc.ts +11 -4
- package/src/voice/call.ts +109 -36
- package/src/voice/softphone.ts +75 -18
- package/src/web-rtc-client.ts +112 -98
package/esm/voice/softphone.js
CHANGED
|
@@ -9,6 +9,7 @@ import IssueReporter from '../service/IssueReporter';
|
|
|
9
9
|
import configureLogger from '../utils/sip-logger';
|
|
10
10
|
import Call from './call';
|
|
11
11
|
import { assertCan, can, getState, waitUntilState } from '../state-machine/utils';
|
|
12
|
+
import { getSipCallId } from '../utils/sdp';
|
|
12
13
|
export const EVENT_INCOMING = 'incoming';
|
|
13
14
|
export const EVENT_OUTGOING = 'outgoing';
|
|
14
15
|
export const EVENT_HEARTBEAT = 'heartbeat';
|
|
@@ -53,6 +54,7 @@ export class Softphone extends EventEmitter {
|
|
|
53
54
|
this.audioRingVolume = 1;
|
|
54
55
|
const server = Wazo.Auth.getHost();
|
|
55
56
|
const session = Wazo.Auth.getSession();
|
|
57
|
+
logger.info('softphone - connect', { server, session: !!session });
|
|
56
58
|
if (!server || !session) {
|
|
57
59
|
throw new Error('Please connect to the server using `Wazo.Auth.logIn` or `Wazo.Auth.authenticate` before using Room.connect().');
|
|
58
60
|
}
|
|
@@ -64,21 +66,28 @@ export class Softphone extends EventEmitter {
|
|
|
64
66
|
this.options.userUuid = session.uuid || '';
|
|
65
67
|
return this.connectWithCredentials(server, this.sipLine, session.displayName(), options);
|
|
66
68
|
}
|
|
69
|
+
async hangupAllCalls() {
|
|
70
|
+
return Promise.all(this.calls.map(call => call.hangup()));
|
|
71
|
+
}
|
|
67
72
|
async disconnect() {
|
|
68
73
|
assertCan(this.softphoneActor, Actions.UNREGISTER);
|
|
74
|
+
logger.info('softphone - disconnect');
|
|
69
75
|
if (!this.client) {
|
|
76
|
+
logger.info('softphone - disconnect, not client to disconnect, bailing');
|
|
70
77
|
return null;
|
|
71
78
|
}
|
|
72
79
|
// Terminate all calls
|
|
73
|
-
await
|
|
74
|
-
|
|
80
|
+
await this.hangupAllCalls();
|
|
81
|
+
await this.client.unregister();
|
|
82
|
+
return this.client.close();
|
|
75
83
|
}
|
|
76
84
|
getPrimaryWebRtcLine() {
|
|
77
85
|
return this.session?.primaryWebRtcLine() || null;
|
|
78
86
|
}
|
|
79
87
|
async connectWithCredentials(server, sipLine, displayName, rawOptions = {}) {
|
|
80
88
|
assertCan(this.softphoneActor, Actions.REGISTER);
|
|
81
|
-
|
|
89
|
+
logger.info('softphone - connect with credentials', { server, username: sipLine.username, displayName, options: rawOptions });
|
|
90
|
+
this._sendAction(Actions.REGISTER);
|
|
82
91
|
const [host, port = 443] = server.split(':');
|
|
83
92
|
let options = { ...rawOptions };
|
|
84
93
|
options.media = options.media || {
|
|
@@ -110,7 +119,7 @@ export class Softphone extends EventEmitter {
|
|
|
110
119
|
if (!this.client) {
|
|
111
120
|
return;
|
|
112
121
|
}
|
|
113
|
-
this.client.
|
|
122
|
+
this.client.register();
|
|
114
123
|
}
|
|
115
124
|
async call(options) {
|
|
116
125
|
logger.info('softphone - call', options);
|
|
@@ -122,7 +131,7 @@ export class Softphone extends EventEmitter {
|
|
|
122
131
|
logger.info('softphone - calling when registering, waiting for Softphone to be registered ...');
|
|
123
132
|
await waitUntilState(this.softphoneActor, States.REGISTERED);
|
|
124
133
|
}
|
|
125
|
-
if (this.state !== States.
|
|
134
|
+
if (this.state !== States.REGISTERED) {
|
|
126
135
|
throw new InvalidState(`Invalid state ${States.UNREGISTERED}`, States.UNREGISTERED);
|
|
127
136
|
}
|
|
128
137
|
// Hold other calls
|
|
@@ -131,6 +140,8 @@ export class Softphone extends EventEmitter {
|
|
|
131
140
|
try {
|
|
132
141
|
sipCall = this.client.call(options.params.To, options.withCamera, options.audioOnly, options.conference, options);
|
|
133
142
|
const call = new Call(sipCall, this);
|
|
143
|
+
call.onMakeCall();
|
|
144
|
+
this.calls.push(call);
|
|
134
145
|
this.emit(EVENT_OUTGOING, call);
|
|
135
146
|
return call;
|
|
136
147
|
}
|
|
@@ -195,10 +206,11 @@ export class Softphone extends EventEmitter {
|
|
|
195
206
|
this.ringingEnabled = false;
|
|
196
207
|
}
|
|
197
208
|
holdAllCalls(exceptCall = null) {
|
|
198
|
-
|
|
209
|
+
logger.info('softphone - hold all calls', { exceptId: exceptCall?.id, ids: this.calls.map(call => call.id) });
|
|
210
|
+
this.calls.filter(call => !call.isHeld() && call.id !== exceptCall?.id).forEach(call => call.hold());
|
|
199
211
|
}
|
|
200
212
|
startHeartbeat() {
|
|
201
|
-
logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: this.client
|
|
213
|
+
logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: this.client?.hasHeartbeat() });
|
|
202
214
|
if (!this.client || this.client.hasHeartbeat()) {
|
|
203
215
|
return;
|
|
204
216
|
}
|
|
@@ -248,7 +260,10 @@ export class Softphone extends EventEmitter {
|
|
|
248
260
|
this.audioRingVolume = volume;
|
|
249
261
|
}
|
|
250
262
|
getCurrentCall() {
|
|
251
|
-
return this.
|
|
263
|
+
return this.getActiveCalls()[0];
|
|
264
|
+
}
|
|
265
|
+
getActiveCalls() {
|
|
266
|
+
return this.calls.filter(call => call.isEstablished());
|
|
252
267
|
}
|
|
253
268
|
getIncomingCalls() {
|
|
254
269
|
return this.calls.filter(call => call.isRinging());
|
|
@@ -256,12 +271,21 @@ export class Softphone extends EventEmitter {
|
|
|
256
271
|
get state() {
|
|
257
272
|
return getState(this.softphoneActor);
|
|
258
273
|
}
|
|
274
|
+
get user() {
|
|
275
|
+
return this.client?.userAgent?.contact?.uri?.user;
|
|
276
|
+
}
|
|
259
277
|
getUserAgent() {
|
|
260
278
|
return this.client?.config?.userAgentString || 'softphone';
|
|
261
279
|
}
|
|
280
|
+
isRegistering() {
|
|
281
|
+
return this.state === States.REGISTERING;
|
|
282
|
+
}
|
|
262
283
|
isRegistered() {
|
|
263
284
|
return this.state === States.REGISTERED;
|
|
264
285
|
}
|
|
286
|
+
isUnRegistered() {
|
|
287
|
+
return this.state === States.UNREGISTERED;
|
|
288
|
+
}
|
|
265
289
|
_bindEvents() {
|
|
266
290
|
this.client.on(this.client.INVITE, (sipSession) => {
|
|
267
291
|
const call = new Call(sipSession, this);
|
|
@@ -280,7 +304,7 @@ export class Softphone extends EventEmitter {
|
|
|
280
304
|
});
|
|
281
305
|
this.client.on(this.client.ON_REINVITE, (sipCall, request, updatedCalleeName, updatedNumber, hadRemoteVideo) => {
|
|
282
306
|
logger.info('softphone - on reinvite', {
|
|
283
|
-
callId: sipCall
|
|
307
|
+
callId: getSipCallId(sipCall),
|
|
284
308
|
inviteId: request.callId,
|
|
285
309
|
updatedCalleeName,
|
|
286
310
|
updatedNumber,
|
|
@@ -320,18 +344,26 @@ export class Softphone extends EventEmitter {
|
|
|
320
344
|
});
|
|
321
345
|
this.client.on(this.client.UNREGISTERED, () => {
|
|
322
346
|
logger.info('softphone - unregistered');
|
|
347
|
+
if (!can(this.softphoneActor, Actions.UNREGISTER)) {
|
|
348
|
+
logger.warn('softphone - cannot unregister', { state: this.state });
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this._sendAction(Actions.UNREGISTER);
|
|
323
352
|
this.emit(EVENT_UNREGISTERED);
|
|
324
|
-
this._sendAction(Actions.UNREGISTERED);
|
|
325
353
|
});
|
|
326
354
|
this.client.on(this.client.ON_DISCONNECTED, () => {
|
|
327
355
|
logger.info('softphone - disconnected');
|
|
328
|
-
this.
|
|
356
|
+
if (!can(this.softphoneActor, Actions.TRANSPORT_CLOSED)) {
|
|
357
|
+
logger.warn('softphone - cannot disconnected', { state: this.state });
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
329
360
|
this._sendAction(Actions.TRANSPORT_CLOSED);
|
|
361
|
+
this.emit(EVENT_DISCONNECTED);
|
|
330
362
|
});
|
|
331
363
|
this.client.on(this.client.REGISTERED, () => {
|
|
332
|
-
logger.info('softphone - registered', { state: getState(this.softphoneActor) });
|
|
364
|
+
logger.info('softphone - registered', { state: getState(this.softphoneActor), reinvite: this.shouldSendReinvite });
|
|
333
365
|
if (!can(this.softphoneActor, Actions.REGISTER_DONE)) {
|
|
334
|
-
logger.warn('softphone - registered but not in REGISTERING state', { state:
|
|
366
|
+
logger.warn('softphone - registered but not in REGISTERING state', { state: this.state });
|
|
335
367
|
return;
|
|
336
368
|
}
|
|
337
369
|
this.stopHeartbeat();
|
|
@@ -347,9 +379,13 @@ export class Softphone extends EventEmitter {
|
|
|
347
379
|
}
|
|
348
380
|
});
|
|
349
381
|
this.client.on(this.client.CONNECTED, () => {
|
|
350
|
-
logger.info('softphone - connected');
|
|
382
|
+
logger.info('softphone - connected', { state: this.state });
|
|
351
383
|
this.stopHeartbeat();
|
|
352
384
|
});
|
|
385
|
+
this.client.on(this.client.REGISTERING, () => {
|
|
386
|
+
logger.info('softphone - registering', { state: this.state });
|
|
387
|
+
this._sendAction(Actions.REGISTER);
|
|
388
|
+
});
|
|
353
389
|
this.client.on(this.client.DISCONNECTED, () => {
|
|
354
390
|
logger.info('softphone - disconnected');
|
|
355
391
|
this.emit(EVENT_DISCONNECTED);
|
|
@@ -375,16 +411,21 @@ export class Softphone extends EventEmitter {
|
|
|
375
411
|
});
|
|
376
412
|
}
|
|
377
413
|
_sendAction(action) {
|
|
414
|
+
const was = this.state;
|
|
378
415
|
this.softphoneActor.send({ type: action });
|
|
416
|
+
logger.trace('softphone - send action', { action, was, state: this.state });
|
|
379
417
|
}
|
|
380
418
|
_getCall(sipCall) {
|
|
381
|
-
return this.calls.find(call => call.id === sipCall
|
|
419
|
+
return this.calls.find(call => call.id === getSipCallId(sipCall));
|
|
420
|
+
}
|
|
421
|
+
_getCallIds() {
|
|
422
|
+
return this.calls.map(call => call.id);
|
|
382
423
|
}
|
|
383
424
|
_onCallEvent(sipCall, eventName, ...args) {
|
|
384
|
-
logger.
|
|
425
|
+
logger.info('softphone - received call event', { eventName, sipId: getSipCallId(sipCall) });
|
|
385
426
|
const call = this._getCall(sipCall);
|
|
386
427
|
if (!call) {
|
|
387
|
-
logger.warn('softphone - no call found to send the event', { eventName, sipId: sipCall.
|
|
428
|
+
logger.warn('softphone - no call found to send the event', { eventName, sipId: getSipCallId(sipCall), ids: this._getCallIds() });
|
|
388
429
|
return;
|
|
389
430
|
}
|
|
390
431
|
// @ts-ignore
|