@voicenter-team/opensips-js 1.0.15 → 1.0.16

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