@voicenter-team/opensips-js 1.0.14 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- package/build/index.d.ts +4 -0
- package/build/index.js +67 -26
- package/package.json +1 -1
- package/src/types/listeners.d.ts +3 -1
package/build/index.d.ts
CHANGED
@@ -12,6 +12,9 @@ export interface InnerState {
|
|
12
12
|
activeCalls: {
|
13
13
|
[key: string]: ICall;
|
14
14
|
};
|
15
|
+
extendedCalls: {
|
16
|
+
[key: string]: ICall;
|
17
|
+
};
|
15
18
|
activeRooms: {
|
16
19
|
[key: number]: IRoom;
|
17
20
|
};
|
@@ -45,6 +48,7 @@ declare class OpenSIPSJS extends UA {
|
|
45
48
|
private readonly options;
|
46
49
|
private readonly newRTCSessionEventName;
|
47
50
|
private readonly activeCalls;
|
51
|
+
private readonly extendedCalls;
|
48
52
|
private _currentActiveRoomId;
|
49
53
|
private _callAddingInProgress;
|
50
54
|
private state;
|
package/build/index.js
CHANGED
@@ -26,7 +26,6 @@ const STORAGE_KEYS = {
|
|
26
26
|
SELECTED_INPUT_DEVICE: 'selectedInputDevice',
|
27
27
|
SELECTED_OUTPUT_DEVICE: 'selectedOutputDevice'
|
28
28
|
};
|
29
|
-
const activeCalls = {};
|
30
29
|
class OpenSIPSJS extends UA_1.default {
|
31
30
|
constructor(options) {
|
32
31
|
const configuration = Object.assign(Object.assign({}, options.configuration), { sockets: options.socketInterfaces.map(sock => new jssip_1.default.WebSocketInterface(sock)) });
|
@@ -34,10 +33,12 @@ class OpenSIPSJS extends UA_1.default {
|
|
34
33
|
this.initialized = false;
|
35
34
|
this.newRTCSessionEventName = 'newRTCSession';
|
36
35
|
this.activeCalls = {};
|
36
|
+
this.extendedCalls = {};
|
37
37
|
this.state = {
|
38
38
|
isMuted: false,
|
39
39
|
isAutoAnswer: false,
|
40
40
|
activeCalls: {},
|
41
|
+
extendedCalls: {},
|
41
42
|
availableMediaDevices: [],
|
42
43
|
selectedMediaDevices: {
|
43
44
|
input: 'default',
|
@@ -115,7 +116,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
115
116
|
}
|
116
117
|
set speakerVolume(value) {
|
117
118
|
this.state.speakerVolume = value;
|
118
|
-
Object.values(
|
119
|
+
Object.values(this.state.extendedCalls).forEach((call) => {
|
119
120
|
if (call.audioTag) {
|
120
121
|
call.audioTag.volume = value;
|
121
122
|
}
|
@@ -248,7 +249,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
248
249
|
if (!validation_regex.test(value)) {
|
249
250
|
throw new Error('Not allowed character in DTMF input');
|
250
251
|
}
|
251
|
-
const call =
|
252
|
+
const call = this.state.extendedCalls[callId];
|
252
253
|
call.sendDTMF(value);
|
253
254
|
}
|
254
255
|
doMute(value) {
|
@@ -260,7 +261,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
260
261
|
return super.sendMessage(`sip:${target}@${this.sipDomain}`, body, options);
|
261
262
|
}
|
262
263
|
doCallHold({ callId, toHold, automatic }) {
|
263
|
-
const call =
|
264
|
+
const call = this.state.extendedCalls[callId];
|
264
265
|
call._automaticHold = automatic !== null && automatic !== void 0 ? automatic : false;
|
265
266
|
if (toHold) {
|
266
267
|
call.hold();
|
@@ -276,7 +277,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
276
277
|
}).forEach(call => this.callTerminate(call._id));
|
277
278
|
}
|
278
279
|
callAnswer(callId) {
|
279
|
-
const call =
|
280
|
+
const call = this.state.extendedCalls[callId];
|
280
281
|
this._cancelAllOutgoingUnanswered();
|
281
282
|
call.answer(this.sipOptions);
|
282
283
|
this.updateCall(call);
|
@@ -305,7 +306,11 @@ class OpenSIPSJS extends UA_1.default {
|
|
305
306
|
}
|
306
307
|
_addCall(value, emitEvent = true) {
|
307
308
|
this.state.activeCalls = Object.assign(Object.assign({}, this.state.activeCalls), { [value._id]: (0, audio_helper_1.simplifyCallObject)(value) });
|
308
|
-
|
309
|
+
/*this.state.extendedCalls = {
|
310
|
+
...this.state.extendedCalls,
|
311
|
+
[value._id]: value
|
312
|
+
}*/
|
313
|
+
this.state.extendedCalls[value._id] = value;
|
309
314
|
if (emitEvent) {
|
310
315
|
this.emit('changeActiveCalls', this.state.activeCalls);
|
311
316
|
}
|
@@ -316,6 +321,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
316
321
|
isTransferring: false,
|
317
322
|
isMerging: false
|
318
323
|
} });
|
324
|
+
this.emit('changeCallStatus', this.state.callStatus);
|
319
325
|
}
|
320
326
|
_updateCallStatus(value) {
|
321
327
|
const prevStatus = Object.assign({}, this.state.callStatus[value.callId]);
|
@@ -330,11 +336,13 @@ class OpenSIPSJS extends UA_1.default {
|
|
330
336
|
newStatus.isMerging = value.isMerging;
|
331
337
|
}
|
332
338
|
this.state.callStatus = Object.assign(Object.assign({}, this.state.callStatus), { [value.callId]: Object.assign({}, newStatus) });
|
339
|
+
this.emit('changeCallStatus', this.state.callStatus);
|
333
340
|
}
|
334
341
|
_removeCallStatus(callId) {
|
335
342
|
const callStatusCopy = Object.assign({}, this.state.callStatus);
|
336
343
|
delete callStatusCopy[callId];
|
337
344
|
this.state.callStatus = Object.assign({}, callStatusCopy);
|
345
|
+
this.emit('changeCallStatus', this.state.callStatus);
|
338
346
|
}
|
339
347
|
_addRoom(value) {
|
340
348
|
this.state.activeRooms = Object.assign(Object.assign({}, this.state.activeRooms), { [value.roomId]: value });
|
@@ -356,7 +364,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
356
364
|
if (Object.keys(this.getActiveCalls).length === 0) {
|
357
365
|
return;
|
358
366
|
}
|
359
|
-
const callsInCurrentRoom = Object.values(
|
367
|
+
const callsInCurrentRoom = Object.values(this.state.extendedCalls).filter(call => call.roomId === this.currentActiveRoomId);
|
360
368
|
if (callsInCurrentRoom.length === 1) {
|
361
369
|
Object.values(callsInCurrentRoom).forEach(call => {
|
362
370
|
const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
|
@@ -381,7 +389,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
381
389
|
return;
|
382
390
|
}
|
383
391
|
this.selectedOutputDevice = dId;
|
384
|
-
const activeCallList = Object.values(
|
392
|
+
const activeCallList = Object.values(this.state.extendedCalls);
|
385
393
|
if (activeCallList.length === 0) {
|
386
394
|
return;
|
387
395
|
}
|
@@ -409,7 +417,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
409
417
|
if (roomId === undefined) {
|
410
418
|
return;
|
411
419
|
}
|
412
|
-
if (Object.values(
|
420
|
+
if (Object.values(this.state.extendedCalls).filter(call => call.roomId === roomId).length === 0) {
|
413
421
|
this.removeRoom(roomId);
|
414
422
|
if (this.currentActiveRoomId === roomId) {
|
415
423
|
this.currentActiveRoomId = undefined;
|
@@ -434,7 +442,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
434
442
|
if (roomId === undefined) {
|
435
443
|
return;
|
436
444
|
}
|
437
|
-
const callsInRoom = Object.values(
|
445
|
+
const callsInRoom = Object.values(this.state.extendedCalls).filter(call => call.roomId === roomId);
|
438
446
|
// Let`s take care on the audio output first and check if passed room is our selected room
|
439
447
|
if (this.currentActiveRoomId === roomId) {
|
440
448
|
callsInRoom.forEach(call => {
|
@@ -547,7 +555,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
547
555
|
}
|
548
556
|
}
|
549
557
|
muteCaller(callId, value) {
|
550
|
-
const call =
|
558
|
+
const call = this.state.extendedCalls[callId];
|
551
559
|
if (call && call.connection.getReceivers().length) {
|
552
560
|
call.localMuted = value;
|
553
561
|
call.connection.getReceivers().forEach((receiver) => {
|
@@ -558,7 +566,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
558
566
|
}
|
559
567
|
}
|
560
568
|
callTerminate(callId) {
|
561
|
-
const call =
|
569
|
+
const call = this.state.extendedCalls[callId];
|
562
570
|
if (call._status !== 8) {
|
563
571
|
call.terminate();
|
564
572
|
}
|
@@ -567,10 +575,8 @@ class OpenSIPSJS extends UA_1.default {
|
|
567
575
|
if (target.toString().length === 0) {
|
568
576
|
return console.error('Target must be passed');
|
569
577
|
}
|
570
|
-
const call =
|
571
|
-
console.log('callTransfer', call);
|
578
|
+
const call = this.state.extendedCalls[callId];
|
572
579
|
if (!call._is_confirmed && !call._is_canceled) {
|
573
|
-
console.log('refer', `sip:${target}@${this.sipDomain}`);
|
574
580
|
call.refer(`sip:${target}@${this.sipDomain}`);
|
575
581
|
return;
|
576
582
|
}
|
@@ -579,7 +585,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
579
585
|
this.updateCall(call);
|
580
586
|
}
|
581
587
|
callMerge(roomId) {
|
582
|
-
const callsInRoom = Object.values(
|
588
|
+
const callsInRoom = Object.values(this.state.extendedCalls).filter((call) => call.roomId === roomId);
|
583
589
|
if (callsInRoom.length !== 2)
|
584
590
|
return;
|
585
591
|
const firstCall = callsInRoom[0];
|
@@ -707,12 +713,15 @@ class OpenSIPSJS extends UA_1.default {
|
|
707
713
|
_removeCall(value) {
|
708
714
|
const stateActiveCallsCopy = Object.assign({}, this.state.activeCalls);
|
709
715
|
delete stateActiveCallsCopy[value];
|
710
|
-
delete activeCalls[value]
|
716
|
+
// delete activeCalls[value]
|
711
717
|
this.state.activeCalls = Object.assign({}, stateActiveCallsCopy);
|
718
|
+
const stateExtendedCallsCopy = Object.assign({}, this.state.extendedCalls);
|
719
|
+
delete stateExtendedCallsCopy[value];
|
720
|
+
this.state.extendedCalls = Object.assign({}, stateExtendedCallsCopy);
|
712
721
|
this.emit('changeActiveCalls', this.state.activeCalls);
|
713
722
|
}
|
714
723
|
_activeCallListRemove(call) {
|
715
|
-
const callRoomIdToConfigure =
|
724
|
+
const callRoomIdToConfigure = this.state.extendedCalls[call._id].roomId;
|
716
725
|
this._removeCall(call._id);
|
717
726
|
this.roomReconfigure(callRoomIdToConfigure);
|
718
727
|
}
|
@@ -732,7 +741,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
732
741
|
this._stopCallTimer(session.id);
|
733
742
|
this._removeCallStatus(session.id);
|
734
743
|
this._removeCallMetrics(session.id);
|
735
|
-
if (!Object.keys(
|
744
|
+
if (!Object.keys(this.state.extendedCalls).length) {
|
736
745
|
this.isMuted = false;
|
737
746
|
}
|
738
747
|
});
|
@@ -751,7 +760,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
751
760
|
this._stopCallTimer(session.id);
|
752
761
|
this._removeCallStatus(session.id);
|
753
762
|
this._removeCallMetrics(session.id);
|
754
|
-
if (!Object.keys(
|
763
|
+
if (!Object.keys(this.state.extendedCalls).length) {
|
755
764
|
this.isMuted = false;
|
756
765
|
}
|
757
766
|
});
|
@@ -768,14 +777,46 @@ class OpenSIPSJS extends UA_1.default {
|
|
768
777
|
this.setCurrentActiveRoomId(roomId);
|
769
778
|
}
|
770
779
|
}
|
771
|
-
setInitialized() {
|
772
|
-
this.initialized =
|
773
|
-
this.emit('ready',
|
780
|
+
setInitialized(value) {
|
781
|
+
this.initialized = value;
|
782
|
+
this.emit('ready', value);
|
774
783
|
}
|
775
784
|
start() {
|
785
|
+
this.on('connecting', (res) => {
|
786
|
+
console.log('ON connecting', res);
|
787
|
+
});
|
788
|
+
this.on('connected', (res) => {
|
789
|
+
console.log('ON connected', res);
|
790
|
+
});
|
791
|
+
this.on('disconnected', (res) => {
|
792
|
+
console.log('ON disconnected', res);
|
793
|
+
});
|
794
|
+
this.on('registered', (res) => {
|
795
|
+
this.setInitialized(true);
|
796
|
+
console.log('ON registered', res);
|
797
|
+
});
|
798
|
+
this.on('unregistered', (res) => {
|
799
|
+
this.setInitialized(false);
|
800
|
+
console.log('ON unregistered', res);
|
801
|
+
});
|
802
|
+
this.on('registrationFailed', (res) => {
|
803
|
+
console.log('ON registrationFailed', res);
|
804
|
+
});
|
805
|
+
this.on('registrationExpiring', (res) => {
|
806
|
+
console.log('ON registrationExpiring', res);
|
807
|
+
});
|
808
|
+
this.on('newMessage', (res) => {
|
809
|
+
console.log('ON newMessage', res);
|
810
|
+
});
|
811
|
+
this.on('sipEvent', (res) => {
|
812
|
+
console.log('ON sipEvent', res);
|
813
|
+
});
|
814
|
+
this.on('newOptions', (res) => {
|
815
|
+
console.log('ON newOptions', res);
|
816
|
+
});
|
776
817
|
this.on(this.newRTCSessionEventName, this.newRTCSessionCallback.bind(this));
|
777
818
|
super.start();
|
778
|
-
this.setInitialized()
|
819
|
+
//this.setInitialized()
|
779
820
|
//this.setDefaultMediaDevices()
|
780
821
|
this.setMediaDevices(true);
|
781
822
|
return this;
|
@@ -863,8 +904,8 @@ class OpenSIPSJS extends UA_1.default {
|
|
863
904
|
}
|
864
905
|
callChangeRoom({ callId, roomId }) {
|
865
906
|
return __awaiter(this, void 0, void 0, function* () {
|
866
|
-
const oldRoomId =
|
867
|
-
|
907
|
+
const oldRoomId = this.state.extendedCalls[callId].roomId;
|
908
|
+
this.state.extendedCalls[callId].roomId = roomId;
|
868
909
|
yield this.setCurrentActiveRoomId(roomId);
|
869
910
|
return Promise.all([
|
870
911
|
this.roomReconfigure(oldRoomId),
|
package/package.json
CHANGED
package/src/types/listeners.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ICall, RoomChangeEmitType } from '@/types/rtc'
|
1
|
+
import { ICall, RoomChangeEmitType, ICallStatus } from '@/types/rtc'
|
2
2
|
import { UAEventMap } from 'jssip/lib/UA'
|
3
3
|
|
4
4
|
export type readyListener = (value: boolean) => void
|
@@ -17,6 +17,7 @@ export type changeOriginalStreamListener = (value: MediaStream) => void
|
|
17
17
|
export type addRoomListener = (value: RoomChangeEmitType) => void
|
18
18
|
export type updateRoomListener = (value: RoomChangeEmitType) => void
|
19
19
|
export type removeRoomListener = (value: RoomChangeEmitType) => void
|
20
|
+
export type changeCallStatusListener = (event: { [key: string]: ICallStatus }) => void
|
20
21
|
|
21
22
|
export interface OpenSIPSEventMap extends UAEventMap {
|
22
23
|
ready: readyListener
|
@@ -35,6 +36,7 @@ export interface OpenSIPSEventMap extends UAEventMap {
|
|
35
36
|
addRoom: addRoomListener
|
36
37
|
updateRoom: updateRoomListener
|
37
38
|
removeRoom: removeRoomListener
|
39
|
+
changeCallStatus: changeCallStatusListener
|
38
40
|
}
|
39
41
|
|
40
42
|
export type ListenersKeyType = keyof OpenSIPSEventMap
|