@voicenter-team/opensips-js 1.0.22 → 1.0.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. package/dist/index.d.ts +737 -0
  2. package/dist/opensips-js.cjs.js +155 -0
  3. package/dist/opensips-js.es.js +21363 -0
  4. package/dist/opensips-js.iife.js +155 -0
  5. package/dist/opensips-js.umd.js +155 -0
  6. package/package.json +14 -8
  7. package/src/types/Dialog.d.ts +7 -0
  8. package/src/types/Socket.d.ts +8 -0
  9. package/src/types/UAExtended.d.ts +24 -12
  10. package/src/types/listeners.d.ts +12 -4
  11. package/src/types/msrp.d.ts +15 -9
  12. package/src/types/rtc.d.ts +15 -5
  13. package/src/types/timer.d.ts +7 -0
  14. package/build/enum/call.event.listener.type.d.ts +0 -7
  15. package/build/enum/call.event.listener.type.js +0 -10
  16. package/build/enum/message.event.listener.type.d.ts +0 -5
  17. package/build/enum/message.event.listener.type.js +0 -8
  18. package/build/enum/metric.keys.to.include.d.ts +0 -2
  19. package/build/enum/metric.keys.to.include.js +0 -4
  20. package/build/enum/session.direction.enum.d.ts +0 -2
  21. package/build/enum/session.direction.enum.js +0 -5
  22. package/build/helpers/UA/index.d.ts +0 -41
  23. package/build/helpers/UA/index.js +0 -318
  24. package/build/helpers/audio.helper.d.ts +0 -15
  25. package/build/helpers/audio.helper.js +0 -97
  26. package/build/helpers/filter.helper.d.ts +0 -2
  27. package/build/helpers/filter.helper.js +0 -14
  28. package/build/helpers/jssip.d.ts +0 -5
  29. package/build/helpers/jssip.js +0 -30
  30. package/build/helpers/time.helper.d.ts +0 -16
  31. package/build/helpers/time.helper.js +0 -28
  32. package/build/helpers/volume.helper.d.ts +0 -2
  33. package/build/helpers/volume.helper.js +0 -76
  34. package/build/helpers/webrtcmetrics/collector.d.ts +0 -32
  35. package/build/helpers/webrtcmetrics/collector.js +0 -282
  36. package/build/helpers/webrtcmetrics/engine.d.ts +0 -20
  37. package/build/helpers/webrtcmetrics/engine.js +0 -164
  38. package/build/helpers/webrtcmetrics/exporter.d.ts +0 -116
  39. package/build/helpers/webrtcmetrics/exporter.js +0 -528
  40. package/build/helpers/webrtcmetrics/extractor.d.ts +0 -1
  41. package/build/helpers/webrtcmetrics/extractor.js +0 -976
  42. package/build/helpers/webrtcmetrics/index.d.ts +0 -63
  43. package/build/helpers/webrtcmetrics/index.js +0 -93
  44. package/build/helpers/webrtcmetrics/metrics.d.ts +0 -2
  45. package/build/helpers/webrtcmetrics/metrics.js +0 -8
  46. package/build/helpers/webrtcmetrics/probe.d.ts +0 -76
  47. package/build/helpers/webrtcmetrics/probe.js +0 -153
  48. package/build/helpers/webrtcmetrics/utils/config.d.ts +0 -12
  49. package/build/helpers/webrtcmetrics/utils/config.js +0 -28
  50. package/build/helpers/webrtcmetrics/utils/helper.d.ts +0 -13
  51. package/build/helpers/webrtcmetrics/utils/helper.js +0 -134
  52. package/build/helpers/webrtcmetrics/utils/log.d.ts +0 -7
  53. package/build/helpers/webrtcmetrics/utils/log.js +0 -71
  54. package/build/helpers/webrtcmetrics/utils/models.d.ts +0 -309
  55. package/build/helpers/webrtcmetrics/utils/models.js +0 -298
  56. package/build/helpers/webrtcmetrics/utils/score.d.ts +0 -4
  57. package/build/helpers/webrtcmetrics/utils/score.js +0 -235
  58. package/build/helpers/webrtcmetrics/utils/shortUUId.d.ts +0 -1
  59. package/build/helpers/webrtcmetrics/utils/shortUUId.js +0 -7
  60. package/build/index.d.ts +0 -180
  61. package/build/index.js +0 -1141
  62. package/build/lib/msrp/message.d.ts +0 -12
  63. package/build/lib/msrp/message.js +0 -82
  64. package/build/lib/msrp/session.d.ts +0 -94
  65. package/build/lib/msrp/session.js +0 -621
package/build/index.js DELETED
@@ -1,1141 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const UA_1 = __importDefault(require("./helpers/UA"));
16
- const p_iteration_1 = require("p-iteration");
17
- const time_helper_1 = require("./helpers/time.helper");
18
- const filter_helper_1 = require("./helpers/filter.helper");
19
- const audio_helper_1 = require("./helpers/audio.helper");
20
- const metrics_1 = __importDefault(require("./helpers/webrtcmetrics/metrics"));
21
- const JsSIP_1 = __importDefault(require("jssip/lib/JsSIP"));
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
- const CALL_STATUS_UNANSWERED = 0;
25
- const STORAGE_KEYS = {
26
- SELECTED_INPUT_DEVICE: 'selectedInputDevice',
27
- SELECTED_OUTPUT_DEVICE: 'selectedOutputDevice'
28
- };
29
- class OpenSIPSJS extends UA_1.default {
30
- constructor(options, logger) {
31
- const configuration = Object.assign(Object.assign({}, options.configuration), { sockets: options.socketInterfaces.map(sock => new JsSIP_1.default.WebSocketInterface(sock)) });
32
- super(configuration);
33
- this.initialized = false;
34
- this.logger = console;
35
- /* Events */
36
- this.newRTCSessionEventName = 'newRTCSession';
37
- this.registeredEventName = 'registered';
38
- this.unregisteredEventName = 'unregistered';
39
- this.disconnectedEventName = 'disconnected';
40
- this.connectedEventName = 'connected';
41
- this.newMSRPSessionEventName = 'newMSRPSession';
42
- /* State */
43
- this.muted = false;
44
- this.isAutoAnswer = false;
45
- this.isDNDEnabled = false;
46
- this.muteWhenJoinEnabled = false;
47
- this.activeRooms = {};
48
- this.activeCalls = {};
49
- this.extendedCalls = {};
50
- this.activeMessages = {};
51
- this.extendedMessages = {};
52
- this.msrpHistory = {};
53
- this.microphoneInputLevelValue = 2; // [0;2]
54
- this.speakerVolumeValue = 1; // [0;1]
55
- this.availableMediaDevices = [];
56
- this.selectedMediaDevices = {
57
- input: 'default',
58
- output: 'default'
59
- };
60
- this.callStatus = {};
61
- this.callTime = {};
62
- this.callMetrics = {};
63
- this.timeIntervals = {};
64
- this.metricConfig = {
65
- refreshEvery: 1000
66
- };
67
- this.originalStreamValue = null;
68
- this.isReconnecting = false;
69
- this.listenersList = {};
70
- this.options = options;
71
- if (logger && (0, audio_helper_1.isLoggerCompatible)(logger)) {
72
- this.logger = logger;
73
- }
74
- }
75
- on(type, listener) {
76
- return super.on(type, listener);
77
- }
78
- off(type, listener) {
79
- return super.off(type, listener);
80
- }
81
- emit(type, args) {
82
- return super.emit(type, args);
83
- }
84
- get sipDomain() {
85
- return this.options.sipDomain;
86
- }
87
- get sipOptions() {
88
- const options = Object.assign(Object.assign({}, this.options.sipOptions), { mediaConstraints: this.getUserMediaConstraints });
89
- return options;
90
- }
91
- get currentActiveRoomId() {
92
- return this.currentActiveRoomIdValue;
93
- }
94
- set currentActiveRoomId(roomId) {
95
- this.currentActiveRoomIdValue = roomId;
96
- this.emit('currentActiveRoomChanged', roomId);
97
- }
98
- get autoAnswer() {
99
- return this.isAutoAnswer;
100
- }
101
- get callAddingInProgress() {
102
- return this.isCallAddingInProgress;
103
- }
104
- set callAddingInProgress(value) {
105
- this.isCallAddingInProgress = value;
106
- this.emit('callAddingInProgressChanged', value);
107
- }
108
- get isMSRPInitializing() {
109
- return this.isMSRPInitializingValue;
110
- }
111
- get muteWhenJoin() {
112
- return this.muteWhenJoinEnabled;
113
- }
114
- get isDND() {
115
- return this.isDNDEnabled;
116
- }
117
- get speakerVolume() {
118
- return this.speakerVolumeValue;
119
- }
120
- get microphoneInputLevel() {
121
- return this.microphoneInputLevelValue;
122
- }
123
- get getActiveCalls() {
124
- return this.activeCalls;
125
- }
126
- get hasActiveCalls() {
127
- return Object.values(this.extendedCalls).length > 0;
128
- }
129
- get getActiveMessages() {
130
- return this.activeMessages;
131
- }
132
- get getActiveRooms() {
133
- return this.activeRooms;
134
- }
135
- get isMuted() {
136
- return this.muted;
137
- }
138
- get getInputDeviceList() {
139
- return this.availableMediaDevices.filter(device => device.kind === 'audioinput');
140
- }
141
- get getOutputDeviceList() {
142
- return this.availableMediaDevices.filter(device => device.kind === 'audiooutput');
143
- }
144
- /*getInputDeviceList: (state) => {
145
- return state.availableMediaDevices.filter(device => device.kind === 'audioinput');
146
- },
147
- getOutputDeviceList: (state) => {
148
- return state.availableMediaDevices.filter(device => device.kind === 'audiooutput');
149
- }*/
150
- get getUserMediaConstraints() {
151
- return {
152
- audio: {
153
- deviceId: {
154
- exact: this.selectedMediaDevices.input
155
- }
156
- },
157
- video: false
158
- };
159
- }
160
- get getInputDefaultDevice() {
161
- return this.getInputDeviceList.find(device => device.deviceId === 'default');
162
- }
163
- get getOutputDefaultDevice() {
164
- return this.getOutputDeviceList.find(device => device.deviceId === 'default');
165
- }
166
- get selectedInputDevice() {
167
- return this.selectedMediaDevices.input;
168
- }
169
- get selectedOutputDevice() {
170
- return this.selectedMediaDevices.output;
171
- }
172
- get originalStream() {
173
- return this.originalStreamValue;
174
- }
175
- setAvailableMediaDevices(devices) {
176
- this.availableMediaDevices = devices;
177
- this.emit('changeAvailableDeviceList', devices);
178
- }
179
- updateDeviceList() {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
182
- const devices = yield navigator.mediaDevices.enumerateDevices();
183
- this.setAvailableMediaDevices(devices);
184
- });
185
- }
186
- setMediaDevices(setDefaults = false) {
187
- var _a, _b;
188
- return __awaiter(this, void 0, void 0, function* () {
189
- this.selectedMediaDevices.input = localStorage.getItem(STORAGE_KEYS.SELECTED_INPUT_DEVICE) || 'default';
190
- this.selectedMediaDevices.output = localStorage.getItem(STORAGE_KEYS.SELECTED_OUTPUT_DEVICE) || 'default';
191
- yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
192
- const devices = yield navigator.mediaDevices.enumerateDevices();
193
- this.setAvailableMediaDevices(devices);
194
- const defaultMicrophone = setDefaults
195
- ? ((_a = this.getInputDefaultDevice) === null || _a === void 0 ? void 0 : _a.deviceId) || ''
196
- : '';
197
- const defaultSpeaker = setDefaults
198
- ? ((_b = this.getOutputDefaultDevice) === null || _b === void 0 ? void 0 : _b.deviceId) || ''
199
- : '';
200
- yield this.setMicrophone(defaultMicrophone);
201
- yield this.setSpeaker(defaultSpeaker);
202
- });
203
- }
204
- setCallTime(value) {
205
- const time = Object.assign({}, value);
206
- delete time.callId;
207
- this.callTime = Object.assign(Object.assign({}, this.callTime), { [value.callId]: time });
208
- this.emit('changeCallTime', this.callTime);
209
- }
210
- removeCallTime(callId) {
211
- const callTimeCopy = Object.assign({}, this.callTime);
212
- delete callTimeCopy[callId];
213
- this.callTime = Object.assign({}, callTimeCopy);
214
- this.emit('changeCallTime', this.callTime);
215
- }
216
- setTimeInterval(callId, interval) {
217
- this.timeIntervals = Object.assign(Object.assign({}, this.timeIntervals), { [callId]: interval });
218
- }
219
- removeTimeInterval(callId) {
220
- const timeIntervalsCopy = Object.assign({}, this.timeIntervals);
221
- clearInterval(timeIntervalsCopy[callId]);
222
- delete timeIntervalsCopy[callId];
223
- this.timeIntervals = Object.assign({}, timeIntervalsCopy);
224
- }
225
- _stopCallTimer(callId) {
226
- this.removeTimeInterval(callId);
227
- this.removeCallTime(callId);
228
- }
229
- setMetricsConfig(config) {
230
- this.metricConfig = Object.assign(Object.assign({}, this.metricConfig), config);
231
- }
232
- sendDTMF(callId, value) {
233
- const validation_regex = /^[A-D0-9]+$/g;
234
- if (!validation_regex.test(value)) {
235
- throw new Error('Not allowed character in DTMF input');
236
- }
237
- const call = this.extendedCalls[callId];
238
- call.sendDTMF(value);
239
- }
240
- setIsMuted(value) {
241
- this.muted = value;
242
- this.emit('changeIsMuted', value);
243
- }
244
- doMute(value) {
245
- const activeRoomId = this.currentActiveRoomId;
246
- this.setIsMuted(value);
247
- //this.isMuted = value
248
- this.roomReconfigure(activeRoomId);
249
- }
250
- doCallHold({ callId, toHold, automatic }) {
251
- const call = this.extendedCalls[callId];
252
- call._automaticHold = automatic !== null && automatic !== void 0 ? automatic : false;
253
- if (toHold) {
254
- call.hold();
255
- }
256
- else {
257
- call.unhold();
258
- }
259
- }
260
- _cancelAllOutgoingUnanswered() {
261
- Object.values(this.getActiveCalls).filter(call => {
262
- return call.direction === 'outgoing'
263
- && call.status === CALL_STATUS_UNANSWERED;
264
- }).forEach(call => this.callTerminate(call._id));
265
- }
266
- callAnswer(callId) {
267
- const call = this.extendedCalls[callId];
268
- this._cancelAllOutgoingUnanswered();
269
- call.answer(this.sipOptions);
270
- this.updateCall(call);
271
- // TODO: maybe would be better to move to the top
272
- this.setCurrentActiveRoomId(call.roomId);
273
- call.connection.addEventListener('addstream', (event) => __awaiter(this, void 0, void 0, function* () {
274
- this._triggerAddStream(event, call);
275
- }));
276
- }
277
- msrpAnswer(callId) {
278
- const call = this.extendedMessages[callId];
279
- //this._cancelAllOutgoingUnanswered()
280
- call.answer(this.sipOptions);
281
- this.updateMSRPSession(call);
282
- // TODO: maybe would be better to move to the top
283
- //this.setCurrentActiveRoomId(call.roomId)
284
- }
285
- callMove(callId, roomId) {
286
- return __awaiter(this, void 0, void 0, function* () {
287
- this._updateCallStatus({ callId, isMoving: true });
288
- yield this.callChangeRoom({ callId, roomId });
289
- this._updateCallStatus({ callId, isMoving: false });
290
- });
291
- }
292
- updateCall(value) {
293
- this.activeCalls[value._id] = (0, audio_helper_1.simplifyCallObject)(value);
294
- this.emit('changeActiveCalls', this.activeCalls);
295
- }
296
- updateMSRPSession(value) {
297
- this.activeMessages[value._id] = (0, audio_helper_1.simplifyMessageObject)(value);
298
- this.emit('changeActiveMessages', this.activeMessages);
299
- }
300
- updateRoom(value) {
301
- const room = this.activeRooms[value.roomId];
302
- const newRoomData = Object.assign(Object.assign({}, room), value);
303
- this.activeRooms = Object.assign(Object.assign({}, this.activeRooms), { [value.roomId]: Object.assign({}, newRoomData) });
304
- this.emit('updateRoom', { room: newRoomData, roomList: this.activeRooms });
305
- }
306
- hasAutoAnswerHeaders(event) {
307
- const regex = /answer-after=0/;
308
- const request = event.request;
309
- const callInfoHeader = request.getHeader('Call-Info');
310
- return callInfoHeader && regex.test(callInfoHeader);
311
- }
312
- _addCall(value, emitEvent = true) {
313
- this.activeCalls = Object.assign(Object.assign({}, this.activeCalls), { [value._id]: (0, audio_helper_1.simplifyCallObject)(value) });
314
- /*this.extendedCalls = {
315
- ...this.extendedCalls,
316
- [value._id]: value
317
- }*/
318
- this.extendedCalls[value._id] = value;
319
- if (emitEvent) {
320
- this.emit('changeActiveCalls', this.activeCalls);
321
- }
322
- }
323
- _addCallStatus(callId) {
324
- this.callStatus = Object.assign(Object.assign({}, this.callStatus), { [callId]: {
325
- isMoving: false,
326
- isTransferring: false,
327
- isMerging: false
328
- } });
329
- this.emit('changeCallStatus', this.callStatus);
330
- }
331
- _addMMSRPSession(value) {
332
- this.activeMessages = Object.assign(Object.assign({}, this.activeMessages), { [value._id]: (0, audio_helper_1.simplifyMessageObject)(value) });
333
- this.extendedMessages[value._id] = value;
334
- this.emit('changeActiveMessages', this.activeMessages);
335
- }
336
- _addMSRPMessage(value, session) {
337
- const sessionMessages = this.msrpHistory[session.id] || [];
338
- sessionMessages.push(value);
339
- this.msrpHistory = Object.assign(Object.assign({}, this.msrpHistory), { [session.id]: [...sessionMessages] });
340
- this.emit('newMSRPMessage', { message: value, session: session });
341
- }
342
- _updateCallStatus(value) {
343
- const prevStatus = Object.assign({}, this.callStatus[value.callId]);
344
- const newStatus = Object.assign({}, prevStatus);
345
- if (value.isMoving !== undefined) {
346
- newStatus.isMoving = value.isMoving;
347
- }
348
- if (value.isTransferring !== undefined) {
349
- newStatus.isTransferring = value.isTransferring;
350
- }
351
- if (value.isMerging !== undefined) {
352
- newStatus.isMerging = value.isMerging;
353
- }
354
- this.callStatus = Object.assign(Object.assign({}, this.callStatus), { [value.callId]: Object.assign({}, newStatus) });
355
- this.emit('changeCallStatus', this.callStatus);
356
- }
357
- _removeCallStatus(callId) {
358
- const callStatusCopy = Object.assign({}, this.callStatus);
359
- delete callStatusCopy[callId];
360
- this.callStatus = Object.assign({}, callStatusCopy);
361
- this.emit('changeCallStatus', this.callStatus);
362
- }
363
- _addRoom(value) {
364
- this.activeRooms = Object.assign(Object.assign({}, this.activeRooms), { [value.roomId]: value });
365
- this.emit('addRoom', { room: value, roomList: this.activeRooms });
366
- }
367
- setMicrophone(dId) {
368
- return __awaiter(this, void 0, void 0, function* () {
369
- if (!this.getInputDeviceList.find(({ deviceId }) => deviceId === dId)) {
370
- return;
371
- }
372
- this.setSelectedInputDevice(dId);
373
- let stream; // = null
374
- try {
375
- stream = yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
376
- }
377
- catch (err) {
378
- console.error(err);
379
- }
380
- if (Object.keys(this.getActiveCalls).length === 0) {
381
- return;
382
- }
383
- const callsInCurrentRoom = Object.values(this.extendedCalls).filter(call => call.roomId === this.currentActiveRoomId);
384
- if (callsInCurrentRoom.length === 1) {
385
- Object.values(callsInCurrentRoom).forEach(call => {
386
- const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
387
- processedStream.getTracks().forEach(track => track.enabled = !this.isMuted);
388
- this._setOriginalStream(processedStream);
389
- call.connection.getSenders()[0].replaceTrack(processedStream.getTracks()[0]);
390
- this.updateCall(call);
391
- });
392
- }
393
- else {
394
- yield this._doConference(callsInCurrentRoom);
395
- }
396
- });
397
- }
398
- _setOriginalStream(value) {
399
- this.originalStreamValue = value;
400
- this.emit('changeOriginalStream', value);
401
- }
402
- setSpeaker(dId) {
403
- return __awaiter(this, void 0, void 0, function* () {
404
- if (!this.getOutputDeviceList.find(({ deviceId }) => deviceId === dId)) {
405
- return;
406
- }
407
- this.setSelectedOutputDevice(dId);
408
- const activeCallList = Object.values(this.extendedCalls);
409
- if (activeCallList.length === 0) {
410
- return;
411
- }
412
- const callsInCurrentRoom = activeCallList.filter(call => call.roomId === this.currentActiveRoomId);
413
- if (callsInCurrentRoom.length === 1) {
414
- activeCallList.forEach(call => {
415
- var _a;
416
- (_a = call.audioTag) === null || _a === void 0 ? void 0 : _a.setSinkId(dId);
417
- this.updateCall(call);
418
- });
419
- }
420
- else {
421
- yield this._doConference(callsInCurrentRoom);
422
- }
423
- });
424
- }
425
- removeRoom(roomId) {
426
- const activeRoomsCopy = Object.assign({}, this.activeRooms);
427
- const roomToRemove = Object.assign({}, activeRoomsCopy[roomId]);
428
- delete activeRoomsCopy[roomId];
429
- this.activeRooms = Object.assign({}, activeRoomsCopy);
430
- this.emit('removeRoom', { room: roomToRemove, roomList: this.activeRooms });
431
- }
432
- deleteRoomIfEmpty(roomId) {
433
- if (roomId === undefined) {
434
- return;
435
- }
436
- if (Object.values(this.extendedCalls).filter(call => call.roomId === roomId).length === 0) {
437
- this.removeRoom(roomId);
438
- if (this.currentActiveRoomId === roomId) {
439
- this.currentActiveRoomId = undefined;
440
- }
441
- }
442
- }
443
- checkInitialized() {
444
- if (!this.initialized) {
445
- throw new Error('[OpenSIPSJS] You must call `start` method first!');
446
- }
447
- }
448
- muteReconfigure(call) {
449
- if (this.muted) {
450
- call.mute({ audio: true });
451
- }
452
- else {
453
- call.unmute({ audio: true });
454
- }
455
- }
456
- roomReconfigure(roomId) {
457
- return __awaiter(this, void 0, void 0, function* () {
458
- if (roomId === undefined) {
459
- return;
460
- }
461
- const callsInRoom = Object.values(this.extendedCalls).filter(call => call.roomId === roomId);
462
- // Let`s take care on the audio output first and check if passed room is our selected room
463
- if (this.currentActiveRoomId === roomId) {
464
- callsInRoom.forEach(call => {
465
- if (call.audioTag) {
466
- this.muteReconfigure(call);
467
- call.audioTag.muted = false;
468
- this.updateCall(call);
469
- }
470
- });
471
- }
472
- else {
473
- callsInRoom.forEach(call => {
474
- if (call.audioTag) {
475
- call.audioTag.muted = true;
476
- this.updateCall(call);
477
- }
478
- });
479
- }
480
- // Now let`s configure the sound we are sending for each active call on this room
481
- if (callsInRoom.length === 0) {
482
- this.deleteRoomIfEmpty(roomId);
483
- }
484
- else if (callsInRoom.length === 1 && this.currentActiveRoomId !== roomId) {
485
- if (!callsInRoom[0].isOnHold().local) {
486
- this.doCallHold({ callId: callsInRoom[0].id, toHold: true, automatic: true });
487
- }
488
- }
489
- else if (callsInRoom.length === 1 && this.currentActiveRoomId === roomId) {
490
- if (callsInRoom[0].isOnHold().local && callsInRoom[0]._automaticHold) {
491
- this.doCallHold({ callId: callsInRoom[0].id, toHold: false });
492
- }
493
- let stream;
494
- try {
495
- stream = yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
496
- }
497
- catch (err) {
498
- console.error(err);
499
- }
500
- if (stream && callsInRoom[0].connection && callsInRoom[0].connection.getSenders()[0]) {
501
- const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
502
- processedStream.getTracks().forEach(track => track.enabled = !this.muted);
503
- this._setOriginalStream(processedStream);
504
- yield callsInRoom[0].connection.getSenders()[0].replaceTrack(processedStream.getTracks()[0]);
505
- this.muteReconfigure(callsInRoom[0]);
506
- }
507
- }
508
- else if (callsInRoom.length > 1) {
509
- yield this._doConference(callsInRoom);
510
- }
511
- });
512
- }
513
- _doConference(sessions) {
514
- return __awaiter(this, void 0, void 0, function* () {
515
- sessions.forEach(call => {
516
- if (call._localHold) {
517
- this.doCallHold({ callId: call._id, toHold: false });
518
- }
519
- });
520
- // Take all received tracks from the sessions you want to merge
521
- const receivedTracks = [];
522
- sessions.forEach(session => {
523
- if (session !== null && session !== undefined) {
524
- session.connection.getReceivers().forEach((receiver) => {
525
- receivedTracks.push(receiver.track);
526
- });
527
- }
528
- });
529
- // Use the Web Audio API to mix the received tracks
530
- const audioContext = new AudioContext();
531
- const allReceivedMediaStreams = new MediaStream();
532
- // For each call we will build dedicated mix for all other calls
533
- yield (0, p_iteration_1.forEach)(sessions, (session) => __awaiter(this, void 0, void 0, function* () {
534
- if (session === null || session === undefined) {
535
- return;
536
- }
537
- const mixedOutput = audioContext.createMediaStreamDestination();
538
- session.connection.getReceivers().forEach((receiver) => {
539
- receivedTracks.forEach(track => {
540
- allReceivedMediaStreams.addTrack(receiver.track);
541
- if (receiver.track.id !== track.id) {
542
- const sourceStream = audioContext.createMediaStreamSource(new MediaStream([track]));
543
- sourceStream.connect(mixedOutput);
544
- }
545
- });
546
- });
547
- if (sessions[0].roomId === this.currentActiveRoomId) {
548
- // Mixing your voice with all the received audio
549
- const stream = yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
550
- const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
551
- processedStream.getTracks().forEach(track => track.enabled = !this.isMuted);
552
- this._setOriginalStream(processedStream);
553
- const sourceStream = audioContext.createMediaStreamSource(processedStream);
554
- // stream.getTracks().forEach(track => track.enabled = !getters.isMuted) // TODO: Fix this
555
- sourceStream.connect(mixedOutput);
556
- }
557
- if (session.connection.getSenders()[0]) {
558
- //mixedOutput.stream.getTracks().forEach(track => track.enabled = !getters.isMuted) // Uncomment to mute all callers on mute
559
- yield session.connection.getSenders()[0].replaceTrack(mixedOutput.stream.getTracks()[0]);
560
- this._muteReconfigure(session);
561
- }
562
- }));
563
- });
564
- }
565
- _muteReconfigure(call) {
566
- if (this.isMuted) {
567
- call.mute({ audio: true });
568
- }
569
- else {
570
- call.unmute({ audio: true });
571
- }
572
- }
573
- muteCaller(callId, value) {
574
- const call = this.extendedCalls[callId];
575
- if (call && call.connection.getReceivers().length) {
576
- call.localMuted = value;
577
- call.connection.getReceivers().forEach((receiver) => {
578
- receiver.track.enabled = !value;
579
- });
580
- this.updateCall(call);
581
- this.roomReconfigure(call.roomId);
582
- }
583
- }
584
- callTerminate(callId) {
585
- const call = this.extendedCalls[callId];
586
- if (call._status !== 8) {
587
- call.terminate();
588
- }
589
- }
590
- messageTerminate(callId) {
591
- const call = this.extendedMessages[callId];
592
- if (call._status !== 8) {
593
- call.terminate();
594
- }
595
- }
596
- callTransfer(callId, target) {
597
- if (target.toString().length === 0) {
598
- return console.error('Target must be passed');
599
- }
600
- const call = this.extendedCalls[callId];
601
- if (!call._is_confirmed && !call._is_canceled) {
602
- const redirectTarget = `sip:${target}@${this.sipDomain}`;
603
- call.terminate({
604
- status_code: 302,
605
- reason_phrase: 'Moved Temporarily',
606
- extraHeaders: [`Contact: ${redirectTarget}`]
607
- });
608
- return;
609
- }
610
- this._updateCallStatus({ callId, isTransferring: true });
611
- call.refer(`sip:${target}@${this.sipDomain}`);
612
- this.updateCall(call);
613
- }
614
- callMerge(roomId) {
615
- const callsInRoom = Object.values(this.extendedCalls).filter((call) => call.roomId === roomId);
616
- if (callsInRoom.length !== 2)
617
- return;
618
- const firstCall = callsInRoom[0];
619
- const secondCall = callsInRoom[1];
620
- if (!firstCall || !secondCall) {
621
- return;
622
- }
623
- // TODO: Check all call.id for working in the same way as call._id
624
- this._updateCallStatus({ callId: firstCall._id, isMerging: true });
625
- this._updateCallStatus({ callId: secondCall._id, isMerging: true });
626
- firstCall.refer(secondCall.remote_identity.uri.toString(), { 'replaces': secondCall });
627
- this.updateCall(firstCall);
628
- }
629
- // TODO: Use this method in demo
630
- setDND(value) {
631
- this.isDNDEnabled = value;
632
- this.emit('changeIsDND', value);
633
- }
634
- _startCallTimer(callId) {
635
- const timeData = {
636
- callId,
637
- hours: 0,
638
- minutes: 0,
639
- seconds: 0,
640
- formatted: ''
641
- };
642
- this.setCallTime(timeData);
643
- const interval = setInterval(() => {
644
- const callTime = Object.assign({}, this.callTime[callId]);
645
- const updatedTime = (0, time_helper_1.setupTime)(callTime);
646
- this.setCallTime(Object.assign({ callId }, updatedTime));
647
- }, 1000);
648
- this.setTimeInterval(callId, interval);
649
- }
650
- setCurrentActiveRoomId(roomId) {
651
- return __awaiter(this, void 0, void 0, function* () {
652
- const oldRoomId = this.currentActiveRoomId;
653
- if (roomId === oldRoomId) {
654
- return;
655
- }
656
- this.currentActiveRoomId = roomId;
657
- yield this.roomReconfigure(oldRoomId);
658
- yield this.roomReconfigure(roomId);
659
- });
660
- }
661
- getNewRoomId() {
662
- const roomIdList = Object.keys(this.activeRooms);
663
- if (roomIdList.length === 0) {
664
- return 1;
665
- }
666
- return (parseInt(roomIdList.sort()[roomIdList.length - 1]) + 1);
667
- }
668
- subscribe(type, listener) {
669
- const isListenerEmpty = !this.listenersList[type] || !this.listenersList[type].length;
670
- const newListeners = isListenerEmpty ? [listener] : [...this.listenersList[type], listener];
671
- this.listenersList = Object.assign(Object.assign({}, this.listenersList), { [type]: newListeners });
672
- }
673
- removeIListener(value) {
674
- const listenersCopy = Object.assign({}, this.listenersList);
675
- delete listenersCopy[value];
676
- this.listenersList = Object.assign({}, listenersCopy);
677
- }
678
- addCall(event) {
679
- var _a, _b;
680
- return __awaiter(this, void 0, void 0, function* () {
681
- const session = event.session;
682
- const sessionAlreadyInActiveCalls = this.getActiveCalls[session.id];
683
- if (sessionAlreadyInActiveCalls !== undefined) {
684
- return;
685
- }
686
- const roomId = this.getNewRoomId();
687
- const newRoomInfo = {
688
- started: new Date(),
689
- incomingInProgress: false,
690
- roomId
691
- };
692
- if (session.direction === 'incoming') {
693
- this.logger.log('New incoming call from', (_b = (_a = session._remote_identity) === null || _a === void 0 ? void 0 : _a._uri) === null || _b === void 0 ? void 0 : _b._user);
694
- newRoomInfo.incomingInProgress = true;
695
- this.subscribe(call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_CONFIRMED, (call) => {
696
- if (session.id === call.id) {
697
- this.updateRoom({
698
- incomingInProgress: false,
699
- roomId
700
- });
701
- this._startCallTimer(session.id);
702
- }
703
- });
704
- this.subscribe(call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_FAILED, (call) => {
705
- if (session.id === call.id) {
706
- this.updateRoom({
707
- incomingInProgress: false,
708
- roomId
709
- });
710
- this.deleteRoomIfEmpty(roomId);
711
- }
712
- });
713
- }
714
- else if (session.direction === 'outgoing') {
715
- this._startCallTimer(session.id);
716
- }
717
- const call = session;
718
- const autoAnswerByHeaders = this.hasAutoAnswerHeaders(event);
719
- const doAutoAnswer = call.direction === 'incoming' && !this.hasActiveCalls && (autoAnswerByHeaders || this.autoAnswer);
720
- call.roomId = roomId;
721
- call.localMuted = false;
722
- call.autoAnswer = doAutoAnswer;
723
- if (doAutoAnswer) {
724
- this._addCall(call, false);
725
- }
726
- else {
727
- this._addCall(call);
728
- }
729
- // this._addCall(call)
730
- this._addCallStatus(session.id);
731
- this._addRoom(newRoomInfo);
732
- if (doAutoAnswer) {
733
- this.callAnswer(call._id);
734
- }
735
- });
736
- }
737
- addMessageSession(session) {
738
- // For cases when session.direction === 'outgoing' and all the
739
- // session properties are missing before answer
740
- if (!session._id) {
741
- return;
742
- }
743
- const sessionAlreadyInActiveMessages = this.getActiveMessages[session._id];
744
- if (sessionAlreadyInActiveMessages !== undefined) {
745
- return;
746
- }
747
- /*const roomId = this.getNewRoomId()
748
-
749
- const newRoomInfo: IRoom = {
750
- started: new Date(),
751
- incomingInProgress: false,
752
- roomId
753
- }*/
754
- /*if (session.direction === 'incoming') {
755
- newRoomInfo.incomingInProgress = true
756
-
757
- this.subscribe(CALL_EVENT_LISTENER_TYPE.CALL_CONFIRMED, (call) => {
758
- if (session.id === call.id) {
759
- this.updateRoom( {
760
- incomingInProgress: false,
761
- roomId
762
- })
763
- this._startCallTimer(session.id)
764
- }
765
- })
766
-
767
- this.subscribe(CALL_EVENT_LISTENER_TYPE.CALL_FAILED, (call) => {
768
- if (session.id === call.id) {
769
- this.updateRoom({
770
- incomingInProgress: false,
771
- roomId
772
- })
773
- }
774
- })
775
-
776
- } else if (session.direction === 'outgoing') {
777
- this._startCallTimer(session.id)
778
- }*/
779
- const MSRPSession = session;
780
- //MSRPSession.roomId = roomId
781
- this._addMMSRPSession(MSRPSession);
782
- //this._addMMSRPSessionStatus(session.id)
783
- //this._addRoom(newRoomInfo)
784
- }
785
- _triggerListener({ listenerType, session, event }) {
786
- const listeners = this.listenersList[listenerType];
787
- if (!listeners || !listeners.length) {
788
- return;
789
- }
790
- listeners.forEach((listener) => {
791
- listener(session, event);
792
- });
793
- }
794
- _triggerMSRPListener({ listenerType, session, event }) {
795
- const listeners = this.listenersList[listenerType];
796
- if (!listeners || !listeners.length) {
797
- return;
798
- }
799
- listeners.forEach((listener) => {
800
- listener(session, event);
801
- });
802
- }
803
- _removeCall(value) {
804
- const stateActiveCallsCopy = Object.assign({}, this.activeCalls);
805
- delete stateActiveCallsCopy[value];
806
- // delete activeCalls[value]
807
- this.activeCalls = Object.assign({}, stateActiveCallsCopy);
808
- const stateExtendedCallsCopy = Object.assign({}, this.extendedCalls);
809
- delete stateExtendedCallsCopy[value];
810
- this.extendedCalls = Object.assign({}, stateExtendedCallsCopy);
811
- this.emit('changeActiveCalls', this.activeCalls);
812
- }
813
- _removeMMSRPSession(value) {
814
- const stateActiveMessagesCopy = Object.assign({}, this.activeMessages);
815
- delete stateActiveMessagesCopy[value];
816
- //delete activeMessages[value]
817
- this.activeMessages = Object.assign({}, stateActiveMessagesCopy);
818
- const stateExtendedMessagesCopy = Object.assign({}, this.extendedMessages);
819
- delete stateExtendedMessagesCopy[value];
820
- this.extendedMessages = Object.assign({}, stateExtendedMessagesCopy);
821
- this.emit('changeActiveMessages', this.activeMessages);
822
- }
823
- _activeCallListRemove(call) {
824
- const callRoomIdToConfigure = this.extendedCalls[call._id].roomId;
825
- this._removeCall(call._id);
826
- this.roomReconfigure(callRoomIdToConfigure);
827
- }
828
- _activeMessageListRemove(call) {
829
- //const callRoomIdToConfigure = activeMessages[call._id].roomId
830
- this._removeMMSRPSession(call._id);
831
- //this.roomReconfigure(callRoomIdToConfigure)
832
- }
833
- newRTCSessionCallback(event) {
834
- const session = event.session;
835
- if (this.isDND) {
836
- session.terminate({ status_code: 486, reason_phrase: 'Do Not Disturb' });
837
- return;
838
- }
839
- // stop timers on ended and failed
840
- session.on('ended', (event) => {
841
- var _a, _b;
842
- this.logger.log('Session ended for', (_b = (_a = session._remote_identity) === null || _a === void 0 ? void 0 : _a._uri) === null || _b === void 0 ? void 0 : _b._user);
843
- this._triggerListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_ENDED, session, event });
844
- const s = this.getActiveCalls[session.id];
845
- if (s) {
846
- this._activeCallListRemove(s);
847
- }
848
- this._stopCallTimer(session.id);
849
- this._removeCallStatus(session.id);
850
- this._removeCallMetrics(session.id);
851
- if (!Object.keys(this.extendedCalls).length) {
852
- this.setIsMuted(false);
853
- }
854
- });
855
- session.on('progress', (event) => {
856
- var _a, _b;
857
- this.logger.log('Session in progress for', (_b = (_a = session._remote_identity) === null || _a === void 0 ? void 0 : _a._uri) === null || _b === void 0 ? void 0 : _b._user);
858
- this._triggerListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_PROGRESS, session, event });
859
- });
860
- session.on('failed', (event) => {
861
- var _a, _b;
862
- this.logger.log('Session failed for', (_b = (_a = session._remote_identity) === null || _a === void 0 ? void 0 : _a._uri) === null || _b === void 0 ? void 0 : _b._user);
863
- this._triggerListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_FAILED, session, event });
864
- if (session.id === this.callAddingInProgress) {
865
- this.callAddingInProgress = undefined;
866
- }
867
- const s = this.getActiveCalls[session.id];
868
- if (s) {
869
- this._activeCallListRemove(s);
870
- }
871
- this._stopCallTimer(session.id);
872
- this._removeCallStatus(session.id);
873
- this._removeCallMetrics(session.id);
874
- if (!Object.keys(this.extendedCalls).length) {
875
- this.setIsMuted(false);
876
- }
877
- });
878
- session.on('confirmed', (event) => {
879
- var _a, _b;
880
- this.logger.log('Session confirmed for', (_b = (_a = session._remote_identity) === null || _a === void 0 ? void 0 : _a._uri) === null || _b === void 0 ? void 0 : _b._user);
881
- this._triggerListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_CONFIRMED, session, event });
882
- this.updateCall(session);
883
- if (session.id === this.callAddingInProgress) {
884
- this.callAddingInProgress = undefined;
885
- }
886
- });
887
- this.addCall(event);
888
- if (session.direction === 'outgoing') {
889
- const roomId = this.getActiveCalls[session.id].roomId;
890
- this.setCurrentActiveRoomId(roomId);
891
- }
892
- }
893
- newMSRPSessionCallback(event) {
894
- const session = event.session;
895
- /*if (this.isDND) {
896
- session.terminate({ status_code: 486, reason_phrase: 'Do Not Disturb' })
897
- return
898
- }*/
899
- // stop timers on ended and failed
900
- session.on('ended', (event) => {
901
- this._triggerMSRPListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_ENDED, session, event });
902
- const s = this.getActiveMessages[session.id];
903
- this._activeMessageListRemove(s);
904
- //this._stopCallTimer(session.id)
905
- //this._removeCallStatus(session.id)
906
- //this._removeCallMetrics(session.id)
907
- /*if (!Object.keys(activeMessages).length) {
908
- this.isMuted = false
909
- }*/
910
- });
911
- /*session.on('active', (event: Event) => {
912
- console.log('event newMSRPSessionCallback active', session)
913
- //this._triggerMSRPListener({ listenerType: CALL_EVENT_LISTENER_TYPE.CALL_PROGRESS, session, event })
914
- })*/
915
- session.on('failed', (event) => {
916
- this._triggerMSRPListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_FAILED, session, event });
917
- /*if (session.id === this.callAddingInProgress) {
918
- this.callAddingInProgress = undefined
919
- }*/
920
- // console.log(session, '0000000000000000000000000')
921
- const s = this.getActiveMessages[session.id];
922
- this._activeMessageListRemove(s);
923
- //this._stopCallTimer(session.id)
924
- //this._removeCallStatus(session.id)
925
- //this._removeCallMetrics(session.id)
926
- /*if (!Object.keys(activeMessages).length) {
927
- this.isMuted = false
928
- }*/
929
- });
930
- session.on('confirmed', (event) => {
931
- this._triggerMSRPListener({ listenerType: call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_CONFIRMED, session, event });
932
- this.updateMSRPSession(session);
933
- /*if (session.id === this.callAddingInProgress) {
934
- this.callAddingInProgress = undefined
935
- }*/
936
- });
937
- session.on('newMessage', (msg) => {
938
- this._addMSRPMessage(msg, session);
939
- });
940
- this.addMessageSession(session);
941
- /*if (session.direction === 'outgoing') {
942
- const roomId = this.getActiveMessages[session.id].roomId
943
- this.setCurrentActiveRoomId(roomId)
944
- }*/
945
- }
946
- setInitialized(value) {
947
- this.initialized = value;
948
- this.emit('ready', value);
949
- }
950
- begin() {
951
- if (this.isConnected()) {
952
- console.error('Connection is already established');
953
- return;
954
- }
955
- this.on(this.registeredEventName, () => {
956
- this.logger.log('Successfully registered to', this.options.socketInterfaces[0]);
957
- this.setInitialized(true);
958
- });
959
- this.on(this.unregisteredEventName, () => {
960
- this.logger.log('Unregistered from', this.options.socketInterfaces[0]);
961
- this.setInitialized(false);
962
- });
963
- this.on(this.newRTCSessionEventName, this.newRTCSessionCallback.bind(this));
964
- this.on(this.connectedEventName, () => {
965
- this.logger.log('Connected to', this.options.socketInterfaces[0]);
966
- this.isReconnecting = false;
967
- });
968
- this.on(this.disconnectedEventName, () => {
969
- if (this.isReconnecting) {
970
- return;
971
- }
972
- this.logger.log('Disconnected from', this.options.socketInterfaces[0]);
973
- this.logger.log('Reconnecting to', this.options.socketInterfaces[0]);
974
- this.isReconnecting = true;
975
- this.stop();
976
- this.setInitialized(false);
977
- setTimeout(this.start.bind(this), 5000);
978
- });
979
- this.on(this.newMSRPSessionEventName, this.newMSRPSessionCallback.bind(this));
980
- this.logger.log('Connecting to', this.options.socketInterfaces[0]);
981
- this.start();
982
- this.setMediaDevices(true);
983
- return this;
984
- }
985
- setMuteWhenJoin(value) {
986
- this.muteWhenJoinEnabled = value;
987
- this.emit('changeMuteWhenJoin', value);
988
- }
989
- setMicrophoneInputLevel(value) {
990
- this.microphoneInputLevelValue = value;
991
- this.roomReconfigure(this.currentActiveRoomId);
992
- }
993
- setSpeakerVolume(value) {
994
- this.speakerVolumeValue = value;
995
- Object.values(this.extendedCalls).forEach((call) => {
996
- if (call.audioTag) {
997
- call.audioTag.volume = value;
998
- }
999
- });
1000
- }
1001
- setAutoAnswer(value) {
1002
- this.isAutoAnswer = value;
1003
- }
1004
- setSelectedInputDevice(deviceId) {
1005
- localStorage.setItem(STORAGE_KEYS.SELECTED_INPUT_DEVICE, deviceId);
1006
- this.selectedMediaDevices.input = deviceId;
1007
- this.emit('changeActiveInputMediaDevice', deviceId);
1008
- }
1009
- setSelectedOutputDevice(deviceId) {
1010
- localStorage.setItem(STORAGE_KEYS.SELECTED_OUTPUT_DEVICE, deviceId);
1011
- this.selectedMediaDevices.output = deviceId;
1012
- this.emit('changeActiveOutputMediaDevice', deviceId);
1013
- }
1014
- setIsMSRPInitializing(value) {
1015
- this.isMSRPInitializingValue = value;
1016
- this.emit('isMSRPInitializingChanged', value);
1017
- }
1018
- _setCallMetrics(value) {
1019
- const metrics = Object.assign({}, value);
1020
- delete metrics['callId'];
1021
- this.callMetrics = Object.assign(Object.assign({}, this.callMetrics), { [value.callId]: metrics });
1022
- this.emit('changeCallMetrics', this.callMetrics);
1023
- }
1024
- _removeCallMetrics(callId) {
1025
- const callMetricsCopy = Object.assign({}, this.callMetrics);
1026
- delete callMetricsCopy[callId];
1027
- this.callMetrics = Object.assign({}, callMetricsCopy);
1028
- this.emit('changeCallMetrics', this.callMetrics);
1029
- }
1030
- _getCallQuality(call) {
1031
- const metrics = new metrics_1.default(this.metricConfig);
1032
- const probe = metrics.createProbe(call.connection, {
1033
- cid: call._id
1034
- });
1035
- const inboundKeys = [];
1036
- let inboundAudio;
1037
- probe.onreport = (probe) => {
1038
- //console.log('probe', probe)
1039
- /*const inboundMetrics = Object.entries(probe.audio).filter(([ key, value ]) => {
1040
- return value.direction === 'inbound'
1041
- })*/
1042
- //const ioo = Object.entries(probe.audio).
1043
- Object.entries(probe.audio).forEach(([key, value]) => {
1044
- if (value.direction === 'inbound' && !inboundKeys.includes(key)) {
1045
- inboundKeys.push(key);
1046
- inboundAudio = key;
1047
- }
1048
- });
1049
- /*inboundMetrics.forEach(([ key, value ]) => {
1050
- if (!inboundKeys.includes(key)) {
1051
- inboundKeys.push(key)
1052
- inboundAudio = key
1053
- }
1054
- })*/
1055
- const inboundAudioMetric = probe.audio[inboundAudio];
1056
- const metric = (0, filter_helper_1.filterObjectKeys)(inboundAudioMetric, metric_keys_to_include_1.METRIC_KEYS_TO_INCLUDE);
1057
- metric.callId = call._id;
1058
- this._setCallMetrics(metrics);
1059
- };
1060
- this.subscribe(call_event_listener_type_1.CALL_EVENT_LISTENER_TYPE.CALL_ENDED, (session) => {
1061
- if (session._id === call._id) {
1062
- metrics.stopAllProbes();
1063
- }
1064
- });
1065
- metrics.startAllProbes();
1066
- }
1067
- _triggerAddStream(event, call) {
1068
- return __awaiter(this, void 0, void 0, function* () {
1069
- this.setIsMuted(this.muteWhenJoin);
1070
- const stream = yield navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
1071
- const processedStream = (0, audio_helper_1.processAudioVolume)(stream, this.microphoneInputLevel);
1072
- const muteMicro = this.isMuted || this.muteWhenJoin;
1073
- processedStream.getTracks().forEach(track => track.enabled = !muteMicro);
1074
- this._setOriginalStream(processedStream);
1075
- yield call.connection.getSenders()[0].replaceTrack(processedStream.getTracks()[0]);
1076
- (0, audio_helper_1.syncStream)(event, call, this.selectedOutputDevice, this.speakerVolume);
1077
- this._getCallQuality(call);
1078
- this.updateCall(call);
1079
- });
1080
- }
1081
- doCall({ target, addToCurrentRoom }) {
1082
- this.checkInitialized();
1083
- if (target.length === 0) {
1084
- return console.error('Target must be a valid string');
1085
- }
1086
- this.logger.log(`Calling sip:${target}@${this.sipDomain}...`);
1087
- const call = this.call(`sip:${target}@${this.sipDomain}`, this.sipOptions);
1088
- this.callAddingInProgress = call.id;
1089
- if (addToCurrentRoom && this.currentActiveRoomId !== undefined) {
1090
- this.callChangeRoom({
1091
- callId: call.id,
1092
- roomId: this.currentActiveRoomId
1093
- });
1094
- }
1095
- call.connection.addEventListener('addstream', (event) => {
1096
- this._triggerAddStream(event, call);
1097
- });
1098
- }
1099
- initMSRP(target, body, options) {
1100
- this.checkInitialized();
1101
- if (target.length === 0) {
1102
- return console.error('Target must be a valid string');
1103
- }
1104
- const session = this.startMSRP(target, options);
1105
- session.on('active', () => {
1106
- this.addMessageSession(session);
1107
- session.sendMSRP(body);
1108
- this.setIsMSRPInitializing(false);
1109
- });
1110
- this.setIsMSRPInitializing(true);
1111
- // if (this.currentActiveRoomId !== undefined) {
1112
- // this.callChangeRoom({
1113
- // callId: call.id,
1114
- // roomId: this.currentActiveRoomId
1115
- // })
1116
- // }
1117
- //this.updateMSRPSession(session)
1118
- }
1119
- sendMSRP(msrpSessionId, body) {
1120
- const msrpSession = this.extendedMessages[msrpSessionId];
1121
- if (!msrpSession) {
1122
- throw new Error(`MSRP session with id ${msrpSessionId} doesn't exist!`);
1123
- }
1124
- msrpSession.sendMSRP(body);
1125
- }
1126
- callChangeRoom({ callId, roomId }) {
1127
- return __awaiter(this, void 0, void 0, function* () {
1128
- const oldRoomId = this.extendedCalls[callId].roomId;
1129
- this.extendedCalls[callId].roomId = roomId;
1130
- yield this.setCurrentActiveRoomId(roomId);
1131
- return Promise.all([
1132
- this.roomReconfigure(oldRoomId),
1133
- this.roomReconfigure(roomId)
1134
- ]).then(() => {
1135
- this.deleteRoomIfEmpty(oldRoomId);
1136
- this.deleteRoomIfEmpty(roomId);
1137
- });
1138
- });
1139
- }
1140
- }
1141
- exports.default = OpenSIPSJS;