@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/lib/voice/softphone.js
CHANGED
|
@@ -47,6 +47,7 @@ const IssueReporter_1 = __importDefault(require("../service/IssueReporter"));
|
|
|
47
47
|
const sip_logger_1 = __importDefault(require("../utils/sip-logger"));
|
|
48
48
|
const call_1 = __importDefault(require("./call"));
|
|
49
49
|
const utils_1 = require("../state-machine/utils");
|
|
50
|
+
const sdp_1 = require("../utils/sdp");
|
|
50
51
|
exports.EVENT_INCOMING = 'incoming';
|
|
51
52
|
exports.EVENT_OUTGOING = 'outgoing';
|
|
52
53
|
exports.EVENT_HEARTBEAT = 'heartbeat';
|
|
@@ -80,6 +81,7 @@ class Softphone extends events_1.EventEmitter {
|
|
|
80
81
|
this.audioRingVolume = 1;
|
|
81
82
|
const server = __1.default.Auth.getHost();
|
|
82
83
|
const session = __1.default.Auth.getSession();
|
|
84
|
+
logger.info('softphone - connect', { server, session: !!session });
|
|
83
85
|
if (!server || !session) {
|
|
84
86
|
throw new Error('Please connect to the server using `Wazo.Auth.logIn` or `Wazo.Auth.authenticate` before using Room.connect().');
|
|
85
87
|
}
|
|
@@ -91,15 +93,23 @@ class Softphone extends events_1.EventEmitter {
|
|
|
91
93
|
this.options.userUuid = session.uuid || '';
|
|
92
94
|
return this.connectWithCredentials(server, this.sipLine, session.displayName(), options);
|
|
93
95
|
}
|
|
96
|
+
hangupAllCalls() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return Promise.all(this.calls.map(call => call.hangup()));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
94
101
|
disconnect() {
|
|
95
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
103
|
(0, utils_1.assertCan)(this.softphoneActor, softphone_state_machine_1.Actions.UNREGISTER);
|
|
104
|
+
logger.info('softphone - disconnect');
|
|
97
105
|
if (!this.client) {
|
|
106
|
+
logger.info('softphone - disconnect, not client to disconnect, bailing');
|
|
98
107
|
return null;
|
|
99
108
|
}
|
|
100
109
|
// Terminate all calls
|
|
101
|
-
yield
|
|
102
|
-
|
|
110
|
+
yield this.hangupAllCalls();
|
|
111
|
+
yield this.client.unregister();
|
|
112
|
+
return this.client.close();
|
|
103
113
|
});
|
|
104
114
|
}
|
|
105
115
|
getPrimaryWebRtcLine() {
|
|
@@ -109,7 +119,8 @@ class Softphone extends events_1.EventEmitter {
|
|
|
109
119
|
connectWithCredentials(server_1, sipLine_1, displayName_1) {
|
|
110
120
|
return __awaiter(this, arguments, void 0, function* (server, sipLine, displayName, rawOptions = {}) {
|
|
111
121
|
(0, utils_1.assertCan)(this.softphoneActor, softphone_state_machine_1.Actions.REGISTER);
|
|
112
|
-
|
|
122
|
+
logger.info('softphone - connect with credentials', { server, username: sipLine.username, displayName, options: rawOptions });
|
|
123
|
+
this._sendAction(softphone_state_machine_1.Actions.REGISTER);
|
|
113
124
|
const [host, port = 443] = server.split(':');
|
|
114
125
|
let options = Object.assign({}, rawOptions);
|
|
115
126
|
options.media = options.media || {
|
|
@@ -134,7 +145,7 @@ class Softphone extends events_1.EventEmitter {
|
|
|
134
145
|
if (!this.client) {
|
|
135
146
|
return;
|
|
136
147
|
}
|
|
137
|
-
this.client.
|
|
148
|
+
this.client.register();
|
|
138
149
|
}
|
|
139
150
|
call(options) {
|
|
140
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -147,7 +158,7 @@ class Softphone extends events_1.EventEmitter {
|
|
|
147
158
|
logger.info('softphone - calling when registering, waiting for Softphone to be registered ...');
|
|
148
159
|
yield (0, utils_1.waitUntilState)(this.softphoneActor, softphone_state_machine_1.States.REGISTERED);
|
|
149
160
|
}
|
|
150
|
-
if (this.state !== softphone_state_machine_1.States.
|
|
161
|
+
if (this.state !== softphone_state_machine_1.States.REGISTERED) {
|
|
151
162
|
throw new InvalidState_1.default(`Invalid state ${softphone_state_machine_1.States.UNREGISTERED}`, softphone_state_machine_1.States.UNREGISTERED);
|
|
152
163
|
}
|
|
153
164
|
// Hold other calls
|
|
@@ -156,6 +167,8 @@ class Softphone extends events_1.EventEmitter {
|
|
|
156
167
|
try {
|
|
157
168
|
sipCall = this.client.call(options.params.To, options.withCamera, options.audioOnly, options.conference, options);
|
|
158
169
|
const call = new call_1.default(sipCall, this);
|
|
170
|
+
call.onMakeCall();
|
|
171
|
+
this.calls.push(call);
|
|
159
172
|
this.emit(exports.EVENT_OUTGOING, call);
|
|
160
173
|
return call;
|
|
161
174
|
}
|
|
@@ -221,10 +234,12 @@ class Softphone extends events_1.EventEmitter {
|
|
|
221
234
|
this.ringingEnabled = false;
|
|
222
235
|
}
|
|
223
236
|
holdAllCalls(exceptCall = null) {
|
|
224
|
-
|
|
237
|
+
logger.info('softphone - hold all calls', { exceptId: exceptCall === null || exceptCall === void 0 ? void 0 : exceptCall.id, ids: this.calls.map(call => call.id) });
|
|
238
|
+
this.calls.filter(call => !call.isHeld() && call.id !== (exceptCall === null || exceptCall === void 0 ? void 0 : exceptCall.id)).forEach(call => call.hold());
|
|
225
239
|
}
|
|
226
240
|
startHeartbeat() {
|
|
227
|
-
|
|
241
|
+
var _a;
|
|
242
|
+
logger.info('softphone - start heartbeat', { client: !!this.client, hasHeartbeat: (_a = this.client) === null || _a === void 0 ? void 0 : _a.hasHeartbeat() });
|
|
228
243
|
if (!this.client || this.client.hasHeartbeat()) {
|
|
229
244
|
return;
|
|
230
245
|
}
|
|
@@ -275,7 +290,10 @@ class Softphone extends events_1.EventEmitter {
|
|
|
275
290
|
this.audioRingVolume = volume;
|
|
276
291
|
}
|
|
277
292
|
getCurrentCall() {
|
|
278
|
-
return this.
|
|
293
|
+
return this.getActiveCalls()[0];
|
|
294
|
+
}
|
|
295
|
+
getActiveCalls() {
|
|
296
|
+
return this.calls.filter(call => call.isEstablished());
|
|
279
297
|
}
|
|
280
298
|
getIncomingCalls() {
|
|
281
299
|
return this.calls.filter(call => call.isRinging());
|
|
@@ -283,13 +301,23 @@ class Softphone extends events_1.EventEmitter {
|
|
|
283
301
|
get state() {
|
|
284
302
|
return (0, utils_1.getState)(this.softphoneActor);
|
|
285
303
|
}
|
|
304
|
+
get user() {
|
|
305
|
+
var _a, _b, _c, _d;
|
|
306
|
+
return (_d = (_c = (_b = (_a = this.client) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.contact) === null || _c === void 0 ? void 0 : _c.uri) === null || _d === void 0 ? void 0 : _d.user;
|
|
307
|
+
}
|
|
286
308
|
getUserAgent() {
|
|
287
309
|
var _a, _b;
|
|
288
310
|
return ((_b = (_a = this.client) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.userAgentString) || 'softphone';
|
|
289
311
|
}
|
|
312
|
+
isRegistering() {
|
|
313
|
+
return this.state === softphone_state_machine_1.States.REGISTERING;
|
|
314
|
+
}
|
|
290
315
|
isRegistered() {
|
|
291
316
|
return this.state === softphone_state_machine_1.States.REGISTERED;
|
|
292
317
|
}
|
|
318
|
+
isUnRegistered() {
|
|
319
|
+
return this.state === softphone_state_machine_1.States.UNREGISTERED;
|
|
320
|
+
}
|
|
293
321
|
_bindEvents() {
|
|
294
322
|
this.client.on(this.client.INVITE, (sipSession) => {
|
|
295
323
|
const call = new call_1.default(sipSession, this);
|
|
@@ -308,7 +336,7 @@ class Softphone extends events_1.EventEmitter {
|
|
|
308
336
|
});
|
|
309
337
|
this.client.on(this.client.ON_REINVITE, (sipCall, request, updatedCalleeName, updatedNumber, hadRemoteVideo) => {
|
|
310
338
|
logger.info('softphone - on reinvite', {
|
|
311
|
-
callId: sipCall
|
|
339
|
+
callId: (0, sdp_1.getSipCallId)(sipCall),
|
|
312
340
|
inviteId: request.callId,
|
|
313
341
|
updatedCalleeName,
|
|
314
342
|
updatedNumber,
|
|
@@ -348,18 +376,26 @@ class Softphone extends events_1.EventEmitter {
|
|
|
348
376
|
});
|
|
349
377
|
this.client.on(this.client.UNREGISTERED, () => {
|
|
350
378
|
logger.info('softphone - unregistered');
|
|
379
|
+
if (!(0, utils_1.can)(this.softphoneActor, softphone_state_machine_1.Actions.UNREGISTER)) {
|
|
380
|
+
logger.warn('softphone - cannot unregister', { state: this.state });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
this._sendAction(softphone_state_machine_1.Actions.UNREGISTER);
|
|
351
384
|
this.emit(exports.EVENT_UNREGISTERED);
|
|
352
|
-
this._sendAction(softphone_state_machine_1.Actions.UNREGISTERED);
|
|
353
385
|
});
|
|
354
386
|
this.client.on(this.client.ON_DISCONNECTED, () => {
|
|
355
387
|
logger.info('softphone - disconnected');
|
|
356
|
-
|
|
388
|
+
if (!(0, utils_1.can)(this.softphoneActor, softphone_state_machine_1.Actions.TRANSPORT_CLOSED)) {
|
|
389
|
+
logger.warn('softphone - cannot disconnected', { state: this.state });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
357
392
|
this._sendAction(softphone_state_machine_1.Actions.TRANSPORT_CLOSED);
|
|
393
|
+
this.emit(exports.EVENT_DISCONNECTED);
|
|
358
394
|
});
|
|
359
395
|
this.client.on(this.client.REGISTERED, () => {
|
|
360
|
-
logger.info('softphone - registered', { state: (0, utils_1.getState)(this.softphoneActor) });
|
|
396
|
+
logger.info('softphone - registered', { state: (0, utils_1.getState)(this.softphoneActor), reinvite: this.shouldSendReinvite });
|
|
361
397
|
if (!(0, utils_1.can)(this.softphoneActor, softphone_state_machine_1.Actions.REGISTER_DONE)) {
|
|
362
|
-
logger.warn('softphone - registered but not in REGISTERING state', { state:
|
|
398
|
+
logger.warn('softphone - registered but not in REGISTERING state', { state: this.state });
|
|
363
399
|
return;
|
|
364
400
|
}
|
|
365
401
|
this.stopHeartbeat();
|
|
@@ -375,9 +411,13 @@ class Softphone extends events_1.EventEmitter {
|
|
|
375
411
|
}
|
|
376
412
|
});
|
|
377
413
|
this.client.on(this.client.CONNECTED, () => {
|
|
378
|
-
logger.info('softphone - connected');
|
|
414
|
+
logger.info('softphone - connected', { state: this.state });
|
|
379
415
|
this.stopHeartbeat();
|
|
380
416
|
});
|
|
417
|
+
this.client.on(this.client.REGISTERING, () => {
|
|
418
|
+
logger.info('softphone - registering', { state: this.state });
|
|
419
|
+
this._sendAction(softphone_state_machine_1.Actions.REGISTER);
|
|
420
|
+
});
|
|
381
421
|
this.client.on(this.client.DISCONNECTED, () => {
|
|
382
422
|
logger.info('softphone - disconnected');
|
|
383
423
|
this.emit(exports.EVENT_DISCONNECTED);
|
|
@@ -403,16 +443,21 @@ class Softphone extends events_1.EventEmitter {
|
|
|
403
443
|
});
|
|
404
444
|
}
|
|
405
445
|
_sendAction(action) {
|
|
446
|
+
const was = this.state;
|
|
406
447
|
this.softphoneActor.send({ type: action });
|
|
448
|
+
logger.trace('softphone - send action', { action, was, state: this.state });
|
|
407
449
|
}
|
|
408
450
|
_getCall(sipCall) {
|
|
409
|
-
return this.calls.find(call => call.id ===
|
|
451
|
+
return this.calls.find(call => call.id === (0, sdp_1.getSipCallId)(sipCall));
|
|
452
|
+
}
|
|
453
|
+
_getCallIds() {
|
|
454
|
+
return this.calls.map(call => call.id);
|
|
410
455
|
}
|
|
411
456
|
_onCallEvent(sipCall, eventName, ...args) {
|
|
412
|
-
logger.
|
|
457
|
+
logger.info('softphone - received call event', { eventName, sipId: (0, sdp_1.getSipCallId)(sipCall) });
|
|
413
458
|
const call = this._getCall(sipCall);
|
|
414
459
|
if (!call) {
|
|
415
|
-
logger.warn('softphone - no call found to send the event', { eventName, sipId: sipCall.
|
|
460
|
+
logger.warn('softphone - no call found to send the event', { eventName, sipId: (0, sdp_1.getSipCallId)(sipCall), ids: this._getCallIds() });
|
|
416
461
|
return;
|
|
417
462
|
}
|
|
418
463
|
// @ts-ignore
|