@voicenter-team/opensips-js 1.0.72 → 1.0.74

Sign up to get free protection for your applications and to get access to all the features.
@@ -20623,8 +20623,8 @@ const uT = /* @__PURE__ */ xt(aT), cT = ["mos_in", "codec_in", "delta_KBytes_in"
20623
20623
  CALL_PROGRESS: "progress",
20624
20624
  CALL_ENDED: "ended"
20625
20625
  }, fT = 0, Wl = {
20626
- SELECTED_INPUT_DEVICE: "selectedInputDevice",
20627
- SELECTED_OUTPUT_DEVICE: "selectedOutputDevice"
20626
+ SELECTED_INPUT_DEVICE: "OpensipsJSInputDevice",
20627
+ SELECTED_OUTPUT_DEVICE: "OpensipsJSOutputDevice"
20628
20628
  };
20629
20629
  class bT extends Jg {
20630
20630
  constructor(r, n) {
@@ -20726,12 +20726,6 @@ class bT extends Jg {
20726
20726
  video: !1
20727
20727
  };
20728
20728
  }
20729
- get getInputDefaultDevice() {
20730
- return this.getInputDeviceList.find((r) => r.deviceId === "default");
20731
- }
20732
- get getOutputDefaultDevice() {
20733
- return this.getOutputDeviceList.find((r) => r.deviceId === "default");
20734
- }
20735
20729
  get selectedInputDevice() {
20736
20730
  return this.selectedMediaDevices.input;
20737
20731
  }
@@ -20749,17 +20743,14 @@ class bT extends Jg {
20749
20743
  const r = await navigator.mediaDevices.enumerateDevices();
20750
20744
  this.setAvailableMediaDevices(r);
20751
20745
  }
20752
- async setMediaDevices(r = !1) {
20753
- var s, p;
20754
- this.selectedMediaDevices.input = localStorage.getItem(Wl.SELECTED_INPUT_DEVICE) || "default", this.selectedMediaDevices.output = localStorage.getItem(Wl.SELECTED_OUTPUT_DEVICE) || "default", (await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints)).getTracks().forEach((h) => h.stop());
20755
- const o = await navigator.mediaDevices.enumerateDevices();
20756
- this.setAvailableMediaDevices(o);
20757
- const a = r && ((s = this.getInputDefaultDevice) == null ? void 0 : s.deviceId) || "", t = r && ((p = this.getOutputDefaultDevice) == null ? void 0 : p.deviceId) || "";
20758
- await this.setMicrophone(a), await this.setSpeaker(t), navigator.mediaDevices.ondevicechange = async () => {
20759
- await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);
20760
- const h = await navigator.mediaDevices.enumerateDevices();
20761
- this.setAvailableMediaDevices(h);
20762
- };
20746
+ async initializeMediaDevices() {
20747
+ const r = localStorage.getItem(Wl.SELECTED_INPUT_DEVICE) || "default", n = localStorage.getItem(Wl.SELECTED_OUTPUT_DEVICE) || "default";
20748
+ (await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints)).getTracks().forEach((t) => t.stop());
20749
+ const a = await navigator.mediaDevices.enumerateDevices();
20750
+ this.setAvailableMediaDevices(a), await this.setMicrophone(r), await this.setSpeaker(n), navigator.mediaDevices.addEventListener("devicechange", async () => {
20751
+ const t = await navigator.mediaDevices.enumerateDevices();
20752
+ this.setAvailableMediaDevices(t);
20753
+ });
20763
20754
  }
20764
20755
  setCallTime(r) {
20765
20756
  const n = { ...r };
@@ -20809,11 +20800,17 @@ class bT extends Jg {
20809
20800
  setIsMuted(r) {
20810
20801
  this.muted = r, this.emit("changeIsMuted", r);
20811
20802
  }
20812
- doMute(r) {
20803
+ processMute(r) {
20813
20804
  const n = this.currentActiveRoomId;
20814
20805
  this.setIsMuted(r), this.initialStreamValue.getTracks().forEach((o) => o.enabled = !r), this.roomReconfigure(n);
20815
20806
  }
20816
- async doCallHold({ callId: r, toHold: n, automatic: o }) {
20807
+ mute() {
20808
+ this.processMute(!0);
20809
+ }
20810
+ unmute() {
20811
+ this.processMute(!1);
20812
+ }
20813
+ async processHold({ callId: r, toHold: n, automatic: o }) {
20817
20814
  const a = this.extendedCalls[r];
20818
20815
  a._automaticHold = o ?? !1, await new Promise((p) => {
20819
20816
  const h = () => {
@@ -20826,12 +20823,25 @@ class bT extends Jg {
20826
20823
  );
20827
20824
  s.length > 1 && await this.doConference(s);
20828
20825
  }
20826
+ holdCall(r, n = !1) {
20827
+ return this.processHold({
20828
+ callId: r,
20829
+ automatic: n,
20830
+ toHold: !0
20831
+ });
20832
+ }
20833
+ unholdCall(r) {
20834
+ return this.processHold({
20835
+ callId: r,
20836
+ toHold: !1
20837
+ });
20838
+ }
20829
20839
  cancelAllOutgoingUnanswered() {
20830
- Object.values(this.getActiveCalls).filter((r) => r.direction === "outgoing" && r.status === fT).forEach((r) => this.callTerminate(r._id));
20840
+ Object.values(this.getActiveCalls).filter((r) => r.direction === "outgoing" && r.status === fT).forEach((r) => this.terminateCall(r._id));
20831
20841
  }
20832
- callAnswer(r) {
20842
+ answerCall(r) {
20833
20843
  const n = this.extendedCalls[r];
20834
- this.cancelAllOutgoingUnanswered(), n.answer(this.sipOptions), this.updateCall(n), this.setCurrentActiveRoomId(n.roomId), n.connection.addEventListener("addstream", async (o) => {
20844
+ this.cancelAllOutgoingUnanswered(), n.answer(this.sipOptions), this.updateCall(n), this.setActiveRoom(n.roomId), n.connection.addEventListener("addstream", async (o) => {
20835
20845
  this.triggerAddStream(o, n);
20836
20846
  });
20837
20847
  }
@@ -20839,11 +20849,11 @@ class bT extends Jg {
20839
20849
  const n = this.extendedMessages[r];
20840
20850
  n.answer(this.sipOptions), this.updateMSRPSession(n);
20841
20851
  }
20842
- async callMove(r, n) {
20852
+ async moveCall(r, n) {
20843
20853
  this.updateCallStatus({
20844
20854
  callId: r,
20845
20855
  isMoving: !0
20846
- }), await this.callChangeRoom({
20856
+ }), await this.processRoomChange({
20847
20857
  callId: r,
20848
20858
  roomId: n
20849
20859
  }), this.updateCallStatus({
@@ -20994,16 +21004,9 @@ class bT extends Jg {
20994
21004
  }), n.length === 0)
20995
21005
  this.deleteRoomIfEmpty(r);
20996
21006
  else if (n.length === 1 && this.currentActiveRoomId !== r)
20997
- n[0].isOnHold().local || await this.doCallHold({
20998
- callId: n[0].id,
20999
- toHold: !0,
21000
- automatic: !0
21001
- });
21007
+ n[0].isOnHold().local || await this.holdCall(n[0].id, !0);
21002
21008
  else if (n.length === 1 && this.currentActiveRoomId === r) {
21003
- if (n[0].isOnHold().local && n[0]._automaticHold && await this.doCallHold({
21004
- callId: n[0].id,
21005
- toHold: !1
21006
- }), n[0].connection && n[0].connection.getSenders()[0]) {
21009
+ if (n[0].isOnHold().local && n[0]._automaticHold && await this.unholdCall(n[0].id), n[0].connection && n[0].connection.getSenders()[0]) {
21007
21010
  const o = this.getActiveStream();
21008
21011
  await n[0].connection.getSenders()[0].replaceTrack(o.getTracks()[0]), this.muteReconfigure(n[0]);
21009
21012
  }
@@ -21012,10 +21015,7 @@ class bT extends Jg {
21012
21015
  }
21013
21016
  async doConference(r) {
21014
21017
  await sf.forEach(r, async (o) => {
21015
- o._localHold && await this.doCallHold({
21016
- callId: o._id,
21017
- toHold: !1
21018
- });
21018
+ o._localHold && await this.unholdCall(o._id);
21019
21019
  });
21020
21020
  const n = [];
21021
21021
  r.forEach((o) => {
@@ -21037,13 +21037,19 @@ class bT extends Jg {
21037
21037
  o.connection.getSenders()[0] && (await o.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]), this.muteReconfigure(o));
21038
21038
  });
21039
21039
  }
21040
- muteCaller(r, n) {
21040
+ processCallerMute(r, n) {
21041
21041
  const o = this.extendedCalls[r];
21042
21042
  o && o.connection.getReceivers().length && (o.localMuted = n, o.connection.getReceivers().forEach((a) => {
21043
21043
  a.track.enabled = !n;
21044
21044
  }), this.updateCall(o));
21045
21045
  }
21046
- callTerminate(r) {
21046
+ muteCaller(r) {
21047
+ this.processCallerMute(r, !0);
21048
+ }
21049
+ unmuteCaller(r) {
21050
+ this.processCallerMute(r, !1);
21051
+ }
21052
+ terminateCall(r) {
21047
21053
  const n = this.extendedCalls[r];
21048
21054
  n._status !== 8 && n.terminate();
21049
21055
  }
@@ -21051,7 +21057,7 @@ class bT extends Jg {
21051
21057
  const n = this.extendedMessages[r];
21052
21058
  n._status !== 8 && n.terminate();
21053
21059
  }
21054
- callTransfer(r, n) {
21060
+ transferCall(r, n) {
21055
21061
  if (n.toString().length === 0)
21056
21062
  return new Error("Target must be passed");
21057
21063
  const o = this.extendedCalls[r];
@@ -21069,7 +21075,7 @@ class bT extends Jg {
21069
21075
  isTransferring: !0
21070
21076
  }), o.refer(`sip:${n}@${this.sipDomain}`), this.updateCall(o);
21071
21077
  }
21072
- callMerge(r) {
21078
+ mergeCall(r) {
21073
21079
  const n = Object.values(this.extendedCalls).filter((t) => t.roomId === r);
21074
21080
  if (n.length !== 2)
21075
21081
  return;
@@ -21104,7 +21110,7 @@ class bT extends Jg {
21104
21110
  }, 1e3);
21105
21111
  this.setTimeInterval(r, o);
21106
21112
  }
21107
- async setCurrentActiveRoomId(r) {
21113
+ async setActiveRoom(r) {
21108
21114
  const n = this.currentActiveRoomId;
21109
21115
  r !== n && (this.currentActiveRoomId = r, await this.roomReconfigure(n), await this.roomReconfigure(r));
21110
21116
  }
@@ -21147,7 +21153,7 @@ class bT extends Jg {
21147
21153
  }), this.deleteRoomIfEmpty(a));
21148
21154
  })) : n.direction === "outgoing" && this.startCallTimer(n.id);
21149
21155
  const s = n, p = this.hasAutoAnswerHeaders(r), h = s.direction === "incoming" && !this.hasActiveCalls && (p || this.autoAnswer);
21150
- s.roomId = a, s.localMuted = !1, s.autoAnswer = h, h ? this._addCall(s, !1) : this._addCall(s), this.addCallStatus(n.id), this.addRoom(t), h && this.callAnswer(s._id);
21156
+ s.roomId = a, s.localMuted = !1, s.autoAnswer = h, h ? this._addCall(s, !1) : this._addCall(s), this.addCallStatus(n.id), this.addRoom(t), h && this.answerCall(s._id);
21151
21157
  }
21152
21158
  addMessageSession(r) {
21153
21159
  if (!r._id || this.getActiveMessages[r._id] !== void 0)
@@ -21241,7 +21247,7 @@ class bT extends Jg {
21241
21247
  }), this.updateCall(n), n.id === this.callAddingInProgress && (this.callAddingInProgress = void 0);
21242
21248
  }), await this.addCall(r), n.direction === "outgoing") {
21243
21249
  const o = this.getActiveCalls[n.id].roomId;
21244
- this.setCurrentActiveRoomId(o);
21250
+ this.setActiveRoom(o);
21245
21251
  }
21246
21252
  }
21247
21253
  newMSRPSessionCallback(r) {
@@ -21306,7 +21312,7 @@ class bT extends Jg {
21306
21312
  ), this.on(
21307
21313
  this.newMSRPSessionEventName,
21308
21314
  this.newMSRPSessionCallback.bind(this)
21309
- ), this.logger.log("Connecting to", this.options.socketInterfaces[0]), this.start(), this.setMediaDevices(!0), this;
21315
+ ), this.logger.log("Connecting to", this.options.socketInterfaces[0]), this.start(), this.initializeMediaDevices(), this;
21310
21316
  }
21311
21317
  setMuteWhenJoin(r) {
21312
21318
  this.muteWhenJoinEnabled = r, this.emit("changeMuteWhenJoin", r);
@@ -21374,7 +21380,7 @@ class bT extends Jg {
21374
21380
  const o = lf(this.initialStreamValue, this.microphoneInputLevel), a = this.isMuted || this.muteWhenJoin;
21375
21381
  o.getTracks().forEach((t) => t.enabled = !a), this.setActiveStream(o), await n.connection.getSenders()[0].replaceTrack(o.getTracks()[0]), nv(r, n, this.selectedOutputDevice, this.speakerVolume), this.setupVUMeter(r.stream, n._id), this.getCallQuality(n), this.updateCall(n);
21376
21382
  }
21377
- doCall({ target: r, addToCurrentRoom: n }) {
21383
+ initCall(r, n) {
21378
21384
  if (this.checkInitialized(), r.length === 0)
21379
21385
  return console.error("Target must be a valid string");
21380
21386
  this.logger.log(`Calling sip:${r}@${this.sipDomain}...`);
@@ -21382,7 +21388,7 @@ class bT extends Jg {
21382
21388
  `sip:${r}@${this.sipDomain}`,
21383
21389
  this.sipOptions
21384
21390
  );
21385
- this.callAddingInProgress = o.id, n && this.currentActiveRoomId !== void 0 && this.callChangeRoom({
21391
+ this.callAddingInProgress = o.id, n && this.currentActiveRoomId !== void 0 && this.processRoomChange({
21386
21392
  callId: o.id,
21387
21393
  roomId: this.currentActiveRoomId
21388
21394
  }), o.connection.addEventListener("addstream", (a) => {
@@ -21403,11 +21409,11 @@ class bT extends Jg {
21403
21409
  throw new Error(`MSRP session with id ${r} doesn't exist!`);
21404
21410
  o.sendMSRP(n);
21405
21411
  }
21406
- async callChangeRoom({ callId: r, roomId: n }) {
21412
+ async processRoomChange({ callId: r, roomId: n }) {
21407
21413
  const o = this.extendedCalls[r].roomId;
21408
21414
  this.extendedCalls[r].roomId = n;
21409
21415
  const a = this.extendedCalls[r];
21410
- return this.updateCall(a), await this.setCurrentActiveRoomId(n), Promise.all([
21416
+ return this.updateCall(a), await this.setActiveRoom(n), Promise.all([
21411
21417
  this.roomReconfigure(o),
21412
21418
  this.roomReconfigure(n)
21413
21419
  ]).then(() => {