quickvo-sdk-js 0.6.4 → 0.6.5

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/dist/index.js CHANGED
@@ -737,8 +737,6 @@ class AudioMediaContext {
737
737
  Z(this, "audioContext", new (window.AudioContext || window.webkitAudioContext)());
738
738
  // 媒体流音频源节点
739
739
  Z(this, "mediaStreamAudioSourceNode");
740
- // 媒体流音频源节点
741
- Z(this, "destination");
742
740
  // 增益节点 (自动增益)
743
741
  Z(this, "autoGainNode");
744
742
  // 滤波器节点 (噪声抑制)
@@ -755,11 +753,6 @@ class AudioMediaContext {
755
753
  * 停止
756
754
  */
757
755
  Z(this, "stop", () => {
758
- {
759
- const I = this.destination.stream.getTracks();
760
- for (const u of I)
761
- u.enabled = !1, u.stop(), this.stream.removeTrack(u);
762
- }
763
756
  {
764
757
  const I = this.stream.getTracks();
765
758
  for (const u of I)
@@ -777,13 +770,12 @@ class AudioMediaContext {
777
770
  /**
778
771
  * 获取数据流
779
772
  */
780
- Z(this, "getStream", () => this.destination.stream);
781
- // getStream = () => this.mediaStreamAudioSourceNode.mediaStream
773
+ Z(this, "getStream", () => this.mediaStreamAudioSourceNode.mediaStream);
782
774
  /**
783
775
  * 静音
784
776
  */
785
777
  Z(this, "setMute", (I = !0) => {
786
- I ? this.analyserNode.disconnect(this.destination) : this.analyserNode.connect(this.destination);
778
+ I ? this.gainNode.disconnect(this.audioContext.destination) : this.gainNode.connect(this.audioContext.destination);
787
779
  });
788
780
  /**
789
781
  * 设置音量
@@ -821,12 +813,13 @@ class AudioMediaContext {
821
813
  */
822
814
  Z(this, "setFilter", (I = {}) => {
823
815
  this.options = { ...this.options, ...I };
824
- const { autoGainControl: u, noiseSuppression: E, echoCancellation: _ } = this.options, { mediaStreamAudioSourceNode: k, autoGainNode: e, biquadFilterNode: n, delayNode: O, gainNode: $ } = this, N = k;
816
+ const { autoGainControl: u, noiseSuppression: E, echoCancellation: _ } = this.options, { mediaStreamAudioSourceNode: k, autoGainNode: e, biquadFilterNode: n, delayNode: O, gainNode: $ } = this;
817
+ let N = k;
825
818
  return u && N.connect(e), E && N.connect(n), _ && N.connect(O), N.connect($), I;
826
819
  });
827
- this.stream.addTrack(I), this.audio.srcObject = this.stream, this.audioContext = new (window.AudioContext || window.webkitAudioContext)(), this.mediaStreamAudioSourceNode = this.audioContext.createMediaStreamSource(this.stream), this.destination = this.audioContext.createMediaStreamDestination(), this.autoGainNode = this.audioContext.createGain(), this.autoGainNode.gain.setValueAtTime(0.8, this.audioContext.currentTime), this.biquadFilterNode = this.audioContext.createBiquadFilter(), this.biquadFilterNode.type = "lowpass", this.biquadFilterNode.frequency.value = 1e3, this.delayNode = this.audioContext.createDelay(), this.delayNode.delayTime.value = 0.5, this.gainNode = this.audioContext.createGain(), this.gainNode.gain.setValueAtTime(this.gain, this.audioContext.currentTime), this.analyserNode = this.audioContext.createAnalyser(), this.analyserNode.fftSize = 512, this.analyserArrayData = new Uint8Array(this.analyserNode.frequencyBinCount);
828
- const { gainNode: u, analyserNode: E, destination: _ } = this;
829
- u.connect(E), E.connect(_), this.audioContext.state === "suspended" && (this.audioContext.resume(), document.addEventListener("click", () => this.audioContext.resume(), { once: !0 })), this.setFilter();
820
+ this.stream.addTrack(I), this.audio.srcObject = this.stream, this.audioContext = new (window.AudioContext || window.webkitAudioContext)(), this.mediaStreamAudioSourceNode = this.audioContext.createMediaStreamSource(this.stream), this.autoGainNode = this.audioContext.createGain(), this.autoGainNode.gain.setValueAtTime(0.8, this.audioContext.currentTime), this.biquadFilterNode = this.audioContext.createBiquadFilter(), this.biquadFilterNode.type = "lowpass", this.biquadFilterNode.frequency.value = 1e3, this.delayNode = this.audioContext.createDelay(), this.delayNode.delayTime.value = 0.5, this.gainNode = this.audioContext.createGain(), this.gainNode.gain.setValueAtTime(this.gain, this.audioContext.currentTime), this.analyserNode = this.audioContext.createAnalyser(), this.analyserNode.fftSize = 512, this.analyserArrayData = new Uint8Array(this.analyserNode.frequencyBinCount);
821
+ const { gainNode: u, analyserNode: E } = this;
822
+ u.connect(E), this.audioContext.state === "suspended" && (this.audioContext.resume(), document.addEventListener("click", () => this.audioContext.resume(), { once: !0 })), this.setFilter();
830
823
  }
831
824
  }
832
825
  class VideoMediaContext {
@@ -7185,7 +7178,7 @@ const noLogEvents = ["heartbeat", "onNetQuality", "networkQualityChange"], compr
7185
7178
  }
7186
7179
  return a;
7187
7180
  };
7188
- var wt, dt, xt, yt, kt, Pt, Bt, Lt, jt, Nt, Zt, Ft, Ht;
7181
+ var wt, dt, xt, yt, kt, Pt, Lt, Bt, jt, Nt, Zt, Ft, Ht;
7189
7182
  class CallsWebSocket {
7190
7183
  // 状态
7191
7184
  constructor(I) {
@@ -7220,11 +7213,11 @@ class CallsWebSocket {
7220
7213
  return E === 1e3 && (_ === "quit success!" || _ === "replace old connection!") && (u = !1), u;
7221
7214
  });
7222
7215
  // 重连成功
7223
- at(this, Bt, async (I) => {
7216
+ at(this, Lt, async (I) => {
7224
7217
  J(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 重连成功", I), this.state = "connected", this.onReconnectSuccess(I);
7225
7218
  });
7226
7219
  // 重连停止
7227
- at(this, Lt, async (I) => {
7220
+ at(this, Bt, async (I) => {
7228
7221
  J(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 重连停止", I), this.close(), this.state = "closed", this.onReconnectStop(I);
7229
7222
  });
7230
7223
  // 自定义心跳规则
@@ -7322,8 +7315,8 @@ class CallsWebSocket {
7322
7315
  onMessage: J(this, Ht),
7323
7316
  checkReconnect: J(this, Pt),
7324
7317
  getHeartbeatMsg: J(this, jt),
7325
- onReconnectSuccess: J(this, Bt),
7326
- onReconnectStop: J(this, Lt)
7318
+ onReconnectSuccess: J(this, Lt),
7319
+ onReconnectStop: J(this, Bt)
7327
7320
  })), this.state = "connecting", await J(this, wt).connect(), this.state = "connected", J(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 当前广播事件", J(this, kt)), u(J(this, wt));
7328
7321
  }));
7329
7322
  /**
@@ -7400,7 +7393,7 @@ class CallsWebSocket {
7400
7393
  Ot(this, dt, { ...J(this, dt), ...I });
7401
7394
  }
7402
7395
  }
7403
- wt = new WeakMap(), dt = new WeakMap(), xt = new WeakMap(), yt = new WeakMap(), kt = new WeakMap(), Pt = new WeakMap(), Bt = new WeakMap(), Lt = new WeakMap(), jt = new WeakMap(), Nt = new WeakMap(), Zt = new WeakMap(), Ft = new WeakMap(), Ht = new WeakMap();
7396
+ wt = new WeakMap(), dt = new WeakMap(), xt = new WeakMap(), yt = new WeakMap(), kt = new WeakMap(), Pt = new WeakMap(), Lt = new WeakMap(), Bt = new WeakMap(), jt = new WeakMap(), Nt = new WeakMap(), Zt = new WeakMap(), Ft = new WeakMap(), Ht = new WeakMap();
7404
7397
  var y = Object.defineProperty, x = (a) => {
7405
7398
  throw TypeError(a);
7406
7399
  }, g = (a, I, u) => I in a ? y(a, I, { enumerable: !0, configurable: !0, writable: !0, value: u }) : a[I] = u, h = (a, I, u) => g(a, typeof I != "symbol" ? I + "" : I, u), b = (a, I, u) => I.has(a) || x("Cannot " + u), o = (a, I, u) => (b(a, I, "read from private field"), u ? u.call(a) : I.get(a)), f = (a, I, u) => I.has(a) ? x("Cannot add the same private member more than once") : I instanceof WeakSet ? I.add(a) : I.set(a, u), p = (a, I, u, E) => (b(a, I, "write to private field"), I.set(a, u), u), d, c, l;
@@ -7528,7 +7521,7 @@ class RoomBase {
7528
7521
  const $ = O(I), N = { origin: n, type: $, app_id: E, user_id: _, ins_id: k, desc: u }, D = btoa(encodeURI(JSON.stringify(N))), q = `${e}/upload/log?log_key=${D}`;
7529
7522
  {
7530
7523
  const P = localStorage.getItem("#quickvo.logs") || JSON.stringify([]), V = new TextEncoder().encode(P), Q = pako.deflate(V, { gzip: !0 });
7531
- console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: reportLogs", { obj: N, url: q, size: ot(Q.byteLength) }), fetch(q, { headers: { "Content-Type": "multipart/form-data" }, method: "POST", body: Q });
7524
+ this.options.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: reportLogs", { obj: N, url: q, size: ot(Q.byteLength) }), fetch(q, { headers: { "Content-Type": "multipart/form-data" }, method: "POST", body: Q });
7532
7525
  }
7533
7526
  }
7534
7527
  });
@@ -7565,7 +7558,7 @@ class RoomBase {
7565
7558
  const I = await navigator.mediaDevices.enumerateDevices();
7566
7559
  I.find((E) => E.kind === "audioinput") || (this.mediaDevicesErrInfo.microphoneCamera_audio = "audioinput is not available."), I.find((E) => E.kind === "videoinput") || (this.mediaDevicesErrInfo.microphoneCamera_video = "videoinput is not available.");
7567
7560
  } catch (I) {
7568
- console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->Breathe:error", I);
7561
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: getMediaDevicesErrInfo is error.", I);
7569
7562
  }
7570
7563
  return this.mediaDevicesErrInfo;
7571
7564
  });
@@ -8268,7 +8261,13 @@ class RoomPeer extends RoomUsers {
8268
8261
  });
8269
8262
  // 初始化假数据流
8270
8263
  at(this, Gt, () => {
8271
- for (const u of mediaType_keys)
8264
+ for (const u of mediaType_keys) {
8265
+ const E = J(this, gt).get(u);
8266
+ if (E) {
8267
+ const _ = E.getTracks();
8268
+ for (const k of _)
8269
+ k.stop();
8270
+ }
8272
8271
  switch (u) {
8273
8272
  case "microphoneCamera_audio":
8274
8273
  J(this, gt).set("microphoneCamera_audio", createMutedAudioStream());
@@ -8283,6 +8282,7 @@ class RoomPeer extends RoomUsers {
8283
8282
  J(this, gt).set("screenSharing_video", createFakeVideoStream());
8284
8283
  break;
8285
8284
  }
8285
+ }
8286
8286
  });
8287
8287
  // 获取假数据流
8288
8288
  at(this, At, (u) => J(this, gt).get(u));
@@ -8325,11 +8325,11 @@ class RoomPeer extends RoomUsers {
8325
8325
  u.length === 0 && (this.peerIns.addTransceiver("audio", { direction: "sendonly" }), this.peerIns.addTransceiver("video", { direction: "sendonly" }));
8326
8326
  const E = [];
8327
8327
  for (const _ of u) {
8328
- if (this.transceiverMap.has(_)) continue;
8329
- const k = J(this, At).call(this, _), [e] = k.getTracks(), n = this.peerIns.addTransceiver(e, { direction: "sendonly" });
8330
- this.transceiverMap.set(_, n), E.push(_);
8328
+ if (this.transceiverMap.get(_)) continue;
8329
+ const e = J(this, At).call(this, _), [n] = e.getTracks(), O = this.peerIns.addTransceiver(n, { direction: "sendonly" });
8330
+ this.transceiverMap.set(_, O), E.push(_);
8331
8331
  }
8332
- if (u.length === 0 || E.length) {
8332
+ if (u.length === 0 || E.length !== 0) {
8333
8333
  const _ = await this.peerIns.createOffer();
8334
8334
  if (this.options.debug) {
8335
8335
  const k = libExports.parse(_.sdp), e = ft(k.media, ["mid", "msid", "type"]);
@@ -8747,20 +8747,17 @@ class RoomCalls extends RoomPeer {
8747
8747
  typeof u == "string" && (u = [u]);
8748
8748
  const { userId: e = "" } = this.options;
8749
8749
  for (const O of u)
8750
- if (this.setLocalStreamActiveMap.set(O, E), E === !1) {
8751
- this.removeUserMediaStreamContext(e, O);
8752
- continue;
8753
- }
8750
+ this.removeUserMediaStreamContext(e, O), this.setLocalStreamActiveMap.set(O, E);
8754
8751
  if (E) {
8755
- if (u.includes("microphoneCamera_audio") && u.includes("microphoneCamera_video") && await this.initLocalStream("microphoneCamera"), u.includes("microphoneCamera_audio") && await this.initLocalStream("microphoneCamera_audio"), u.includes("microphoneCamera_video") && await this.initLocalStream("microphoneCamera_video"), u.includes("screenSharing_audio") && u.includes("screenSharing_video") && await this.initLocalStream("screenSharing"), u.includes("screenSharing_audio") && !u.includes("screenSharing_video") && await this.initLocalStream("screenSharing_audio"), u.includes("screenSharing_video") && !u.includes("screenSharing_audio") && await this.initLocalStream("screenSharing_video"), u.includes("screenSharing_audio")) {
8752
+ if (u.includes("microphoneCamera_audio") && u.includes("microphoneCamera_video") ? await this.initLocalStream("microphoneCamera") : u.includes("microphoneCamera_audio") ? await this.initLocalStream("microphoneCamera_audio") : u.includes("microphoneCamera_video") ? await this.initLocalStream("microphoneCamera_video") : u.includes("screenSharing_audio") && u.includes("screenSharing_video") ? await this.initLocalStream("screenSharing") : u.includes("screenSharing_audio") && !u.includes("screenSharing_video") ? await this.initLocalStream("screenSharing_audio") : u.includes("screenSharing_video") && !u.includes("screenSharing_audio") && await this.initLocalStream("screenSharing_video"), u.includes("screenSharing_audio")) {
8756
8753
  const $ = this.getUserStream(e, "screenSharing_audio").getTracks();
8757
8754
  for (const N of $)
8758
- N.onended = () => this.stopPublish(["screenSharing_audio"]);
8755
+ N.onended = () => this.stopPublish(["screenSharing_audio", "screenSharing_video"]);
8759
8756
  }
8760
8757
  if (u.includes("screenSharing_video")) {
8761
8758
  const $ = this.getUserStream(e, "screenSharing_video").getTracks();
8762
8759
  for (const N of $)
8763
- N.onended = () => this.stopPublish(["screenSharing_video"]);
8760
+ N.onended = () => this.stopPublish(["screenSharing_audio", "screenSharing_video"]);
8764
8761
  }
8765
8762
  }
8766
8763
  const n = this.getUserStreams(e);
@@ -8796,7 +8793,7 @@ class RoomCalls extends RoomPeer {
8796
8793
  Z(this, "changeScreenSharing", async (u) => {
8797
8794
  const E = await this.getCaller(), { tracks: _ = [], callActionMap: k } = E;
8798
8795
  try {
8799
- await this.setLocalStream(u, !0), console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->Breathe: 123");
8796
+ await this.setLocalStream(u, !0);
8800
8797
  for (const e of u)
8801
8798
  _.find((O) => O.mediaType === e && k[e]) && await this.replaceSenderStream([e], !0);
8802
8799
  } catch (e) {
@@ -8895,7 +8892,8 @@ class RoomCalls extends RoomPeer {
8895
8892
  const e = await this.getCaller();
8896
8893
  try {
8897
8894
  await this.setLocalStream(u, !0);
8898
- } catch {
8895
+ } catch (q) {
8896
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: setLocalStream is error.", q);
8899
8897
  }
8900
8898
  const n = [];
8901
8899
  for (const q of u)
@@ -8905,7 +8903,7 @@ class RoomCalls extends RoomPeer {
8905
8903
  const $ = await this.getSenderTracks(O), N = [...e.tracks, ...$];
8906
8904
  await this.updateUsertracks(e.id, N, !0);
8907
8905
  const D = await this.getCallAction(N);
8908
- await J(this, Et).call(this, D), J(this, Xt).call(this, u), await this.replaceSenderStream(O, !0), n.length !== 0 && await this.inactiveTracks(n, !1);
8906
+ await J(this, Et).call(this, D), n.length !== 0 && await this.inactiveTracks(n, !1), O.length !== 0 && await this.replaceSenderStream(O, !0), J(this, Xt).call(this, u);
8909
8907
  {
8910
8908
  await this.emitNotifyUpdateUsers();
8911
8909
  const q = await this.getCaller();
@@ -8935,7 +8933,7 @@ class RoomCalls extends RoomPeer {
8935
8933
  await this.emitNotifyUpdateUsers(), E($);
8936
8934
  };
8937
8935
  if (n.length === 0) return O();
8938
- await this.replaceSenderStream(u, !1), await this.closeUserTracks(e.id, n, !0), await this.removeSenders(u);
8936
+ await this.closeUserTracks(e.id, n, !0), await this.removeSenders(u);
8939
8937
  {
8940
8938
  const $ = await this.getCallAction(e.tracks);
8941
8939
  await J(this, Et).call(this, $);
@@ -9065,6 +9063,7 @@ class RoomCalls extends RoomPeer {
9065
9063
  const k = await this.getCaller();
9066
9064
  if (!k) return;
9067
9065
  const { tracks: e = [] } = k, n = [...e];
9066
+ await this.replaceSenderStream(u, !0);
9068
9067
  for (let $ of n) {
9069
9068
  const { mediaType: N } = $;
9070
9069
  if (N && u.includes(N)) {
@@ -9075,7 +9074,7 @@ class RoomCalls extends RoomPeer {
9075
9074
  }
9076
9075
  }
9077
9076
  const O = await this.getCallAction(n);
9078
- await J(this, Et).call(this, O), await this.emitNotifyUpdateUsers(), _(!0);
9077
+ await J(this, Et).call(this, O), E === !1 && await this.replaceSenderStream(u, !1), await this.emitNotifyUpdateUsers(), _(!0);
9079
9078
  }));
9080
9079
  /**
9081
9080
  * 远端调试