@voicenter-team/opensips-js 1.0.18 → 1.0.20
Sign up to get free protection for your applications and to get access to all the features.
- package/build/helpers/UA/index.d.ts +0 -2
- package/build/helpers/UA/index.js +0 -6
- package/build/index.d.ts +14 -3
- package/build/index.js +103 -42
- package/package.json +1 -1
- package/src/types/rtc.d.ts +2 -1
- package/build/lib/msrp/message.d.ts +0 -13
- package/build/lib/msrp/message.js +0 -65
- package/build/lib/msrp/session.d.ts +0 -21
- package/build/lib/msrp/session.js +0 -130
@@ -1,8 +1,6 @@
|
|
1
1
|
import { UA } from 'jssip';
|
2
2
|
import { CallOptionsExtended } from '@/types/rtc';
|
3
3
|
import { RTCSession } from 'jssip/lib/RTCSession';
|
4
|
-
import { MSRPSession } from '@/lib/msrp/session';
|
5
4
|
export default class UAExtended extends UA {
|
6
5
|
call(target: string, options?: CallOptionsExtended): RTCSession;
|
7
|
-
sendMSRPMessage(target: string, options: string): MSRPSession;
|
8
6
|
}
|
@@ -1,15 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const jssip_1 = require("jssip");
|
4
|
-
const session_1 = require("@/lib/msrp/session");
|
5
4
|
class UAExtended extends jssip_1.UA {
|
6
5
|
call(target, options) {
|
7
6
|
return super.call(target, options);
|
8
7
|
}
|
9
|
-
sendMSRPMessage(target, options) {
|
10
|
-
const session = new session_1.MSRPSession(this);
|
11
|
-
session.send(target, options);
|
12
|
-
return session;
|
13
|
-
}
|
14
8
|
}
|
15
9
|
exports.default = UAExtended;
|
package/build/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import JsSIP from 'jssip';
|
2
|
-
import UA from '
|
3
|
-
import { TempTimeData, ITimeData } from '
|
2
|
+
import UA from './helpers/UA';
|
3
|
+
import { TempTimeData, ITimeData } from './helpers/time.helper';
|
4
4
|
import { WebrtcMetricsConfigType, MediaDeviceType } from '@/types/webrtcmetrics';
|
5
5
|
import { ListenersKeyType, ListenerCallbackFnType } from '@/types/listeners';
|
6
6
|
import { RTCSessionExtended, ICall, IntervalType, ListenerEventType, IRoom, IDoCallParam, ICallStatus, IRoomUpdate, IOpenSIPSJSOptions } from '@/types/rtc';
|
@@ -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
|
};
|
@@ -38,12 +41,16 @@ export interface InnerState {
|
|
38
41
|
[key: string]: Array<(call: RTCSessionExtended, event: ListenerEventType | undefined) => void>;
|
39
42
|
};
|
40
43
|
metricConfig: WebrtcMetricsConfigType;
|
44
|
+
isAutoAnswer: boolean;
|
41
45
|
}
|
42
46
|
declare class OpenSIPSJS extends UA {
|
43
47
|
private initialized;
|
44
48
|
private readonly options;
|
45
49
|
private readonly newRTCSessionEventName;
|
50
|
+
private readonly registeredEventName;
|
51
|
+
private readonly unregisteredEventName;
|
46
52
|
private readonly activeCalls;
|
53
|
+
private readonly extendedCalls;
|
47
54
|
private _currentActiveRoomId;
|
48
55
|
private _callAddingInProgress;
|
49
56
|
private state;
|
@@ -67,6 +74,8 @@ declare class OpenSIPSJS extends UA {
|
|
67
74
|
};
|
68
75
|
get currentActiveRoomId(): number | undefined;
|
69
76
|
private set currentActiveRoomId(value);
|
77
|
+
get autoAnswer(): boolean;
|
78
|
+
set autoAnswer(value: boolean);
|
70
79
|
get callAddingInProgress(): string | undefined;
|
71
80
|
private set callAddingInProgress(value);
|
72
81
|
get muteWhenJoin(): boolean;
|
@@ -80,6 +89,7 @@ declare class OpenSIPSJS extends UA {
|
|
80
89
|
get getActiveCalls(): {
|
81
90
|
[key: string]: ICall;
|
82
91
|
};
|
92
|
+
get hasActiveCalls(): boolean;
|
83
93
|
get getActiveRooms(): {
|
84
94
|
[key: number]: IRoom;
|
85
95
|
};
|
@@ -113,7 +123,7 @@ declare class OpenSIPSJS extends UA {
|
|
113
123
|
setMetricsConfig(config: WebrtcMetricsConfigType): void;
|
114
124
|
sendDTMF(callId: string, value: string): void;
|
115
125
|
doMute(value: boolean): void;
|
116
|
-
|
126
|
+
sendMessage(target: string | JsSIP.URI, body: string, options?: SendMessageOptions): import("jssip/lib/Message").Message;
|
117
127
|
doCallHold({ callId, toHold, automatic }: {
|
118
128
|
callId: string;
|
119
129
|
toHold: boolean;
|
@@ -124,6 +134,7 @@ declare class OpenSIPSJS extends UA {
|
|
124
134
|
callMove(callId: string, roomId: number): Promise<void>;
|
125
135
|
updateCall(value: ICall): void;
|
126
136
|
updateRoom(value: IRoomUpdate): void;
|
137
|
+
private hasAutoAnswerHeaders;
|
127
138
|
private _addCall;
|
128
139
|
private _addCallStatus;
|
129
140
|
private _updateCallStatus;
|
package/build/index.js
CHANGED
@@ -13,30 +13,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
const jssip_1 = __importDefault(require("jssip"));
|
16
|
-
const UA_1 = __importDefault(require("
|
16
|
+
const UA_1 = __importDefault(require("./helpers/UA"));
|
17
17
|
const p_iteration_1 = require("p-iteration");
|
18
|
-
const time_helper_1 = require("
|
19
|
-
const filter_helper_1 = require("
|
20
|
-
const audio_helper_1 = require("
|
21
|
-
const metrics_1 = __importDefault(require("
|
22
|
-
const metric_keys_to_include_1 = require("
|
23
|
-
const call_event_listener_type_1 = require("
|
18
|
+
const time_helper_1 = require("./helpers/time.helper");
|
19
|
+
const filter_helper_1 = require("./helpers/filter.helper");
|
20
|
+
const audio_helper_1 = require("./helpers/audio.helper");
|
21
|
+
const metrics_1 = __importDefault(require("./helpers/webrtcmetrics/metrics"));
|
22
|
+
const metric_keys_to_include_1 = require("./enum/metric.keys.to.include");
|
23
|
+
const call_event_listener_type_1 = require("./enum/call.event.listener.type");
|
24
24
|
const CALL_STATUS_UNANSWERED = 0;
|
25
25
|
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)) });
|
33
32
|
super(configuration);
|
34
33
|
this.initialized = false;
|
35
34
|
this.newRTCSessionEventName = 'newRTCSession';
|
35
|
+
this.registeredEventName = 'registered';
|
36
|
+
this.unregisteredEventName = 'unregistered';
|
36
37
|
this.activeCalls = {};
|
38
|
+
this.extendedCalls = {};
|
37
39
|
this.state = {
|
38
40
|
isMuted: false,
|
41
|
+
isAutoAnswer: false,
|
39
42
|
activeCalls: {},
|
43
|
+
extendedCalls: {},
|
40
44
|
availableMediaDevices: [],
|
41
45
|
selectedMediaDevices: {
|
42
46
|
input: 'default',
|
@@ -82,6 +86,12 @@ class OpenSIPSJS extends UA_1.default {
|
|
82
86
|
this._currentActiveRoomId = roomId;
|
83
87
|
this.emit('currentActiveRoomChanged', roomId);
|
84
88
|
}
|
89
|
+
get autoAnswer() {
|
90
|
+
return this.state.isAutoAnswer;
|
91
|
+
}
|
92
|
+
set autoAnswer(value) {
|
93
|
+
this.state.isAutoAnswer = value;
|
94
|
+
}
|
85
95
|
get callAddingInProgress() {
|
86
96
|
return this._callAddingInProgress;
|
87
97
|
}
|
@@ -108,7 +118,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
108
118
|
}
|
109
119
|
set speakerVolume(value) {
|
110
120
|
this.state.speakerVolume = value;
|
111
|
-
Object.values(
|
121
|
+
Object.values(this.state.extendedCalls).forEach((call) => {
|
112
122
|
if (call.audioTag) {
|
113
123
|
call.audioTag.volume = value;
|
114
124
|
}
|
@@ -124,6 +134,9 @@ class OpenSIPSJS extends UA_1.default {
|
|
124
134
|
get getActiveCalls() {
|
125
135
|
return this.state.activeCalls;
|
126
136
|
}
|
137
|
+
get hasActiveCalls() {
|
138
|
+
return Object.values(this.state.extendedCalls).length > 0;
|
139
|
+
}
|
127
140
|
get getActiveRooms() {
|
128
141
|
return this.state.activeRooms;
|
129
142
|
}
|
@@ -241,7 +254,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
241
254
|
if (!validation_regex.test(value)) {
|
242
255
|
throw new Error('Not allowed character in DTMF input');
|
243
256
|
}
|
244
|
-
const call =
|
257
|
+
const call = this.state.extendedCalls[callId];
|
245
258
|
call.sendDTMF(value);
|
246
259
|
}
|
247
260
|
doMute(value) {
|
@@ -249,12 +262,11 @@ class OpenSIPSJS extends UA_1.default {
|
|
249
262
|
this.isMuted = value;
|
250
263
|
this.roomReconfigure(activeRoomId);
|
251
264
|
}
|
252
|
-
|
253
|
-
super.sendMSRPMessage(`sip:${target}@${this.sipDomain}`, body);
|
265
|
+
sendMessage(target, body, options) {
|
254
266
|
return super.sendMessage(`sip:${target}@${this.sipDomain}`, body, options);
|
255
267
|
}
|
256
268
|
doCallHold({ callId, toHold, automatic }) {
|
257
|
-
const call =
|
269
|
+
const call = this.state.extendedCalls[callId];
|
258
270
|
call._automaticHold = automatic !== null && automatic !== void 0 ? automatic : false;
|
259
271
|
if (toHold) {
|
260
272
|
call.hold();
|
@@ -270,7 +282,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
270
282
|
}).forEach(call => this.callTerminate(call._id));
|
271
283
|
}
|
272
284
|
callAnswer(callId) {
|
273
|
-
const call =
|
285
|
+
const call = this.state.extendedCalls[callId];
|
274
286
|
this._cancelAllOutgoingUnanswered();
|
275
287
|
call.answer(this.sipOptions);
|
276
288
|
this.updateCall(call);
|
@@ -297,10 +309,22 @@ class OpenSIPSJS extends UA_1.default {
|
|
297
309
|
this.state.activeRooms = Object.assign(Object.assign({}, this.state.activeRooms), { [value.roomId]: Object.assign({}, newRoomData) });
|
298
310
|
this.emit('updateRoom', { room: newRoomData, roomList: this.state.activeRooms });
|
299
311
|
}
|
300
|
-
|
312
|
+
hasAutoAnswerHeaders(event) {
|
313
|
+
const regex = /answer-after=0/;
|
314
|
+
const request = event.request;
|
315
|
+
const callInfoHeader = request.getHeader('Call-Info');
|
316
|
+
return callInfoHeader && regex.test(callInfoHeader);
|
317
|
+
}
|
318
|
+
_addCall(value, emitEvent = true) {
|
301
319
|
this.state.activeCalls = Object.assign(Object.assign({}, this.state.activeCalls), { [value._id]: (0, audio_helper_1.simplifyCallObject)(value) });
|
302
|
-
|
303
|
-
|
320
|
+
/*this.state.extendedCalls = {
|
321
|
+
...this.state.extendedCalls,
|
322
|
+
[value._id]: value
|
323
|
+
}*/
|
324
|
+
this.state.extendedCalls[value._id] = value;
|
325
|
+
if (emitEvent) {
|
326
|
+
this.emit('changeActiveCalls', this.state.activeCalls);
|
327
|
+
}
|
304
328
|
}
|
305
329
|
_addCallStatus(callId) {
|
306
330
|
this.state.callStatus = Object.assign(Object.assign({}, this.state.callStatus), { [callId]: {
|
@@ -308,6 +332,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
308
332
|
isTransferring: false,
|
309
333
|
isMerging: false
|
310
334
|
} });
|
335
|
+
this.emit('changeCallStatus', this.state.callStatus);
|
311
336
|
}
|
312
337
|
_updateCallStatus(value) {
|
313
338
|
const prevStatus = Object.assign({}, this.state.callStatus[value.callId]);
|
@@ -322,11 +347,13 @@ class OpenSIPSJS extends UA_1.default {
|
|
322
347
|
newStatus.isMerging = value.isMerging;
|
323
348
|
}
|
324
349
|
this.state.callStatus = Object.assign(Object.assign({}, this.state.callStatus), { [value.callId]: Object.assign({}, newStatus) });
|
350
|
+
this.emit('changeCallStatus', this.state.callStatus);
|
325
351
|
}
|
326
352
|
_removeCallStatus(callId) {
|
327
353
|
const callStatusCopy = Object.assign({}, this.state.callStatus);
|
328
354
|
delete callStatusCopy[callId];
|
329
355
|
this.state.callStatus = Object.assign({}, callStatusCopy);
|
356
|
+
this.emit('changeCallStatus', this.state.callStatus);
|
330
357
|
}
|
331
358
|
_addRoom(value) {
|
332
359
|
this.state.activeRooms = Object.assign(Object.assign({}, this.state.activeRooms), { [value.roomId]: value });
|
@@ -348,7 +375,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
348
375
|
if (Object.keys(this.getActiveCalls).length === 0) {
|
349
376
|
return;
|
350
377
|
}
|
351
|
-
const callsInCurrentRoom = Object.values(
|
378
|
+
const callsInCurrentRoom = Object.values(this.state.extendedCalls).filter(call => call.roomId === this.currentActiveRoomId);
|
352
379
|
if (callsInCurrentRoom.length === 1) {
|
353
380
|
Object.values(callsInCurrentRoom).forEach(call => {
|
354
381
|
const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
|
@@ -373,7 +400,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
373
400
|
return;
|
374
401
|
}
|
375
402
|
this.selectedOutputDevice = dId;
|
376
|
-
const activeCallList = Object.values(
|
403
|
+
const activeCallList = Object.values(this.state.extendedCalls);
|
377
404
|
if (activeCallList.length === 0) {
|
378
405
|
return;
|
379
406
|
}
|
@@ -401,10 +428,10 @@ class OpenSIPSJS extends UA_1.default {
|
|
401
428
|
if (roomId === undefined) {
|
402
429
|
return;
|
403
430
|
}
|
404
|
-
if (Object.values(
|
431
|
+
if (Object.values(this.state.extendedCalls).filter(call => call.roomId === roomId).length === 0) {
|
405
432
|
this.removeRoom(roomId);
|
406
433
|
if (this.currentActiveRoomId === roomId) {
|
407
|
-
this.currentActiveRoomId =
|
434
|
+
this.currentActiveRoomId = undefined;
|
408
435
|
}
|
409
436
|
}
|
410
437
|
}
|
@@ -426,7 +453,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
426
453
|
if (roomId === undefined) {
|
427
454
|
return;
|
428
455
|
}
|
429
|
-
const callsInRoom = Object.values(
|
456
|
+
const callsInRoom = Object.values(this.state.extendedCalls).filter(call => call.roomId === roomId);
|
430
457
|
// Let`s take care on the audio output first and check if passed room is our selected room
|
431
458
|
if (this.currentActiveRoomId === roomId) {
|
432
459
|
callsInRoom.forEach(call => {
|
@@ -539,7 +566,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
539
566
|
}
|
540
567
|
}
|
541
568
|
muteCaller(callId, value) {
|
542
|
-
const call =
|
569
|
+
const call = this.state.extendedCalls[callId];
|
543
570
|
if (call && call.connection.getReceivers().length) {
|
544
571
|
call.localMuted = value;
|
545
572
|
call.connection.getReceivers().forEach((receiver) => {
|
@@ -550,7 +577,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
550
577
|
}
|
551
578
|
}
|
552
579
|
callTerminate(callId) {
|
553
|
-
const call =
|
580
|
+
const call = this.state.extendedCalls[callId];
|
554
581
|
if (call._status !== 8) {
|
555
582
|
call.terminate();
|
556
583
|
}
|
@@ -559,13 +586,22 @@ class OpenSIPSJS extends UA_1.default {
|
|
559
586
|
if (target.toString().length === 0) {
|
560
587
|
return console.error('Target must be passed');
|
561
588
|
}
|
589
|
+
const call = this.state.extendedCalls[callId];
|
590
|
+
if (!call._is_confirmed && !call._is_canceled) {
|
591
|
+
const redirectTarget = `sip:${target}@${this.sipDomain}`;
|
592
|
+
call.terminate({
|
593
|
+
status_code: 302,
|
594
|
+
reason_phrase: 'Moved Temporarily',
|
595
|
+
extraHeaders: [`Contact: ${redirectTarget}`]
|
596
|
+
});
|
597
|
+
return;
|
598
|
+
}
|
562
599
|
this._updateCallStatus({ callId, isTransferring: true });
|
563
|
-
const call = activeCalls[callId];
|
564
600
|
call.refer(`sip:${target}@${this.sipDomain}`);
|
565
601
|
this.updateCall(call);
|
566
602
|
}
|
567
603
|
callMerge(roomId) {
|
568
|
-
const callsInRoom = Object.values(
|
604
|
+
const callsInRoom = Object.values(this.state.extendedCalls).filter((call) => call.roomId === roomId);
|
569
605
|
if (callsInRoom.length !== 2)
|
570
606
|
return;
|
571
607
|
const firstCall = callsInRoom[0];
|
@@ -627,8 +663,9 @@ class OpenSIPSJS extends UA_1.default {
|
|
627
663
|
delete listenersCopy[value];
|
628
664
|
this.state.listeners = Object.assign({}, listenersCopy);
|
629
665
|
}
|
630
|
-
addCall(
|
666
|
+
addCall(event) {
|
631
667
|
return __awaiter(this, void 0, void 0, function* () {
|
668
|
+
const session = event.session;
|
632
669
|
const sessionAlreadyInActiveCalls = this.getActiveCalls[session.id];
|
633
670
|
if (sessionAlreadyInActiveCalls !== undefined) {
|
634
671
|
return;
|
@@ -656,6 +693,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
656
693
|
incomingInProgress: false,
|
657
694
|
roomId
|
658
695
|
});
|
696
|
+
this.deleteRoomIfEmpty(roomId);
|
659
697
|
}
|
660
698
|
});
|
661
699
|
}
|
@@ -663,11 +701,23 @@ class OpenSIPSJS extends UA_1.default {
|
|
663
701
|
this._startCallTimer(session.id);
|
664
702
|
}
|
665
703
|
const call = session;
|
704
|
+
const autoAnswerByHeaders = this.hasAutoAnswerHeaders(event);
|
705
|
+
const doAutoAnswer = call.direction === 'incoming' && !this.hasActiveCalls && (autoAnswerByHeaders || this.autoAnswer);
|
666
706
|
call.roomId = roomId;
|
667
707
|
call.localMuted = false;
|
668
|
-
|
708
|
+
call.autoAnswer = doAutoAnswer;
|
709
|
+
if (doAutoAnswer) {
|
710
|
+
this._addCall(call, false);
|
711
|
+
}
|
712
|
+
else {
|
713
|
+
this._addCall(call);
|
714
|
+
}
|
715
|
+
// this._addCall(call)
|
669
716
|
this._addCallStatus(session.id);
|
670
717
|
this._addRoom(newRoomInfo);
|
718
|
+
if (doAutoAnswer) {
|
719
|
+
this.callAnswer(call._id);
|
720
|
+
}
|
671
721
|
});
|
672
722
|
}
|
673
723
|
_triggerListener({ listenerType, session, event }) {
|
@@ -682,12 +732,15 @@ class OpenSIPSJS extends UA_1.default {
|
|
682
732
|
_removeCall(value) {
|
683
733
|
const stateActiveCallsCopy = Object.assign({}, this.state.activeCalls);
|
684
734
|
delete stateActiveCallsCopy[value];
|
685
|
-
delete activeCalls[value]
|
735
|
+
// delete activeCalls[value]
|
686
736
|
this.state.activeCalls = Object.assign({}, stateActiveCallsCopy);
|
737
|
+
const stateExtendedCallsCopy = Object.assign({}, this.state.extendedCalls);
|
738
|
+
delete stateExtendedCallsCopy[value];
|
739
|
+
this.state.extendedCalls = Object.assign({}, stateExtendedCallsCopy);
|
687
740
|
this.emit('changeActiveCalls', this.state.activeCalls);
|
688
741
|
}
|
689
742
|
_activeCallListRemove(call) {
|
690
|
-
const callRoomIdToConfigure =
|
743
|
+
const callRoomIdToConfigure = this.state.extendedCalls[call._id].roomId;
|
691
744
|
this._removeCall(call._id);
|
692
745
|
this.roomReconfigure(callRoomIdToConfigure);
|
693
746
|
}
|
@@ -701,11 +754,13 @@ class OpenSIPSJS extends UA_1.default {
|
|
701
754
|
session.on('ended', (event) => {
|
702
755
|
this._triggerListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_ENDED, session, event });
|
703
756
|
const s = this.getActiveCalls[session.id];
|
704
|
-
|
757
|
+
if (s) {
|
758
|
+
this._activeCallListRemove(s);
|
759
|
+
}
|
705
760
|
this._stopCallTimer(session.id);
|
706
761
|
this._removeCallStatus(session.id);
|
707
762
|
this._removeCallMetrics(session.id);
|
708
|
-
if (!Object.keys(
|
763
|
+
if (!Object.keys(this.state.extendedCalls).length) {
|
709
764
|
this.isMuted = false;
|
710
765
|
}
|
711
766
|
});
|
@@ -718,11 +773,13 @@ class OpenSIPSJS extends UA_1.default {
|
|
718
773
|
this.callAddingInProgress = undefined;
|
719
774
|
}
|
720
775
|
const s = this.getActiveCalls[session.id];
|
721
|
-
|
776
|
+
if (s) {
|
777
|
+
this._activeCallListRemove(s);
|
778
|
+
}
|
722
779
|
this._stopCallTimer(session.id);
|
723
780
|
this._removeCallStatus(session.id);
|
724
781
|
this._removeCallMetrics(session.id);
|
725
|
-
if (!Object.keys(
|
782
|
+
if (!Object.keys(this.state.extendedCalls).length) {
|
726
783
|
this.isMuted = false;
|
727
784
|
}
|
728
785
|
});
|
@@ -733,21 +790,25 @@ class OpenSIPSJS extends UA_1.default {
|
|
733
790
|
this.callAddingInProgress = undefined;
|
734
791
|
}
|
735
792
|
});
|
736
|
-
this.addCall(
|
793
|
+
this.addCall(event);
|
737
794
|
if (session.direction === 'outgoing') {
|
738
795
|
const roomId = this.getActiveCalls[session.id].roomId;
|
739
796
|
this.setCurrentActiveRoomId(roomId);
|
740
797
|
}
|
741
798
|
}
|
742
|
-
setInitialized() {
|
743
|
-
this.initialized =
|
744
|
-
this.emit('ready',
|
799
|
+
setInitialized(value) {
|
800
|
+
this.initialized = value;
|
801
|
+
this.emit('ready', value);
|
745
802
|
}
|
746
803
|
start() {
|
804
|
+
this.on(this.registeredEventName, () => {
|
805
|
+
this.setInitialized(true);
|
806
|
+
});
|
807
|
+
this.on(this.unregisteredEventName, () => {
|
808
|
+
this.setInitialized(false);
|
809
|
+
});
|
747
810
|
this.on(this.newRTCSessionEventName, this.newRTCSessionCallback.bind(this));
|
748
811
|
super.start();
|
749
|
-
this.setInitialized();
|
750
|
-
//this.setDefaultMediaDevices()
|
751
812
|
this.setMediaDevices(true);
|
752
813
|
return this;
|
753
814
|
}
|
@@ -834,8 +895,8 @@ class OpenSIPSJS extends UA_1.default {
|
|
834
895
|
}
|
835
896
|
callChangeRoom({ callId, roomId }) {
|
836
897
|
return __awaiter(this, void 0, void 0, function* () {
|
837
|
-
const oldRoomId =
|
838
|
-
|
898
|
+
const oldRoomId = this.state.extendedCalls[callId].roomId;
|
899
|
+
this.state.extendedCalls[callId].roomId = roomId;
|
839
900
|
yield this.setCurrentActiveRoomId(roomId);
|
840
901
|
return Promise.all([
|
841
902
|
this.roomReconfigure(oldRoomId),
|
package/package.json
CHANGED
package/src/types/rtc.d.ts
CHANGED
@@ -75,6 +75,7 @@ export interface ICall extends RTCSessionExtended {
|
|
75
75
|
localMuted?: boolean
|
76
76
|
localHold?: boolean
|
77
77
|
audioTag?: StreamMediaType
|
78
|
+
autoAnswer?: boolean
|
78
79
|
}
|
79
80
|
|
80
81
|
export type RoomChangeEmitType = {
|
@@ -137,4 +138,4 @@ export interface CallOptionsExtended extends AnswerOptionsExtended {
|
|
137
138
|
anonymous?: boolean;
|
138
139
|
fromUserName?: string;
|
139
140
|
fromDisplayName?: string;
|
140
|
-
}
|
141
|
+
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
export declare class MSRPMessage {
|
2
|
-
protocol: string;
|
3
|
-
ident: null;
|
4
|
-
code: null;
|
5
|
-
method: null;
|
6
|
-
headers: any;
|
7
|
-
body: string;
|
8
|
-
challenge: null;
|
9
|
-
constructor(msg: string);
|
10
|
-
addHeader(name: string, content: string): void;
|
11
|
-
getHeader(name: string): any;
|
12
|
-
toString(): string;
|
13
|
-
}
|
@@ -1,65 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.MSRPMessage = void 0;
|
7
|
-
const Utils_1 = __importDefault(require("jssip/lib/Utils"));
|
8
|
-
class MSRPMessage {
|
9
|
-
constructor(msg) {
|
10
|
-
this.protocol = '';
|
11
|
-
this.ident = null;
|
12
|
-
this.code = null;
|
13
|
-
this.method = null;
|
14
|
-
this.headers = {};
|
15
|
-
this.body = '';
|
16
|
-
this.challenge = null;
|
17
|
-
if (msg.length > 0) {
|
18
|
-
let _hasBody = false;
|
19
|
-
const msgLines = msg.split('\r\n');
|
20
|
-
const msgHeadLineArray = msgLines.shift().split(/\s/);
|
21
|
-
this.protocol = msgHeadLineArray[0];
|
22
|
-
this.ident = msgHeadLineArray[1];
|
23
|
-
this.code = (msgHeadLineArray.length > 3) ? msgHeadLineArray[2] : null;
|
24
|
-
this.method = (msgHeadLineArray.length > 3) ? msgHeadLineArray[3] : msgHeadLineArray[2];
|
25
|
-
for (const msgLine of msgLines) {
|
26
|
-
if (msgLine == `-------${this.ident}$`) {
|
27
|
-
break;
|
28
|
-
}
|
29
|
-
if (msgLine === '') {
|
30
|
-
_hasBody = true;
|
31
|
-
continue;
|
32
|
-
}
|
33
|
-
if (_hasBody) {
|
34
|
-
this.body += msgLine + '\r\n';
|
35
|
-
}
|
36
|
-
else {
|
37
|
-
const msgLineArray = msgLine.split(': ');
|
38
|
-
this.addHeader(msgLineArray[0], msgLineArray[1].trim());
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
else {
|
43
|
-
this.ident = Utils_1.default.createRandomToken(12);
|
44
|
-
this.protocol = 'MSRP';
|
45
|
-
}
|
46
|
-
}
|
47
|
-
addHeader(name, content) {
|
48
|
-
this.headers[name] = content;
|
49
|
-
}
|
50
|
-
getHeader(name) {
|
51
|
-
return this.headers[name];
|
52
|
-
}
|
53
|
-
toString() {
|
54
|
-
let _msg = `${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s/ig, '') + '\r\n';
|
55
|
-
for (const _header in this.headers) {
|
56
|
-
_msg += `${_header}: ${this.headers[_header]}\r\n`;
|
57
|
-
}
|
58
|
-
if (this.body) {
|
59
|
-
_msg += '\r\n' + this.body;
|
60
|
-
}
|
61
|
-
_msg += `-------${this.ident}$\r\n`;
|
62
|
-
return _msg;
|
63
|
-
}
|
64
|
-
}
|
65
|
-
exports.MSRPMessage = MSRPMessage;
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { UA } from 'jssip';
|
2
|
-
export declare class MSRPSession {
|
3
|
-
_ua: UA;
|
4
|
-
_request: any;
|
5
|
-
credentials: any;
|
6
|
-
webSocket: any;
|
7
|
-
status: string;
|
8
|
-
target: string;
|
9
|
-
message: string;
|
10
|
-
constructor(ua: UA);
|
11
|
-
connect(): void;
|
12
|
-
authenticate(auth: any): void;
|
13
|
-
onmessage(msg: any): void;
|
14
|
-
onclose(): void;
|
15
|
-
onopen(): void;
|
16
|
-
onerror(): void;
|
17
|
-
stop(): void;
|
18
|
-
inviteParty(smgObj: any): void;
|
19
|
-
send(target: string, message: string): void;
|
20
|
-
parseAuth(content: string): any;
|
21
|
-
}
|
@@ -1,130 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.MSRPSession = void 0;
|
7
|
-
const Utils_1 = __importDefault(require("jssip/lib/Utils"));
|
8
|
-
const RequestSender_1 = __importDefault(require("jssip/lib/RequestSender"));
|
9
|
-
const DigestAuthentication_1 = __importDefault(require("jssip/lib/DigestAuthentication"));
|
10
|
-
const message_1 = require("@/lib/msrp/message");
|
11
|
-
const URI_1 = __importDefault(require("jssip/lib/URI"));
|
12
|
-
const SIPMessage_1 = __importDefault(require("jssip/lib/SIPMessage"));
|
13
|
-
class MSRPSession {
|
14
|
-
constructor(ua) {
|
15
|
-
this._ua = ua;
|
16
|
-
this.credentials = {
|
17
|
-
'username': ua._configuration.authorization_user,
|
18
|
-
'ha1': ua._configuration.ha1,
|
19
|
-
'realm': ua._configuration.realm,
|
20
|
-
'msrprelay': 'msrp://sip06.voicenter.co:2856;ws',
|
21
|
-
'msrpurl': 'ws://sip06.voicenter.co:2856'
|
22
|
-
};
|
23
|
-
this.status = 'new';
|
24
|
-
this.target = '';
|
25
|
-
this.message = '';
|
26
|
-
}
|
27
|
-
connect() {
|
28
|
-
this.webSocket = new WebSocket(this.credentials.msrpurl, 'msrp');
|
29
|
-
this.webSocket.binaryType = 'arraybuffer';
|
30
|
-
this.webSocket.onopen = () => {
|
31
|
-
this.onopen();
|
32
|
-
};
|
33
|
-
this.webSocket.onclose = () => {
|
34
|
-
this.onclose();
|
35
|
-
};
|
36
|
-
this.webSocket.onmessage = (msg) => {
|
37
|
-
this.onmessage(msg);
|
38
|
-
};
|
39
|
-
this.webSocket.onerror = () => {
|
40
|
-
this.onerror();
|
41
|
-
};
|
42
|
-
}
|
43
|
-
authenticate(auth) {
|
44
|
-
this.status = 'auth';
|
45
|
-
const msgObj = new message_1.MSRPMessage('');
|
46
|
-
msgObj.method = 'AUTH';
|
47
|
-
msgObj.addHeader('To-Path', this.credentials.msrprelay);
|
48
|
-
msgObj.addHeader('From-Path', 'msrp://' + this.credentials.username + '.sip06.voicenter.co:2856/' + msgObj.ident + ';ws');
|
49
|
-
if (auth) {
|
50
|
-
msgObj.addHeader('Authorization', auth.toString());
|
51
|
-
}
|
52
|
-
this.webSocket.send(msgObj.toString());
|
53
|
-
}
|
54
|
-
onmessage(msg) {
|
55
|
-
const msgObj = new message_1.MSRPMessage(msg.data);
|
56
|
-
if (this.status == 'auth' && msgObj.code === '401') {
|
57
|
-
const _challenge = this.parseAuth(msgObj.getHeader('WWW-Authenticate'));
|
58
|
-
const digestAuthentication = new DigestAuthentication_1.default(this.credentials);
|
59
|
-
digestAuthentication.authenticate({ method: 'AUTH', ruri: this.credentials.msrprelay, body: null }, _challenge, Utils_1.default.createRandomToken(12));
|
60
|
-
this.authenticate(digestAuthentication);
|
61
|
-
}
|
62
|
-
if (this.status == 'auth' && msgObj.code === '200') {
|
63
|
-
this.status = 'ready';
|
64
|
-
this.inviteParty(msgObj);
|
65
|
-
// console.log(msgObj)
|
66
|
-
}
|
67
|
-
}
|
68
|
-
onclose() {
|
69
|
-
console.log('close');
|
70
|
-
}
|
71
|
-
onopen() {
|
72
|
-
this.authenticate(null);
|
73
|
-
}
|
74
|
-
onerror() {
|
75
|
-
}
|
76
|
-
stop() {
|
77
|
-
this.webSocket.close();
|
78
|
-
}
|
79
|
-
inviteParty(smgObj) {
|
80
|
-
const requestParams = {};
|
81
|
-
const extraHeaders = [];
|
82
|
-
requestParams.from_uri = new URI_1.default('sip', this._ua._configuration.uri.user, this._ua.configuration.uri.host);
|
83
|
-
requestParams.to_uri = new URI_1.default('sip', this.target, this._ua._configuration.realm);
|
84
|
-
extraHeaders.push(`P-Preferred-Identity: ${this._ua._configuration.uri.toString()}`);
|
85
|
-
extraHeaders.push(`Contact: ${this._ua.contact.toString({
|
86
|
-
outbound: true
|
87
|
-
})}`);
|
88
|
-
extraHeaders.push('Content-Type: application/sdp');
|
89
|
-
const request = new SIPMessage_1.default.InitialOutgoingInviteRequest(this._ua.normalizeTarget(this.target), this._ua, requestParams, extraHeaders, 'v=0\n' +
|
90
|
-
'o=- 4232740119537112802 2 IN IP4 185.138.168.169\n' +
|
91
|
-
'c=IN IP4 185.138.168.169\n' +
|
92
|
-
't=0 0\n' +
|
93
|
-
'm=message 2855 TCP/TLS/MSRP *\n' +
|
94
|
-
'a=accept-types:text/plain text/html\n' +
|
95
|
-
'a=path:' + smgObj.getHeader('Use-Path') + '\n');
|
96
|
-
const request_sender = new RequestSender_1.default(this._ua, request, {
|
97
|
-
onRequestTimeout: () => {
|
98
|
-
console.log('to');
|
99
|
-
},
|
100
|
-
onTransportError: (err) => {
|
101
|
-
console.log(err);
|
102
|
-
},
|
103
|
-
// Update the request on authentication.
|
104
|
-
onAuthenticated: (request) => {
|
105
|
-
this._request = request;
|
106
|
-
},
|
107
|
-
onReceiveResponse: (response) => {
|
108
|
-
console.log(response);
|
109
|
-
}
|
110
|
-
});
|
111
|
-
request_sender.send();
|
112
|
-
}
|
113
|
-
send(target, message) {
|
114
|
-
this.target = target;
|
115
|
-
this.message = message;
|
116
|
-
if (this.status == 'new') {
|
117
|
-
this.connect();
|
118
|
-
}
|
119
|
-
}
|
120
|
-
parseAuth(content) {
|
121
|
-
const _challenge = {};
|
122
|
-
const _challengeArray = content.replace('Digest', '').split(',');
|
123
|
-
for (const _authItem of _challengeArray) {
|
124
|
-
const _itemArray = _authItem.trim().split('=');
|
125
|
-
_challenge[_itemArray[0]] = _itemArray[1].match('^"(.+)"$')[1];
|
126
|
-
}
|
127
|
-
return _challenge;
|
128
|
-
}
|
129
|
-
}
|
130
|
-
exports.MSRPSession = MSRPSession;
|