@lvce-editor/renderer-process 30.27.0 → 30.28.0

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.
@@ -9594,7 +9594,7 @@ const queryAudio = (uid, elementLocator) => {
9594
9594
  }
9595
9595
  return remoteAudio;
9596
9596
  };
9597
- const setupLevelMeter = (audioCtx, stream, kind) => {
9597
+ const setupLevelMeter = (audioCtx, stream) => {
9598
9598
  const source = audioCtx.createMediaStreamSource(stream);
9599
9599
  const analyser = audioCtx.createAnalyser();
9600
9600
  // TODO make variables confirguable
@@ -9620,7 +9620,9 @@ const startWebRtcAudioStream = async options => {
9620
9620
  }
9621
9621
  let audioCtx;
9622
9622
  let micAnalyzer;
9623
- let remoteAnalyzer;
9623
+ const remoteAnalyzerInstance = {
9624
+ instance: undefined
9625
+ };
9624
9626
  if (trackAudioData) {
9625
9627
  // @ts-ignore
9626
9628
  audioCtx = new (window.AudioContext || window.webkitAudioContext)();
@@ -9629,7 +9631,7 @@ const startWebRtcAudioStream = async options => {
9629
9631
  pc.ontrack = e => {
9630
9632
  remoteAudio.srcObject = e.streams[0];
9631
9633
  if (trackAudioData && audioCtx) {
9632
- remoteAnalyzer = setupLevelMeter(audioCtx, e.streams[0]);
9634
+ remoteAnalyzerInstance.instance = setupLevelMeter(audioCtx, e.streams[0]);
9633
9635
  }
9634
9636
  };
9635
9637
  const micStream = await navigator.mediaDevices.getUserMedia({
@@ -9648,11 +9650,12 @@ const startWebRtcAudioStream = async options => {
9648
9650
  const offer = await pc.createOffer();
9649
9651
  await pc.setLocalDescription(offer);
9650
9652
  pcs[uid] = {
9653
+ audioCtx,
9651
9654
  connection: pc,
9652
9655
  micAnalyzer,
9653
9656
  micStream,
9654
9657
  port,
9655
- remoteAnalyzer
9658
+ remoteAnalyzer: remoteAnalyzerInstance
9656
9659
  };
9657
9660
  return offer.sdp;
9658
9661
  };
@@ -9674,6 +9677,8 @@ const setRemoteDescription = async options => {
9674
9677
  type
9675
9678
  });
9676
9679
  };
9680
+
9681
+ // TODO this has a race conditon when start/stop is pressed fast
9677
9682
  const stopWebRtcAudioStream = async options => {
9678
9683
  const {
9679
9684
  uid
@@ -9684,6 +9689,7 @@ const stopWebRtcAudioStream = async options => {
9684
9689
  }
9685
9690
  // TODO use disposableMap maybe?
9686
9691
  const {
9692
+ audioCtx,
9687
9693
  connection,
9688
9694
  micStream,
9689
9695
  port
@@ -9694,6 +9700,17 @@ const stopWebRtcAudioStream = async options => {
9694
9700
  t.stop();
9695
9701
  }
9696
9702
  port.close();
9703
+ if (audioCtx) {
9704
+ await audioCtx.close();
9705
+ }
9706
+ };
9707
+ const readMicLevel = analyzer => {
9708
+ let data = new Uint8Array();
9709
+ if (analyzer) {
9710
+ data = new Uint8Array(analyzer.frequencyBinCount);
9711
+ analyzer.getByteTimeDomainData(data);
9712
+ }
9713
+ return data;
9697
9714
  };
9698
9715
  const readMicLevels = options => {
9699
9716
  const {
@@ -9710,16 +9727,8 @@ const readMicLevels = options => {
9710
9727
  micAnalyzer,
9711
9728
  remoteAnalyzer
9712
9729
  } = pc;
9713
- let micAnalyzerData = new Uint8Array();
9714
- if (micAnalyzer) {
9715
- micAnalyzerData = new Uint8Array(micAnalyzer.frequencyBinCount);
9716
- micAnalyzer.getByteTimeDomainData(micAnalyzerData);
9717
- }
9718
- let remoteAnalyzerData = new Uint8Array();
9719
- if (remoteAnalyzer) {
9720
- remoteAnalyzerData = new Uint8Array(remoteAnalyzer.frequencyBinCount);
9721
- remoteAnalyzer.getByteTimeDomainData(remoteAnalyzerData);
9722
- }
9730
+ const micAnalyzerData = readMicLevel(micAnalyzer);
9731
+ const remoteAnalyzerData = readMicLevel(remoteAnalyzer.instance);
9723
9732
  return {
9724
9733
  micAnalyzerData,
9725
9734
  remoteAnalyzerData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.27.0",
3
+ "version": "30.28.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"