@voicenter-team/opensips-js 1.0.17 → 1.0.18
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/build/helpers/UA/index.d.ts +2 -0
- package/build/helpers/UA/index.js +6 -0
- package/build/index.d.ts +3 -12
- package/build/index.js +40 -89
- package/build/lib/msrp/message.d.ts +13 -0
- package/build/lib/msrp/message.js +65 -0
- package/build/lib/msrp/session.d.ts +21 -0
- package/build/lib/msrp/session.js +130 -0
- package/package.json +2 -2
- package/build/enum/session.direction.enum.d.ts +0 -2
- package/build/enum/session.direction.enum.js +0 -5
- package/build/helpers/jssip.d.ts +0 -5
- package/build/helpers/jssip.js +0 -30
@@ -1,6 +1,8 @@
|
|
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';
|
4
5
|
export default class UAExtended extends UA {
|
5
6
|
call(target: string, options?: CallOptionsExtended): RTCSession;
|
7
|
+
sendMSRPMessage(target: string, options: string): MSRPSession;
|
6
8
|
}
|
@@ -1,9 +1,15 @@
|
|
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");
|
4
5
|
class UAExtended extends jssip_1.UA {
|
5
6
|
call(target, options) {
|
6
7
|
return super.call(target, options);
|
7
8
|
}
|
9
|
+
sendMSRPMessage(target, options) {
|
10
|
+
const session = new session_1.MSRPSession(this);
|
11
|
+
session.send(target, options);
|
12
|
+
return session;
|
13
|
+
}
|
8
14
|
}
|
9
15
|
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,9 +12,6 @@ export interface InnerState {
|
|
12
12
|
activeCalls: {
|
13
13
|
[key: string]: ICall;
|
14
14
|
};
|
15
|
-
extendedCalls: {
|
16
|
-
[key: string]: ICall;
|
17
|
-
};
|
18
15
|
activeRooms: {
|
19
16
|
[key: number]: IRoom;
|
20
17
|
};
|
@@ -41,16 +38,12 @@ export interface InnerState {
|
|
41
38
|
[key: string]: Array<(call: RTCSessionExtended, event: ListenerEventType | undefined) => void>;
|
42
39
|
};
|
43
40
|
metricConfig: WebrtcMetricsConfigType;
|
44
|
-
isAutoAnswer: boolean;
|
45
41
|
}
|
46
42
|
declare class OpenSIPSJS extends UA {
|
47
43
|
private initialized;
|
48
44
|
private readonly options;
|
49
45
|
private readonly newRTCSessionEventName;
|
50
|
-
private readonly registeredEventName;
|
51
|
-
private readonly unregisteredEventName;
|
52
46
|
private readonly activeCalls;
|
53
|
-
private readonly extendedCalls;
|
54
47
|
private _currentActiveRoomId;
|
55
48
|
private _callAddingInProgress;
|
56
49
|
private state;
|
@@ -74,8 +67,6 @@ declare class OpenSIPSJS extends UA {
|
|
74
67
|
};
|
75
68
|
get currentActiveRoomId(): number | undefined;
|
76
69
|
private set currentActiveRoomId(value);
|
77
|
-
get autoAnswer(): boolean;
|
78
|
-
set autoAnswer(value: boolean);
|
79
70
|
get callAddingInProgress(): string | undefined;
|
80
71
|
private set callAddingInProgress(value);
|
81
72
|
get muteWhenJoin(): boolean;
|
@@ -122,7 +113,7 @@ declare class OpenSIPSJS extends UA {
|
|
122
113
|
setMetricsConfig(config: WebrtcMetricsConfigType): void;
|
123
114
|
sendDTMF(callId: string, value: string): void;
|
124
115
|
doMute(value: boolean): void;
|
125
|
-
|
116
|
+
sendMSRP(target: string | JsSIP.URI, body: string, options?: SendMessageOptions): import("jssip/lib/Message").Message;
|
126
117
|
doCallHold({ callId, toHold, automatic }: {
|
127
118
|
callId: string;
|
128
119
|
toHold: boolean;
|
package/build/index.js
CHANGED
@@ -13,34 +13,30 @@ 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 = {};
|
29
30
|
class OpenSIPSJS extends UA_1.default {
|
30
31
|
constructor(options) {
|
31
32
|
const configuration = Object.assign(Object.assign({}, options.configuration), { sockets: options.socketInterfaces.map(sock => new jssip_1.default.WebSocketInterface(sock)) });
|
32
33
|
super(configuration);
|
33
34
|
this.initialized = false;
|
34
35
|
this.newRTCSessionEventName = 'newRTCSession';
|
35
|
-
this.registeredEventName = 'registered';
|
36
|
-
this.unregisteredEventName = 'unregistered';
|
37
36
|
this.activeCalls = {};
|
38
|
-
this.extendedCalls = {};
|
39
37
|
this.state = {
|
40
38
|
isMuted: false,
|
41
|
-
isAutoAnswer: false,
|
42
39
|
activeCalls: {},
|
43
|
-
extendedCalls: {},
|
44
40
|
availableMediaDevices: [],
|
45
41
|
selectedMediaDevices: {
|
46
42
|
input: 'default',
|
@@ -86,12 +82,6 @@ class OpenSIPSJS extends UA_1.default {
|
|
86
82
|
this._currentActiveRoomId = roomId;
|
87
83
|
this.emit('currentActiveRoomChanged', roomId);
|
88
84
|
}
|
89
|
-
get autoAnswer() {
|
90
|
-
return this.state.isAutoAnswer;
|
91
|
-
}
|
92
|
-
set autoAnswer(value) {
|
93
|
-
this.state.isAutoAnswer = value;
|
94
|
-
}
|
95
85
|
get callAddingInProgress() {
|
96
86
|
return this._callAddingInProgress;
|
97
87
|
}
|
@@ -118,7 +108,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
118
108
|
}
|
119
109
|
set speakerVolume(value) {
|
120
110
|
this.state.speakerVolume = value;
|
121
|
-
Object.values(
|
111
|
+
Object.values(activeCalls).forEach((call) => {
|
122
112
|
if (call.audioTag) {
|
123
113
|
call.audioTag.volume = value;
|
124
114
|
}
|
@@ -251,7 +241,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
251
241
|
if (!validation_regex.test(value)) {
|
252
242
|
throw new Error('Not allowed character in DTMF input');
|
253
243
|
}
|
254
|
-
const call =
|
244
|
+
const call = activeCalls[callId];
|
255
245
|
call.sendDTMF(value);
|
256
246
|
}
|
257
247
|
doMute(value) {
|
@@ -259,11 +249,12 @@ class OpenSIPSJS extends UA_1.default {
|
|
259
249
|
this.isMuted = value;
|
260
250
|
this.roomReconfigure(activeRoomId);
|
261
251
|
}
|
262
|
-
|
252
|
+
sendMSRP(target, body, options) {
|
253
|
+
super.sendMSRPMessage(`sip:${target}@${this.sipDomain}`, body);
|
263
254
|
return super.sendMessage(`sip:${target}@${this.sipDomain}`, body, options);
|
264
255
|
}
|
265
256
|
doCallHold({ callId, toHold, automatic }) {
|
266
|
-
const call =
|
257
|
+
const call = activeCalls[callId];
|
267
258
|
call._automaticHold = automatic !== null && automatic !== void 0 ? automatic : false;
|
268
259
|
if (toHold) {
|
269
260
|
call.hold();
|
@@ -279,7 +270,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
279
270
|
}).forEach(call => this.callTerminate(call._id));
|
280
271
|
}
|
281
272
|
callAnswer(callId) {
|
282
|
-
const call =
|
273
|
+
const call = activeCalls[callId];
|
283
274
|
this._cancelAllOutgoingUnanswered();
|
284
275
|
call.answer(this.sipOptions);
|
285
276
|
this.updateCall(call);
|
@@ -306,16 +297,10 @@ class OpenSIPSJS extends UA_1.default {
|
|
306
297
|
this.state.activeRooms = Object.assign(Object.assign({}, this.state.activeRooms), { [value.roomId]: Object.assign({}, newRoomData) });
|
307
298
|
this.emit('updateRoom', { room: newRoomData, roomList: this.state.activeRooms });
|
308
299
|
}
|
309
|
-
_addCall(value
|
300
|
+
_addCall(value) {
|
310
301
|
this.state.activeCalls = Object.assign(Object.assign({}, this.state.activeCalls), { [value._id]: (0, audio_helper_1.simplifyCallObject)(value) });
|
311
|
-
|
312
|
-
|
313
|
-
[value._id]: value
|
314
|
-
}*/
|
315
|
-
this.state.extendedCalls[value._id] = value;
|
316
|
-
if (emitEvent) {
|
317
|
-
this.emit('changeActiveCalls', this.state.activeCalls);
|
318
|
-
}
|
302
|
+
activeCalls[value._id] = value;
|
303
|
+
this.emit('changeActiveCalls', this.state.activeCalls);
|
319
304
|
}
|
320
305
|
_addCallStatus(callId) {
|
321
306
|
this.state.callStatus = Object.assign(Object.assign({}, this.state.callStatus), { [callId]: {
|
@@ -323,7 +308,6 @@ class OpenSIPSJS extends UA_1.default {
|
|
323
308
|
isTransferring: false,
|
324
309
|
isMerging: false
|
325
310
|
} });
|
326
|
-
this.emit('changeCallStatus', this.state.callStatus);
|
327
311
|
}
|
328
312
|
_updateCallStatus(value) {
|
329
313
|
const prevStatus = Object.assign({}, this.state.callStatus[value.callId]);
|
@@ -338,13 +322,11 @@ class OpenSIPSJS extends UA_1.default {
|
|
338
322
|
newStatus.isMerging = value.isMerging;
|
339
323
|
}
|
340
324
|
this.state.callStatus = Object.assign(Object.assign({}, this.state.callStatus), { [value.callId]: Object.assign({}, newStatus) });
|
341
|
-
this.emit('changeCallStatus', this.state.callStatus);
|
342
325
|
}
|
343
326
|
_removeCallStatus(callId) {
|
344
327
|
const callStatusCopy = Object.assign({}, this.state.callStatus);
|
345
328
|
delete callStatusCopy[callId];
|
346
329
|
this.state.callStatus = Object.assign({}, callStatusCopy);
|
347
|
-
this.emit('changeCallStatus', this.state.callStatus);
|
348
330
|
}
|
349
331
|
_addRoom(value) {
|
350
332
|
this.state.activeRooms = Object.assign(Object.assign({}, this.state.activeRooms), { [value.roomId]: value });
|
@@ -366,7 +348,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
366
348
|
if (Object.keys(this.getActiveCalls).length === 0) {
|
367
349
|
return;
|
368
350
|
}
|
369
|
-
const callsInCurrentRoom = Object.values(
|
351
|
+
const callsInCurrentRoom = Object.values(activeCalls).filter(call => call.roomId === this.currentActiveRoomId);
|
370
352
|
if (callsInCurrentRoom.length === 1) {
|
371
353
|
Object.values(callsInCurrentRoom).forEach(call => {
|
372
354
|
const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
|
@@ -391,7 +373,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
391
373
|
return;
|
392
374
|
}
|
393
375
|
this.selectedOutputDevice = dId;
|
394
|
-
const activeCallList = Object.values(
|
376
|
+
const activeCallList = Object.values(activeCalls);
|
395
377
|
if (activeCallList.length === 0) {
|
396
378
|
return;
|
397
379
|
}
|
@@ -419,10 +401,10 @@ class OpenSIPSJS extends UA_1.default {
|
|
419
401
|
if (roomId === undefined) {
|
420
402
|
return;
|
421
403
|
}
|
422
|
-
if (Object.values(
|
404
|
+
if (Object.values(activeCalls).filter(call => call.roomId === roomId).length === 0) {
|
423
405
|
this.removeRoom(roomId);
|
424
406
|
if (this.currentActiveRoomId === roomId) {
|
425
|
-
this.currentActiveRoomId =
|
407
|
+
this.currentActiveRoomId = roomId;
|
426
408
|
}
|
427
409
|
}
|
428
410
|
}
|
@@ -444,7 +426,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
444
426
|
if (roomId === undefined) {
|
445
427
|
return;
|
446
428
|
}
|
447
|
-
const callsInRoom = Object.values(
|
429
|
+
const callsInRoom = Object.values(activeCalls).filter(call => call.roomId === roomId);
|
448
430
|
// Let`s take care on the audio output first and check if passed room is our selected room
|
449
431
|
if (this.currentActiveRoomId === roomId) {
|
450
432
|
callsInRoom.forEach(call => {
|
@@ -557,7 +539,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
557
539
|
}
|
558
540
|
}
|
559
541
|
muteCaller(callId, value) {
|
560
|
-
const call =
|
542
|
+
const call = activeCalls[callId];
|
561
543
|
if (call && call.connection.getReceivers().length) {
|
562
544
|
call.localMuted = value;
|
563
545
|
call.connection.getReceivers().forEach((receiver) => {
|
@@ -568,7 +550,7 @@ class OpenSIPSJS extends UA_1.default {
|
|
568
550
|
}
|
569
551
|
}
|
570
552
|
callTerminate(callId) {
|
571
|
-
const call =
|
553
|
+
const call = activeCalls[callId];
|
572
554
|
if (call._status !== 8) {
|
573
555
|
call.terminate();
|
574
556
|
}
|
@@ -577,22 +559,13 @@ class OpenSIPSJS extends UA_1.default {
|
|
577
559
|
if (target.toString().length === 0) {
|
578
560
|
return console.error('Target must be passed');
|
579
561
|
}
|
580
|
-
const call = this.state.extendedCalls[callId];
|
581
|
-
if (!call._is_confirmed && !call._is_canceled) {
|
582
|
-
const redirectTarget = `sip:${target}@${this.sipDomain}`;
|
583
|
-
call.terminate({
|
584
|
-
status_code: 302,
|
585
|
-
reason_phrase: 'Moved Temporarily',
|
586
|
-
extraHeaders: [`Contact: ${redirectTarget}`]
|
587
|
-
});
|
588
|
-
return;
|
589
|
-
}
|
590
562
|
this._updateCallStatus({ callId, isTransferring: true });
|
563
|
+
const call = activeCalls[callId];
|
591
564
|
call.refer(`sip:${target}@${this.sipDomain}`);
|
592
565
|
this.updateCall(call);
|
593
566
|
}
|
594
567
|
callMerge(roomId) {
|
595
|
-
const callsInRoom = Object.values(
|
568
|
+
const callsInRoom = Object.values(activeCalls).filter((call) => call.roomId === roomId);
|
596
569
|
if (callsInRoom.length !== 2)
|
597
570
|
return;
|
598
571
|
const firstCall = callsInRoom[0];
|
@@ -683,7 +656,6 @@ class OpenSIPSJS extends UA_1.default {
|
|
683
656
|
incomingInProgress: false,
|
684
657
|
roomId
|
685
658
|
});
|
686
|
-
this.deleteRoomIfEmpty(roomId);
|
687
659
|
}
|
688
660
|
});
|
689
661
|
}
|
@@ -693,19 +665,9 @@ class OpenSIPSJS extends UA_1.default {
|
|
693
665
|
const call = session;
|
694
666
|
call.roomId = roomId;
|
695
667
|
call.localMuted = false;
|
696
|
-
|
697
|
-
if (doAutoAnswer) {
|
698
|
-
this._addCall(call, false);
|
699
|
-
}
|
700
|
-
else {
|
701
|
-
this._addCall(call);
|
702
|
-
}
|
703
|
-
// this._addCall(call)
|
668
|
+
this._addCall(call);
|
704
669
|
this._addCallStatus(session.id);
|
705
670
|
this._addRoom(newRoomInfo);
|
706
|
-
if (doAutoAnswer) {
|
707
|
-
this.callAnswer(call._id);
|
708
|
-
}
|
709
671
|
});
|
710
672
|
}
|
711
673
|
_triggerListener({ listenerType, session, event }) {
|
@@ -720,15 +682,12 @@ class OpenSIPSJS extends UA_1.default {
|
|
720
682
|
_removeCall(value) {
|
721
683
|
const stateActiveCallsCopy = Object.assign({}, this.state.activeCalls);
|
722
684
|
delete stateActiveCallsCopy[value];
|
723
|
-
|
685
|
+
delete activeCalls[value];
|
724
686
|
this.state.activeCalls = Object.assign({}, stateActiveCallsCopy);
|
725
|
-
const stateExtendedCallsCopy = Object.assign({}, this.state.extendedCalls);
|
726
|
-
delete stateExtendedCallsCopy[value];
|
727
|
-
this.state.extendedCalls = Object.assign({}, stateExtendedCallsCopy);
|
728
687
|
this.emit('changeActiveCalls', this.state.activeCalls);
|
729
688
|
}
|
730
689
|
_activeCallListRemove(call) {
|
731
|
-
const callRoomIdToConfigure =
|
690
|
+
const callRoomIdToConfigure = activeCalls[call._id].roomId;
|
732
691
|
this._removeCall(call._id);
|
733
692
|
this.roomReconfigure(callRoomIdToConfigure);
|
734
693
|
}
|
@@ -742,13 +701,11 @@ class OpenSIPSJS extends UA_1.default {
|
|
742
701
|
session.on('ended', (event) => {
|
743
702
|
this._triggerListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_ENDED, session, event });
|
744
703
|
const s = this.getActiveCalls[session.id];
|
745
|
-
|
746
|
-
this._activeCallListRemove(s);
|
747
|
-
}
|
704
|
+
this._activeCallListRemove(s);
|
748
705
|
this._stopCallTimer(session.id);
|
749
706
|
this._removeCallStatus(session.id);
|
750
707
|
this._removeCallMetrics(session.id);
|
751
|
-
if (!Object.keys(
|
708
|
+
if (!Object.keys(activeCalls).length) {
|
752
709
|
this.isMuted = false;
|
753
710
|
}
|
754
711
|
});
|
@@ -761,13 +718,11 @@ class OpenSIPSJS extends UA_1.default {
|
|
761
718
|
this.callAddingInProgress = undefined;
|
762
719
|
}
|
763
720
|
const s = this.getActiveCalls[session.id];
|
764
|
-
|
765
|
-
this._activeCallListRemove(s);
|
766
|
-
}
|
721
|
+
this._activeCallListRemove(s);
|
767
722
|
this._stopCallTimer(session.id);
|
768
723
|
this._removeCallStatus(session.id);
|
769
724
|
this._removeCallMetrics(session.id);
|
770
|
-
if (!Object.keys(
|
725
|
+
if (!Object.keys(activeCalls).length) {
|
771
726
|
this.isMuted = false;
|
772
727
|
}
|
773
728
|
});
|
@@ -784,19 +739,15 @@ class OpenSIPSJS extends UA_1.default {
|
|
784
739
|
this.setCurrentActiveRoomId(roomId);
|
785
740
|
}
|
786
741
|
}
|
787
|
-
setInitialized(
|
788
|
-
this.initialized =
|
789
|
-
this.emit('ready',
|
742
|
+
setInitialized() {
|
743
|
+
this.initialized = true;
|
744
|
+
this.emit('ready', true);
|
790
745
|
}
|
791
746
|
start() {
|
792
|
-
this.on(this.registeredEventName, () => {
|
793
|
-
this.setInitialized(true);
|
794
|
-
});
|
795
|
-
this.on(this.unregisteredEventName, () => {
|
796
|
-
this.setInitialized(false);
|
797
|
-
});
|
798
747
|
this.on(this.newRTCSessionEventName, this.newRTCSessionCallback.bind(this));
|
799
748
|
super.start();
|
749
|
+
this.setInitialized();
|
750
|
+
//this.setDefaultMediaDevices()
|
800
751
|
this.setMediaDevices(true);
|
801
752
|
return this;
|
802
753
|
}
|
@@ -883,8 +834,8 @@ class OpenSIPSJS extends UA_1.default {
|
|
883
834
|
}
|
884
835
|
callChangeRoom({ callId, roomId }) {
|
885
836
|
return __awaiter(this, void 0, void 0, function* () {
|
886
|
-
const oldRoomId =
|
887
|
-
|
837
|
+
const oldRoomId = activeCalls[callId].roomId;
|
838
|
+
activeCalls[callId].roomId = roomId;
|
888
839
|
yield this.setCurrentActiveRoomId(roomId);
|
889
840
|
return Promise.all([
|
890
841
|
this.roomReconfigure(oldRoomId),
|
@@ -0,0 +1,13 @@
|
|
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
|
+
}
|
@@ -0,0 +1,65 @@
|
|
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;
|
@@ -0,0 +1,21 @@
|
|
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
|
+
}
|
@@ -0,0 +1,130 @@
|
|
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;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@voicenter-team/opensips-js",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.18",
|
4
4
|
"description": "The JS package for opensips",
|
5
5
|
"default": "src/index.ts",
|
6
6
|
"main": "build/index.js",
|
@@ -42,7 +42,7 @@
|
|
42
42
|
"regenerator-runtime": "^0.13.11",
|
43
43
|
"tsc-alias": "^1.8.6",
|
44
44
|
"typescript": "^4.9.5",
|
45
|
-
"vite": "
|
45
|
+
"vite": "4.3.9",
|
46
46
|
"vite-plugin-singlefile": "^0.13.5",
|
47
47
|
"vue": "3.2.25"
|
48
48
|
},
|
@@ -1,5 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SessionDirection = void 0;
|
4
|
-
const RTCSession_1 = require("jssip/lib/RTCSession");
|
5
|
-
Object.defineProperty(exports, "SessionDirection", { enumerable: true, get: function () { return RTCSession_1.SessionDirection; } });
|
package/build/helpers/jssip.d.ts
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
import JsSIP, { UA } from 'jssip';
|
2
|
-
import { IncomingAckEvent, IncomingEvent, OutgoingAckEvent, OutgoingEvent } from 'jssip/lib/RTCSession';
|
3
|
-
import { RTCSessionEvent, UAConfiguration, UAEventMap } from 'jssip/lib/UA';
|
4
|
-
export default JsSIP;
|
5
|
-
export { UA, IncomingAckEvent, IncomingEvent, OutgoingAckEvent, OutgoingEvent, RTCSessionEvent, UAConfiguration, UAEventMap };
|
package/build/helpers/jssip.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.UA = void 0;
|
27
|
-
// @ts-nocheck
|
28
|
-
const jssip_1 = __importStar(require("jssip"));
|
29
|
-
Object.defineProperty(exports, "UA", { enumerable: true, get: function () { return jssip_1.UA; } });
|
30
|
-
exports.default = jssip_1.default;
|