opensips-js 0.1.40 → 0.1.42

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.
@@ -23547,7 +23547,7 @@ function cu(c, t) {
23547
23547
  class hS {
23548
23548
  constructor(t) {
23549
23549
  var n;
23550
- this.isAutoAnswer = !0, this.muteWhenJoinEnabled = !1, this.isDNDEnabled = !1, this.isCallWaitingEnabled = !0, this.muted = !1, this.microphoneInputLevelValue = 1, this.speakerVolumeValue = 1, this.activeRooms = {}, this.activeCalls = {}, this.extendedCalls = {}, this.conferenceNodes = {}, this.availableMediaDevices = [], this.selectedMediaDevices = {
23550
+ this.isAutoAnswer = !1, this.muteWhenJoinEnabled = !1, this.isDNDEnabled = !1, this.isCallWaitingEnabled = !0, this.muted = !1, this.microphoneInputLevelValue = 1, this.speakerVolumeValue = 1, this.activeRooms = {}, this.activeCalls = {}, this.extendedCalls = {}, this.conferenceNodes = {}, this.availableMediaDevices = [], this.selectedMediaDevices = {
23551
23551
  input: "default",
23552
23552
  output: "default"
23553
23553
  }, this.callStatus = {}, this.callTime = {}, this.callMetrics = {}, this.timeIntervals = {}, this.metricConfig = {
@@ -23555,7 +23555,7 @@ class hS {
23555
23555
  }, this.activeStreamValue = null, this.initialStreamValue = null, this.vadSession = null, this.vadSessionState = {
23556
23556
  currentMode: "clean",
23557
23557
  isSpeaking: !1
23558
- }, this.vadInterval = null, this.vadMrsInterval = null, this.ringbackTimers = {}, this.ringbackAudioContexts = {}, this.ringbackSessionProgressReceived = {}, this.hangupBeepContext = null, this.managedAudioContext = new fS(), this.context = t, this.context.on(
23558
+ }, this.vadInterval = null, this.vadMrsInterval = null, this.vadSessionGeneration = 0, this.ringbackTimers = {}, this.ringbackAudioContexts = {}, this.ringbackSessionProgressReceived = {}, this.hangupBeepContext = null, this.managedAudioContext = new fS(), this.context = t, this.context.on(
23559
23559
  this.context.newRTCSessionEventName,
23560
23560
  this.newRTCSessionCallback.bind(this)
23561
23561
  ), this.VUMeter = new cS({
@@ -24089,89 +24089,108 @@ class hS {
24089
24089
  }, this.noiseReduction.noiseCheckInterval);
24090
24090
  }
24091
24091
  async processVADForActiveStream(t = {}) {
24092
+ var m;
24092
24093
  const n = this.activeStream;
24093
- this.stopSessionVad(), this.vadSessionState = {
24094
+ this.stopSessionVad();
24095
+ const o = this.vadSessionGeneration, a = () => o !== this.vadSessionGeneration;
24096
+ this.vadSessionState = {
24094
24097
  currentMode: "clean",
24095
24098
  isSpeaking: !1
24096
24099
  };
24097
- const o = await this.managedAudioContext.getContext(), a = await hv(n, o, 150);
24098
- let s = !1;
24099
- const r = Object.values(this.extendedCalls).filter((d) => d.roomId === this.currentActiveRoomId), _ = await this.MicVAD.new({
24100
- getStream: () => new Promise((d) => d(n)),
24100
+ const s = await this.managedAudioContext.getContext();
24101
+ if (a())
24102
+ return;
24103
+ const r = await hv(n, s, 150);
24104
+ if (a())
24105
+ return;
24106
+ let _ = !1;
24107
+ const d = Object.values(this.extendedCalls).filter((T) => T.roomId === this.currentActiveRoomId), h = await this.MicVAD.new({
24108
+ getStream: () => new Promise((T) => T(n)),
24109
+ pauseStream: async () => {
24110
+ },
24111
+ resumeStream: async (T) => T,
24101
24112
  ...uS,
24102
24113
  ...this.noiseReduction.vadConfig,
24103
24114
  baseAssetPath: this.noiseReduction.baseAssetPath,
24104
24115
  onnxWASMBasePath: this.noiseReduction.onnxWASMBasePath,
24105
24116
  onFrameProcessed: () => {
24106
- var d;
24107
- if (!s) {
24108
- if (s = !0, console.log("✅ VAD initialized, starting background noise monitoring"), this.noiseReduction.mode === "enabled") {
24117
+ var T, S;
24118
+ if (!a() && !_) {
24119
+ if (_ = !0, console.log("✅ VAD initialized, starting background noise monitoring"), this.noiseReduction.mode === "enabled") {
24109
24120
  if (t && Object.keys(t).length)
24110
- Object.keys(t).forEach((h) => {
24111
- const m = this.extendedCalls[h];
24112
- if (m && m.connection.getSenders()[0]) {
24113
- const T = cu(a.stream, t[h]);
24114
- m.connection.getSenders()[0].replaceTrack(T.getAudioTracks()[0]);
24121
+ Object.keys(t).forEach((E) => {
24122
+ const C = this.extendedCalls[E];
24123
+ if (C && C.connection.getSenders()[0]) {
24124
+ const A = cu(r.stream, t[E]);
24125
+ C.connection.getSenders()[0].replaceTrack(A.getAudioTracks()[0]);
24115
24126
  }
24116
24127
  });
24117
24128
  else {
24118
- const h = r[0];
24119
- h.connection.getSenders()[0] && h.connection.getSenders()[0].replaceTrack(a.stream.getAudioTracks()[0]);
24129
+ const E = d[0], C = (T = E == null ? void 0 : E.connection) == null ? void 0 : T.getSenders()[0], A = r.stream.getAudioTracks()[0];
24130
+ C && C.replaceTrack(A);
24120
24131
  }
24121
24132
  return;
24122
24133
  }
24123
24134
  if (!this.vadSessionState) {
24124
- console.error("[processVAD] CRITICAL: State not found"), (d = this.context.logger) == null || d.error("[processVAD] CRITICAL: State not found");
24135
+ console.error("[processVAD] CRITICAL: State not found"), (S = this.context.logger) == null || S.error("[processVAD] CRITICAL: State not found");
24125
24136
  return;
24126
24137
  }
24127
24138
  this.startNoiseMonitor({
24128
24139
  stream: n,
24129
24140
  onNoiseDetected: async () => {
24130
- var h;
24131
- if (console.log("[processVad] - Replace track with Vad Controlled"), (h = this.context.logger) == null || h.log("[processVad] - Replace track with Vad Controlled"), t && Object.keys(t).length)
24132
- Object.keys(t).forEach((m) => {
24133
- const T = this.extendedCalls[m];
24134
- if (T && T.connection.getSenders()[0]) {
24135
- const S = cu(a.stream, t[m]);
24136
- T.connection.getSenders()[0].replaceTrack(S.getAudioTracks()[0]);
24141
+ var E;
24142
+ if (console.log("[processVad] - Replace track with Vad Controlled"), (E = this.context.logger) == null || E.log("[processVad] - Replace track with Vad Controlled"), t && Object.keys(t).length)
24143
+ Object.keys(t).forEach((C) => {
24144
+ const A = this.extendedCalls[C];
24145
+ if (A && A.connection.getSenders()[0]) {
24146
+ const R = cu(r.stream, t[C]);
24147
+ A.connection.getSenders()[0].replaceTrack(R.getAudioTracks()[0]);
24137
24148
  }
24138
24149
  });
24139
24150
  else {
24140
- const m = r[0];
24141
- m.connection.getSenders()[0] && m.connection.getSenders()[0].replaceTrack(a.stream.getAudioTracks()[0]);
24151
+ const C = d[0];
24152
+ C.connection.getSenders()[0] && C.connection.getSenders()[0].replaceTrack(r.stream.getAudioTracks()[0]);
24142
24153
  }
24143
24154
  },
24144
24155
  onNoiseStop: async () => {
24145
24156
  if (console.log("Replace track with Original"), t && Object.keys(t).length)
24146
- Object.keys(t).forEach((h) => {
24147
- const m = this.extendedCalls[h];
24148
- if (!m)
24157
+ Object.keys(t).forEach((E) => {
24158
+ const C = this.extendedCalls[E];
24159
+ if (!C)
24149
24160
  return;
24150
- const T = m.connection.getSenders()[0];
24151
- if (T && T.track && T.transport && T.transport.state !== "closed" && T.transport.state !== "failed") {
24152
- const S = cu(n, t[h]);
24153
- T.replaceTrack(S.getAudioTracks()[0]);
24161
+ const A = C.connection.getSenders()[0];
24162
+ if (A && A.track && A.transport && A.transport.state !== "closed" && A.transport.state !== "failed") {
24163
+ const R = cu(n, t[E]);
24164
+ A.replaceTrack(R.getAudioTracks()[0]);
24154
24165
  }
24155
24166
  });
24156
24167
  else {
24157
- const h = r[0].connection.getSenders()[0];
24158
- h && h.track && h.transport && h.transport.state !== "closed" && h.transport.state !== "failed" && h.replaceTrack(n.getAudioTracks()[0]);
24168
+ const E = d[0].connection.getSenders()[0];
24169
+ E && E.track && E.transport && E.transport.state !== "closed" && E.transport.state !== "failed" && E.replaceTrack(n.getAudioTracks()[0]);
24159
24170
  }
24160
24171
  }
24161
24172
  });
24162
24173
  }
24163
24174
  },
24164
24175
  onSpeechStart: () => {
24165
- console.log("🎤 Speech started"), a.setSpeaking(!0), this.vadSessionState.isSpeaking = !0;
24176
+ a() || (console.log("🎤 Speech started"), r.setSpeaking(!0), this.vadSessionState.isSpeaking = !0);
24166
24177
  },
24167
24178
  onSpeechEnd: () => {
24168
- console.log("🛑 Speech end"), a.setSpeaking(!1), this.vadSessionState.isSpeaking = !1;
24179
+ a() || (console.log("🛑 Speech end"), r.setSpeaking(!1), this.vadSessionState.isSpeaking = !1);
24169
24180
  }
24170
24181
  });
24171
- this.vadSession && (this.vadSession.pause(), this.vadSession = null), this.vadSession = _, _.start();
24182
+ if (a()) {
24183
+ try {
24184
+ h.pause();
24185
+ } catch (T) {
24186
+ (m = this.context.logger) == null || m.error("[processVADForActiveStream] Error pausing stale vadSession:", T);
24187
+ }
24188
+ return;
24189
+ }
24190
+ this.vadSession && (this.vadSession.pause(), this.vadSession = null), this.vadSession = h, h.start();
24172
24191
  }
24173
24192
  stopSessionVad() {
24174
- this.vadSession && (this.vadSession.pause(), this.vadSession = null), this.vadInterval && (clearInterval(this.vadInterval), this.vadInterval = null), this.vadMrsInterval && (clearInterval(this.vadMrsInterval), this.vadMrsInterval = null), this.vadSessionState && (this.vadSessionState = {
24193
+ this.vadSessionGeneration++, this.vadSession && (this.vadSession.pause(), this.vadSession = null), this.vadInterval && (clearInterval(this.vadInterval), this.vadInterval = null), this.vadMrsInterval && (clearInterval(this.vadMrsInterval), this.vadMrsInterval = null), this.vadSessionState && (this.vadSessionState = {
24175
24194
  currentMode: "clean",
24176
24195
  isSpeaking: !1
24177
24196
  }, this.context.emit("changeNoiseReductionState", !1));