quickvo-sdk-js 0.7.0 → 0.7.2

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
@@ -749,6 +749,11 @@ class AudioMediaContext {
749
749
  Z(this, "analyserNode");
750
750
  // 缓冲区 存储分析节点的时域数据
751
751
  Z(this, "analyserArrayData");
752
+ Z(this, "initNode", () => {
753
+ 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);
754
+ const { gainNode: I, analyserNode: a } = this;
755
+ I.connect(a), this.audioContext.state === "suspended" && (this.audioContext.resume(), document.addEventListener("click", () => this.audioContext.resume(), { once: !0 })), this.setFilter();
756
+ });
752
757
  /**
753
758
  * 停止
754
759
  */
@@ -763,11 +768,11 @@ class AudioMediaContext {
763
768
  * 替换媒体
764
769
  */
765
770
  Z(this, "replaceStream", (I) => {
766
- const a = this.stream.getTracks();
767
- for (const _ of a)
768
- this.stream.removeTrack(_);
769
- const [E] = I.getAudioTracks();
770
- E && this.stream.addTrack(E);
771
+ const a = this.stream, E = a.getTracks();
772
+ for (const k of E)
773
+ a.removeTrack(k);
774
+ const [_] = I.getAudioTracks();
775
+ _ && a.addTrack(_), this.initNode();
771
776
  });
772
777
  /**
773
778
  * 获取数据流
@@ -819,9 +824,7 @@ class AudioMediaContext {
819
824
  let N = k;
820
825
  return a && N.connect(e), E && N.connect(n), _ && N.connect(O), N.connect($), I;
821
826
  });
822
- 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);
823
- const { gainNode: a, analyserNode: E } = this;
824
- a.connect(E), this.audioContext.state === "suspended" && (this.audioContext.resume(), document.addEventListener("click", () => this.audioContext.resume(), { once: !0 })), this.setFilter();
827
+ this.stream.addTrack(I), this.initNode();
825
828
  }
826
829
  }
827
830
  class VideoMediaContext {
@@ -840,11 +843,11 @@ class VideoMediaContext {
840
843
  * 替换媒体
841
844
  */
842
845
  Z(this, "replaceStream", (I) => {
843
- const a = this.stream.getTracks();
844
- for (const _ of a)
845
- this.stream.removeTrack(_);
846
- const [E] = I.getVideoTracks();
847
- E && this.stream.addTrack(E);
846
+ const a = this.stream, E = a.getTracks();
847
+ for (const k of E)
848
+ a.removeTrack(k);
849
+ const [_] = I.getVideoTracks();
850
+ _ && a.addTrack(_);
848
851
  });
849
852
  /**
850
853
  * 获取数据流
@@ -7182,7 +7185,7 @@ const noLogEvents = ["heartbeat", "onNetQuality", "networkQualityChange"], compr
7182
7185
  }
7183
7186
  return u;
7184
7187
  };
7185
- var wt, dt, xt, yt, kt, Mt, Pt, Lt, Bt, Nt, jt, Zt, Ft;
7188
+ var wt, dt, xt, yt, bt, Mt, Pt, Lt, Bt, Nt, jt, Zt, Ft;
7186
7189
  class CallsWebSocket {
7187
7190
  // 状态
7188
7191
  constructor(I) {
@@ -7199,7 +7202,7 @@ class CallsWebSocket {
7199
7202
  lt(this, xt, "");
7200
7203
  // 缓存登录凭证
7201
7204
  lt(this, yt, {});
7202
- lt(this, kt, {});
7205
+ lt(this, bt, {});
7203
7206
  Z(this, "state", "closed");
7204
7207
  // 外部 发送消息之前
7205
7208
  Z(this, "sendMessageBefore", async () => {
@@ -7321,7 +7324,7 @@ class CallsWebSocket {
7321
7324
  getHeartbeatMsg: Q(this, Bt),
7322
7325
  onReconnectSuccess: Q(this, Pt),
7323
7326
  onReconnectStop: Q(this, Lt)
7324
- })), this.state = "connecting", await Q(this, wt).connect(), this.state = "connected", Q(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 当前广播事件", Q(this, kt)), a(Q(this, wt));
7327
+ })), this.state = "connecting", await Q(this, wt).connect(), this.state = "connected", Q(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 当前广播事件", Q(this, bt)), a(Q(this, wt));
7325
7328
  }));
7326
7329
  /**
7327
7330
  * 关闭
@@ -7362,7 +7365,7 @@ class CallsWebSocket {
7362
7365
  * @param result 事件响应值
7363
7366
  */
7364
7367
  Z(this, "emitNotify", async (I, a) => {
7365
- const E = Q(this, kt)[I] || [];
7368
+ const E = Q(this, bt)[I] || [];
7366
7369
  for (const _ of E) {
7367
7370
  const { callback: k = async () => {
7368
7371
  } } = _;
@@ -7377,8 +7380,8 @@ class CallsWebSocket {
7377
7380
  */
7378
7381
  Z(this, "addNotify", (I, a = !1) => {
7379
7382
  const { event: E, sn: _ = ht(32) } = I;
7380
- Q(this, kt)[E] || (Q(this, kt)[E] = []);
7381
- const k = Q(this, kt)[E], e = k.findIndex((n) => n.sn === _);
7383
+ Q(this, bt)[E] || (Q(this, bt)[E] = []);
7384
+ const k = Q(this, bt)[E], e = k.findIndex((n) => n.sn === _);
7382
7385
  return e !== -1 && k.splice(e, 1), a ? k.unshift(I) : k.push(I), _;
7383
7386
  });
7384
7387
  /**
@@ -7386,18 +7389,18 @@ class CallsWebSocket {
7386
7389
  */
7387
7390
  Z(this, "removeNotify", (I = []) => {
7388
7391
  if (I.length === 0)
7389
- St(this, kt, {});
7392
+ St(this, bt, {});
7390
7393
  else {
7391
- const a = Object.keys(Q(this, kt));
7394
+ const a = Object.keys(Q(this, bt));
7392
7395
  for (const E of a)
7393
- Q(this, kt)[E] = Q(this, kt)[E].filter((_) => !I.includes(_.sn || ""));
7396
+ Q(this, bt)[E] = Q(this, bt)[E].filter((_) => !I.includes(_.sn || ""));
7394
7397
  }
7395
- Q(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 移除广播事件", Q(this, kt));
7398
+ Q(this, dt).debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: 移除广播事件", Q(this, bt));
7396
7399
  });
7397
7400
  St(this, dt, { ...Q(this, dt), ...I });
7398
7401
  }
7399
7402
  }
7400
- wt = new WeakMap(), dt = new WeakMap(), xt = new WeakMap(), yt = new WeakMap(), kt = new WeakMap(), Mt = new WeakMap(), Pt = new WeakMap(), Lt = new WeakMap(), Bt = new WeakMap(), Nt = new WeakMap(), jt = new WeakMap(), Zt = new WeakMap(), Ft = new WeakMap();
7403
+ wt = new WeakMap(), dt = new WeakMap(), xt = new WeakMap(), yt = new WeakMap(), bt = new WeakMap(), Mt = new WeakMap(), Pt = new WeakMap(), Lt = new WeakMap(), Bt = new WeakMap(), Nt = new WeakMap(), jt = new WeakMap(), Zt = new WeakMap(), Ft = new WeakMap();
7401
7404
  var y = Object.defineProperty, x = (u) => {
7402
7405
  throw TypeError(u);
7403
7406
  }, g = (u, I, a) => I in u ? y(u, I, { enumerable: !0, configurable: !0, writable: !0, value: a }) : u[I] = a, h = (u, I, a) => g(u, typeof I != "symbol" ? I + "" : I, a), b = (u, I, a) => I.has(u) || x("Cannot " + a), o = (u, I, a) => (b(u, I, "read from private field"), a ? a.call(u) : I.get(u)), f = (u, I, a) => I.has(u) ? x("Cannot add the same private member more than once") : I instanceof WeakSet ? I.add(u) : I.set(u, a), p = (u, I, a, E) => (b(u, I, "write to private field"), I.set(u, a), a), d, c, l;
@@ -7634,14 +7637,14 @@ class RoomBase {
7634
7637
  }
7635
7638
  }
7636
7639
  Ht = new WeakMap();
7637
- var It, bt, _t, vt, gt, zt, Jt, Rt, Wt;
7640
+ var It, kt, _t, vt, gt, zt, Jt, Rt, Wt;
7638
7641
  class RoomMedias extends RoomBase {
7639
7642
  // 本地流活动状态管理
7640
7643
  constructor(a) {
7641
7644
  super(a);
7642
7645
  lt(this, It, []);
7643
7646
  // 可用媒体设备列表
7644
- lt(this, bt, /* @__PURE__ */ new Map());
7647
+ lt(this, kt, /* @__PURE__ */ new Map());
7645
7648
  // 媒体流设备管理
7646
7649
  lt(this, _t, /* @__PURE__ */ new Map());
7647
7650
  // 媒体轨道参数管理
@@ -7660,7 +7663,7 @@ class RoomMedias extends RoomBase {
7660
7663
  * 初始化媒体设备类型
7661
7664
  */
7662
7665
  lt(this, Jt, () => {
7663
- Q(this, bt).set("audioinput", "default"), Q(this, bt).set("videoinput", "default"), Q(this, bt).set("audiooutput", "default");
7666
+ Q(this, kt).set("audioinput", "default"), Q(this, kt).set("videoinput", "default"), Q(this, kt).set("audiooutput", "default");
7664
7667
  });
7665
7668
  /**
7666
7669
  * 房间所有用户所有媒体流变化
@@ -7700,7 +7703,7 @@ class RoomMedias extends RoomBase {
7700
7703
  const $ = this.getUserMediaStreamContext(a, E);
7701
7704
  if ($ && $.kind === "audio")
7702
7705
  try {
7703
- const N = Q(this, bt).get("audiooutput");
7706
+ const N = Q(this, kt).get("audiooutput");
7704
7707
  (O = $.audioContext) == null || O.setSinkId(N);
7705
7708
  } catch (N) {
7706
7709
  console.warn("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: setSinkId is error", N);
@@ -7799,21 +7802,21 @@ class RoomMedias extends RoomBase {
7799
7802
  // 麦克风
7800
7803
  case "microphoneCamera_audio":
7801
7804
  {
7802
- const E = Q(this, bt).get("audioinput"), _ = Q(this, _t).get("microphoneCamera_audio"), k = await navigator.mediaDevices.getUserMedia({ audio: { deviceId: E, ..._ }, video: !1 });
7805
+ const E = Q(this, kt).get("audioinput"), _ = Q(this, _t).get("microphoneCamera_audio"), k = await navigator.mediaDevices.getUserMedia({ audio: { deviceId: E, ..._ }, video: !1 });
7803
7806
  this.addLocalStream("microphoneCamera_audio", k);
7804
7807
  }
7805
7808
  break;
7806
7809
  // 摄像头
7807
7810
  case "microphoneCamera_video":
7808
7811
  {
7809
- const E = Q(this, bt).get("videoinput"), _ = Q(this, _t).get("microphoneCamera_video"), k = await navigator.mediaDevices.getUserMedia({ audio: !1, video: { deviceId: E, ..._ } });
7812
+ const E = Q(this, kt).get("videoinput"), _ = Q(this, _t).get("microphoneCamera_video"), k = await navigator.mediaDevices.getUserMedia({ audio: !1, video: { deviceId: E, ..._ } });
7810
7813
  this.addLocalStream("microphoneCamera_video", k);
7811
7814
  }
7812
7815
  break;
7813
7816
  // 麦克风 + 摄像头
7814
7817
  case "microphoneCamera":
7815
7818
  {
7816
- const E = Q(this, bt).get("audioinput"), _ = Q(this, bt).get("videoinput"), k = Q(this, _t).get("microphoneCamera_audio"), e = Q(this, _t).get("microphoneCamera_video"), O = (await navigator.mediaDevices.getUserMedia({ audio: { deviceId: E, ...k }, video: { deviceId: _, ...e } })).getTracks();
7819
+ const E = Q(this, kt).get("audioinput"), _ = Q(this, kt).get("videoinput"), k = Q(this, _t).get("microphoneCamera_audio"), e = Q(this, _t).get("microphoneCamera_video"), O = (await navigator.mediaDevices.getUserMedia({ audio: { deviceId: E, ...k }, video: { deviceId: _, ...e } })).getTracks();
7817
7820
  for (const $ of O) {
7818
7821
  const { kind: N } = $;
7819
7822
  if (N === "audio") {
@@ -7907,18 +7910,18 @@ class RoomMedias extends RoomBase {
7907
7910
  * @param mediaDeviceKind 设备类型 "audioinput" | "audiooutput" | "videoinput"
7908
7911
  * @returns deviceId 设备ID
7909
7912
  */
7910
- Z(this, "getMediaDeviceKind", (a) => Q(this, bt).get(a));
7913
+ Z(this, "getMediaDeviceKind", (a) => Q(this, kt).get(a));
7911
7914
  /**
7912
7915
  * 更改音频输出
7913
7916
  */
7914
7917
  Z(this, "changeAudiooutput", () => {
7915
- const a = Q(this, vt).values();
7916
- for (const E of a)
7917
- if (E.kind === "audio" && "setSinkId" in HTMLMediaElement.prototype)
7918
+ const a = Q(this, kt).get("audiooutput"), E = Q(this, vt).values();
7919
+ for (const _ of E)
7920
+ if (_.kind === "audio" && "setSinkId" in HTMLMediaElement.prototype)
7918
7921
  try {
7919
- E.audioContext.setSinkId(deviceId);
7920
- } catch (_) {
7921
- console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: setSinkId is error.", _);
7922
+ _.audioContext.setSinkId(a);
7923
+ } catch (k) {
7924
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->quickvo: setSinkId is error.", k);
7922
7925
  }
7923
7926
  });
7924
7927
  /**
@@ -7927,7 +7930,7 @@ class RoomMedias extends RoomBase {
7927
7930
  * @param deviceId 设备ID
7928
7931
  */
7929
7932
  Z(this, "setDeviceKind", (a, E) => {
7930
- Q(this, bt).set(a, E);
7933
+ Q(this, kt).set(a, E);
7931
7934
  });
7932
7935
  /**
7933
7936
  * 设置音频输出设备
@@ -7959,7 +7962,7 @@ class RoomMedias extends RoomBase {
7959
7962
  Q(this, Wt).call(this), Q(this, Jt).call(this), Q(this, zt).call(this);
7960
7963
  }
7961
7964
  }
7962
- It = new WeakMap(), bt = new WeakMap(), _t = new WeakMap(), vt = new WeakMap(), gt = new WeakMap(), zt = new WeakMap(), Jt = new WeakMap(), Rt = new WeakMap(), Wt = new WeakMap();
7965
+ It = new WeakMap(), kt = new WeakMap(), _t = new WeakMap(), vt = new WeakMap(), gt = new WeakMap(), zt = new WeakMap(), Jt = new WeakMap(), Rt = new WeakMap(), Wt = new WeakMap();
7963
7966
  class RoomUsers extends RoomMedias {
7964
7967
  constructor(a) {
7965
7968
  super(a);
@@ -8319,15 +8322,16 @@ class RoomPeer extends RoomUsers {
8319
8322
  * 替换发射器媒体流
8320
8323
  */
8321
8324
  Z(this, "replaceSenderStream", async (a = [], E) => {
8325
+ const { userId: _ } = this.options;
8322
8326
  a.length === 0 && (a = mediaType_keys);
8323
- for (const _ of a) {
8324
- const k = this.transceiverMap.get(_);
8325
- let e;
8326
- if (k) {
8327
- const { sender: n } = k;
8328
- E ? e = this.getLocalStream(_) : e = this.getPhoneyStreams(_);
8329
- const [O] = (e == null ? void 0 : e.getTracks()) || [];
8330
- O && await n.replaceTrack(O);
8327
+ for (const k of a) {
8328
+ const e = this.transceiverMap.get(k);
8329
+ let n;
8330
+ if (e) {
8331
+ const { sender: O } = e;
8332
+ E ? n = this.getUserStream(_, k) : n = this.getPhoneyStreams(k);
8333
+ const [$] = n.getTracks();
8334
+ $ && await O.replaceTrack($);
8331
8335
  }
8332
8336
  }
8333
8337
  });