@lvce-editor/renderer-process 30.27.0 → 30.29.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.
- package/dist/rendererProcessMain.js +35 -14
- package/package.json +1 -1
|
@@ -9594,7 +9594,7 @@ const queryAudio = (uid, elementLocator) => {
|
|
|
9594
9594
|
}
|
|
9595
9595
|
return remoteAudio;
|
|
9596
9596
|
};
|
|
9597
|
-
const setupLevelMeter = (audioCtx, stream
|
|
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
|
-
|
|
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
|
-
|
|
9634
|
+
remoteAnalyzerInstance.instance = setupLevelMeter(audioCtx, e.streams[0]);
|
|
9633
9635
|
}
|
|
9634
9636
|
};
|
|
9635
9637
|
const micStream = await navigator.mediaDevices.getUserMedia({
|
|
@@ -9643,16 +9645,27 @@ const startWebRtcAudioStream = async options => {
|
|
|
9643
9645
|
dc.addEventListener('message', e => {
|
|
9644
9646
|
port.postMessage(e.data);
|
|
9645
9647
|
});
|
|
9648
|
+
port.onmessage = event => {
|
|
9649
|
+
const {
|
|
9650
|
+
data
|
|
9651
|
+
} = event;
|
|
9652
|
+
if (dc.readyState !== 'open') {
|
|
9653
|
+
return;
|
|
9654
|
+
}
|
|
9655
|
+
dc.send(data);
|
|
9656
|
+
};
|
|
9646
9657
|
|
|
9647
9658
|
// 3. Standard WebRTC offer/answer handshake against the Realtime API.
|
|
9648
9659
|
const offer = await pc.createOffer();
|
|
9649
9660
|
await pc.setLocalDescription(offer);
|
|
9650
9661
|
pcs[uid] = {
|
|
9662
|
+
audioCtx,
|
|
9651
9663
|
connection: pc,
|
|
9664
|
+
dataChannel: dc,
|
|
9652
9665
|
micAnalyzer,
|
|
9653
9666
|
micStream,
|
|
9654
9667
|
port,
|
|
9655
|
-
remoteAnalyzer
|
|
9668
|
+
remoteAnalyzer: remoteAnalyzerInstance
|
|
9656
9669
|
};
|
|
9657
9670
|
return offer.sdp;
|
|
9658
9671
|
};
|
|
@@ -9674,6 +9687,8 @@ const setRemoteDescription = async options => {
|
|
|
9674
9687
|
type
|
|
9675
9688
|
});
|
|
9676
9689
|
};
|
|
9690
|
+
|
|
9691
|
+
// TODO this has a race conditon when start/stop is pressed fast
|
|
9677
9692
|
const stopWebRtcAudioStream = async options => {
|
|
9678
9693
|
const {
|
|
9679
9694
|
uid
|
|
@@ -9684,16 +9699,30 @@ const stopWebRtcAudioStream = async options => {
|
|
|
9684
9699
|
}
|
|
9685
9700
|
// TODO use disposableMap maybe?
|
|
9686
9701
|
const {
|
|
9702
|
+
audioCtx,
|
|
9687
9703
|
connection,
|
|
9704
|
+
dataChannel,
|
|
9688
9705
|
micStream,
|
|
9689
9706
|
port
|
|
9690
9707
|
} = pc;
|
|
9691
9708
|
delete pcs[uid];
|
|
9692
9709
|
connection.close();
|
|
9710
|
+
dataChannel.close();
|
|
9693
9711
|
for (const t of micStream.getTracks()) {
|
|
9694
9712
|
t.stop();
|
|
9695
9713
|
}
|
|
9696
9714
|
port.close();
|
|
9715
|
+
if (audioCtx) {
|
|
9716
|
+
await audioCtx.close();
|
|
9717
|
+
}
|
|
9718
|
+
};
|
|
9719
|
+
const readMicLevel = analyzer => {
|
|
9720
|
+
let data = new Uint8Array();
|
|
9721
|
+
if (analyzer) {
|
|
9722
|
+
data = new Uint8Array(analyzer.frequencyBinCount);
|
|
9723
|
+
analyzer.getByteTimeDomainData(data);
|
|
9724
|
+
}
|
|
9725
|
+
return data;
|
|
9697
9726
|
};
|
|
9698
9727
|
const readMicLevels = options => {
|
|
9699
9728
|
const {
|
|
@@ -9710,16 +9739,8 @@ const readMicLevels = options => {
|
|
|
9710
9739
|
micAnalyzer,
|
|
9711
9740
|
remoteAnalyzer
|
|
9712
9741
|
} = pc;
|
|
9713
|
-
|
|
9714
|
-
|
|
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
|
-
}
|
|
9742
|
+
const micAnalyzerData = readMicLevel(micAnalyzer);
|
|
9743
|
+
const remoteAnalyzerData = readMicLevel(remoteAnalyzer.instance);
|
|
9723
9744
|
return {
|
|
9724
9745
|
micAnalyzerData,
|
|
9725
9746
|
remoteAnalyzerData
|