@voicenter-team/opensips-js 1.0.20 → 1.0.22

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.
@@ -0,0 +1,5 @@
1
+ export declare const MESSAGE_EVENT_LISTENER_TYPE: {
2
+ ACTIVE: string;
3
+ FAILED: string;
4
+ ENDED: string;
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MESSAGE_EVENT_LISTENER_TYPE = void 0;
4
+ exports.MESSAGE_EVENT_LISTENER_TYPE = {
5
+ ACTIVE: 'active',
6
+ FAILED: 'failed',
7
+ ENDED: 'ended'
8
+ };
@@ -0,0 +1,2 @@
1
+ import { SessionDirection } from 'jssip/lib/RTCSession';
2
+ export { SessionDirection };
@@ -0,0 +1,5 @@
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; } });
@@ -1,6 +1,41 @@
1
- import { UA } from 'jssip';
1
+ import { MSRPOptions, UAConfiguration, UA as UAType } from 'jssip';
2
+ import { Originator, RTCSession } from 'jssip/lib/RTCSession';
3
+ import { IncomingRequest } from 'jssip/lib/SIPMessage';
4
+ import { MSRPSession } from '../../lib/msrp/session';
2
5
  import { CallOptionsExtended } from '@/types/rtc';
3
- import { RTCSession } from 'jssip/lib/RTCSession';
4
- export default class UAExtended extends UA {
6
+ export interface IncomingMSRPSessionEvent {
7
+ originator: Originator.REMOTE;
8
+ session: MSRPSession;
9
+ request: IncomingRequest;
10
+ }
11
+ export interface OutgoingMSRPSessionEvent {
12
+ originator: Originator.LOCAL;
13
+ session: MSRPSession;
14
+ request: IncomingRequest;
15
+ }
16
+ export type MSRPSessionEvent = IncomingMSRPSessionEvent | OutgoingMSRPSessionEvent;
17
+ declare const UAConstructor: typeof UAType;
18
+ export default class UAExtended extends UAConstructor {
19
+ _msrp_sessions: MSRPSession[];
20
+ _transactions: {
21
+ nist: {};
22
+ nict: {};
23
+ ist: {};
24
+ ict: {};
25
+ };
26
+ constructor(configuration: UAConfiguration);
5
27
  call(target: string, options?: CallOptionsExtended): RTCSession;
28
+ /**
29
+ * new MSRPSession
30
+ */
31
+ newMSRPSession(session: MSRPSession, data: object): void;
32
+ /**
33
+ * MSRPSession destroyed.
34
+ */
35
+ destroyMSRPSession(session: MSRPSession): void;
36
+ receiveRequest(request: any): void;
37
+ startMSRP(target: string, options: MSRPOptions): MSRPSession;
38
+ terminateMSRPSessions(options: object): void;
39
+ stop(): void;
6
40
  }
41
+ export {};
@@ -1,9 +1,318 @@
1
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
29
  const jssip_1 = require("jssip");
4
- class UAExtended extends jssip_1.UA {
30
+ const UA_1 = __importDefault(require("jssip/lib/UA"));
31
+ const JsSIP_C = __importStar(require("jssip/lib/Constants"));
32
+ const Transactions_1 = __importDefault(require("jssip/lib/Transactions"));
33
+ const session_1 = require("../../lib/msrp/session");
34
+ const logger = console;
35
+ const C = {
36
+ // UA status codes.
37
+ STATUS_INIT: 0,
38
+ STATUS_READY: 1,
39
+ STATUS_USER_CLOSED: 2,
40
+ STATUS_NOT_READY: 3,
41
+ // UA error codes.
42
+ CONFIGURATION_ERROR: 1,
43
+ NETWORK_ERROR: 2
44
+ };
45
+ const UAConstructor = UA_1.default;
46
+ class UAExtended extends UAConstructor {
47
+ constructor(configuration) {
48
+ console.log(configuration);
49
+ // const _proto = configuration.uri.split(':').shift()
50
+ // const _user = (configuration.uri.split(':').pop()).split('@').shift()
51
+ // const _realm = (configuration.uri.split(':').pop()).split('@').pop()
52
+ // configuration.uri = URI.parse(configuration.uri)
53
+ super(configuration);
54
+ this._msrp_sessions = [];
55
+ this._transactions = { nist: {},
56
+ nict: {},
57
+ ist: {},
58
+ ict: {}
59
+ };
60
+ // console.log(configuration.uri)
61
+ }
5
62
  call(target, options) {
6
63
  return super.call(target, options);
7
64
  }
65
+ /**
66
+ * new MSRPSession
67
+ */
68
+ newMSRPSession(session, data) {
69
+ // Listening for message history update
70
+ session.on('msgHistoryUpdate', (obj) => {
71
+ console.log(obj);
72
+ });
73
+ this._msrp_sessions[session.id] = session;
74
+ this.emit('newMSRPSession', data);
75
+ }
76
+ /**
77
+ * MSRPSession destroyed.
78
+ */
79
+ destroyMSRPSession(session) {
80
+ delete this._msrp_sessions[session.id];
81
+ }
82
+ receiveRequest(request) {
83
+ const method = request.method;
84
+ console.log('-----------');
85
+ // Check that request URI points to us.
86
+ if (request.ruri.user !== this._configuration.uri.user &&
87
+ request.ruri.user !== this._contact.uri.user) {
88
+ logger.debug('Request-URI does not point to us');
89
+ if (request.method !== JsSIP_C.ACK) {
90
+ request.reply_sl(404);
91
+ }
92
+ return;
93
+ }
94
+ // Check request URI scheme.
95
+ if (request.ruri.scheme === JsSIP_C.SIPS) {
96
+ request.reply_sl(416);
97
+ return;
98
+ }
99
+ // Check transaction.
100
+ if (Transactions_1.default.checkTransaction(this, request)) {
101
+ return;
102
+ }
103
+ // Create the server transaction.
104
+ if (method === JsSIP_C.INVITE) {
105
+ /* eslint-disable no-new */
106
+ new Transactions_1.default.InviteServerTransaction(this, this._transport, request);
107
+ /* eslint-enable no-new */
108
+ }
109
+ else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
110
+ /* eslint-disable no-new */
111
+ new Transactions_1.default.NonInviteServerTransaction(this, this._transport, request);
112
+ /* eslint-enable no-new */
113
+ }
114
+ /* RFC3261 12.2.2
115
+ * Requests that do not change in any way the state of a dialog may be
116
+ * received within a dialog (for example, an OPTIONS request).
117
+ * They are processed as if they had been received outside the dialog.
118
+ */
119
+ if (method === JsSIP_C.OPTIONS) {
120
+ if (this.listeners('newOptions').length === 0) {
121
+ request.reply(200);
122
+ return;
123
+ }
124
+ const message = new jssip_1.Options(this);
125
+ message.init_incoming(request);
126
+ }
127
+ else if (method === JsSIP_C.MESSAGE) {
128
+ if (this.listeners('newMessage').length === 0) {
129
+ request.reply(405);
130
+ return;
131
+ }
132
+ const message = new jssip_1.Message(this);
133
+ message.init_incoming(request);
134
+ }
135
+ else if (method === JsSIP_C.INVITE) {
136
+ // Initial INVITE.
137
+ if (!request.to_tag && this.listeners('newRTCSession').length === 0) {
138
+ request.reply(405);
139
+ return;
140
+ }
141
+ }
142
+ let dialog;
143
+ let session;
144
+ // Initial Request.
145
+ if (!request.to_tag) {
146
+ switch (method) {
147
+ case JsSIP_C.INVITE:
148
+ if (window.RTCPeerConnection) { // TODO
149
+ if (request.hasHeader('replaces')) {
150
+ const replaces = request.replaces;
151
+ dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
152
+ if (dialog) {
153
+ session = dialog.owner;
154
+ if (!session.isEnded()) {
155
+ session.receiveRequest(request);
156
+ }
157
+ else {
158
+ request.reply(603);
159
+ }
160
+ }
161
+ else {
162
+ request.reply(481);
163
+ }
164
+ }
165
+ else {
166
+ if (request.body.search(/MSRP/ig)) {
167
+ session = new session_1.MSRPSession(this);
168
+ session.init_incoming(request);
169
+ }
170
+ else {
171
+ session = new jssip_1.RTCSessiono(this);
172
+ session.init_incoming(request);
173
+ }
174
+ }
175
+ }
176
+ else {
177
+ logger.warn('INVITE received but WebRTC is not supported');
178
+ request.reply(488);
179
+ }
180
+ break;
181
+ case JsSIP_C.BYE:
182
+ // Out of dialog BYE received.
183
+ request.reply(481);
184
+ break;
185
+ case JsSIP_C.CANCEL:
186
+ session = this._findSession(request);
187
+ if (session) {
188
+ session.receiveRequest(request);
189
+ }
190
+ else {
191
+ logger.debug('received CANCEL request for a non existent session');
192
+ }
193
+ break;
194
+ case JsSIP_C.ACK:
195
+ /* Absorb it.
196
+ * ACK request without a corresponding Invite Transaction
197
+ * and without To tag.
198
+ */
199
+ break;
200
+ case JsSIP_C.NOTIFY:
201
+ // Receive new sip event.
202
+ this.emit('sipEvent', {
203
+ event: request.event,
204
+ request
205
+ });
206
+ request.reply(200);
207
+ break;
208
+ default:
209
+ request.reply(405);
210
+ break;
211
+ }
212
+ }
213
+ // In-dialog request.
214
+ else {
215
+ dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag);
216
+ if (dialog) {
217
+ dialog.receiveRequest(request);
218
+ }
219
+ else if (method === JsSIP_C.NOTIFY) {
220
+ session = this._findSession(request);
221
+ if (session) {
222
+ session.receiveRequest(request);
223
+ }
224
+ else {
225
+ logger.debug('received NOTIFY request for a non existent subscription');
226
+ request.reply(481, 'Subscription does not exist');
227
+ }
228
+ }
229
+ /* RFC3261 12.2.2
230
+ * Request with to tag, but no matching dialog found.
231
+ * Exception: ACK for an Invite request for which a dialog has not
232
+ * been created.
233
+ */
234
+ else if (method !== JsSIP_C.ACK) {
235
+ request.reply(481);
236
+ }
237
+ }
238
+ }
239
+ startMSRP(target, options) {
240
+ logger.debug('startMSRP()', options);
241
+ const session = new session_1.MSRPSession(this);
242
+ session.connect(target);
243
+ return session;
244
+ }
245
+ terminateMSRPSessions(options) {
246
+ logger.debug('terminateSessions()');
247
+ for (const idx in this._msrp_sessions) {
248
+ if (!this._msrp_sessions[idx].isEnded()) {
249
+ this._msrp_sessions[idx].terminate(options);
250
+ }
251
+ }
252
+ }
253
+ stop() {
254
+ logger.debug('stop()');
255
+ // Remove dynamic settings.
256
+ this._dynConfiguration = {};
257
+ if (this._status === C.STATUS_USER_CLOSED) {
258
+ logger.debug('UA already closed');
259
+ return;
260
+ }
261
+ // Close registrator.
262
+ this._registrator.close();
263
+ // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
264
+ const num_sessions = Object.keys(this._sessions).length;
265
+ // Run _terminate_ on every Session.
266
+ for (const session in this._sessions) {
267
+ if (Object.prototype.hasOwnProperty.call(this._sessions, session)) {
268
+ logger.debug(`closing session ${session}`);
269
+ try {
270
+ this._sessions[session].terminate();
271
+ }
272
+ catch (error) {
273
+ console.error(error);
274
+ }
275
+ }
276
+ }
277
+ // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
278
+ // const num_msrp_sessions = Object.keys(this._msrp_sessions).length
279
+ // Run _terminate_ on every Session.
280
+ for (const msrp_session in this._msrp_sessions) {
281
+ if (Object.prototype.hasOwnProperty.call(this._msrp_sessions, msrp_session)) {
282
+ logger.debug(`closing session ${msrp_session}`);
283
+ try {
284
+ this._msrp_sessions[msrp_session].terminate();
285
+ }
286
+ catch (error) {
287
+ console.error(error);
288
+ }
289
+ }
290
+ }
291
+ // Run _close_ on every applicant.
292
+ for (const applicant in this._applicants) {
293
+ if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) {
294
+ try {
295
+ this._applicants[applicant].close();
296
+ }
297
+ catch (error) {
298
+ console.error(error);
299
+ }
300
+ }
301
+ }
302
+ this._status = C.STATUS_USER_CLOSED;
303
+ const num_transactions = Object.keys(this._transactions.nict).length +
304
+ Object.keys(this._transactions.nist).length +
305
+ Object.keys(this._transactions.ict).length +
306
+ Object.keys(this._transactions.ist).length;
307
+ if (num_transactions === 0 && num_sessions === 0) {
308
+ this._transport.disconnect();
309
+ }
310
+ else {
311
+ this._closeTimer = setTimeout(() => {
312
+ this._closeTimer = null;
313
+ this._transport.disconnect();
314
+ }, 2000);
315
+ }
316
+ }
8
317
  }
9
318
  exports.default = UAExtended;
@@ -1,9 +1,15 @@
1
- import { ICall, MediaEvent } from '@/types/rtc';
1
+ import { ICall, MediaEvent, CustomLoggerType } from '@/types/rtc';
2
2
  import { Writeable } from '@/types/generic';
3
+ import { IMessage } from '@/types/msrp';
3
4
  type ICallKey = keyof ICall;
4
5
  declare const CALL_KEYS_TO_INCLUDE: Array<ICallKey>;
6
+ type IMessageKey = keyof IMessage;
7
+ declare const MESSAGE_KEYS_TO_INCLUDE: Array<IMessageKey>;
5
8
  export type ICallSimplified = Writeable<Pick<ICall, typeof CALL_KEYS_TO_INCLUDE[number]>>;
9
+ export type IMessageSimplified = Writeable<Pick<IMessage, typeof MESSAGE_KEYS_TO_INCLUDE[number]>>;
6
10
  export declare function simplifyCallObject(call: ICall): ICallSimplified;
11
+ export declare function simplifyMessageObject(call: IMessage): IMessageSimplified;
7
12
  export declare function processAudioVolume(stream: MediaStream, volume: number): MediaStream;
8
13
  export declare function syncStream(event: MediaEvent, call: ICall, outputDevice: string, volume: number): void;
14
+ export declare function isLoggerCompatible(logger: CustomLoggerType): true | undefined;
9
15
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syncStream = exports.processAudioVolume = exports.simplifyCallObject = void 0;
3
+ exports.isLoggerCompatible = exports.syncStream = exports.processAudioVolume = exports.simplifyMessageObject = exports.simplifyCallObject = void 0;
4
4
  const CALL_KEYS_TO_INCLUDE = [
5
5
  'roomId',
6
6
  '_audioMuted',
@@ -23,7 +23,25 @@ const CALL_KEYS_TO_INCLUDE = [
23
23
  //'audioQuality',
24
24
  'isOnHold',
25
25
  //'originalStream',
26
- 'localMuted'
26
+ 'localMuted',
27
+ 'autoAnswer'
28
+ ];
29
+ const MESSAGE_KEYS_TO_INCLUDE = [
30
+ //'roomId',
31
+ '_cancel_reason',
32
+ '_contact',
33
+ 'direction',
34
+ '_end_time',
35
+ '_eventsCount',
36
+ '_from_tag',
37
+ '_id',
38
+ '_is_canceled',
39
+ '_is_confirmed',
40
+ '_late_sdp',
41
+ 'status',
42
+ 'start_time',
43
+ '_remote_identity',
44
+ 'target_addr'
27
45
  ];
28
46
  function simplifyCallObject(call) {
29
47
  const simplified = {};
@@ -36,6 +54,16 @@ function simplifyCallObject(call) {
36
54
  return simplified;
37
55
  }
38
56
  exports.simplifyCallObject = simplifyCallObject;
57
+ function simplifyMessageObject(call) {
58
+ const simplified = {};
59
+ MESSAGE_KEYS_TO_INCLUDE.forEach(key => {
60
+ if (call[key] !== undefined) {
61
+ simplified[key] = call[key];
62
+ }
63
+ });
64
+ return simplified;
65
+ }
66
+ exports.simplifyMessageObject = simplifyMessageObject;
39
67
  function processAudioVolume(stream, volume) {
40
68
  const audioContext = new AudioContext();
41
69
  const audioSource = audioContext.createMediaStreamSource(stream);
@@ -58,3 +86,12 @@ function syncStream(event, call, outputDevice, volume) {
58
86
  call.audioTag = audio;
59
87
  }
60
88
  exports.syncStream = syncStream;
89
+ function isLoggerCompatible(logger) {
90
+ if (logger
91
+ && typeof logger.log === 'function'
92
+ && typeof logger.warn === 'function'
93
+ && typeof logger.error === 'function') {
94
+ return true;
95
+ }
96
+ }
97
+ exports.isLoggerCompatible = isLoggerCompatible;
@@ -0,0 +1,5 @@
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 };
@@ -0,0 +1,30 @@
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;