mirror of
https://github.com/SrIzan10/helium.git
synced 2026-06-06 00:56:58 +00:00
perf(native): reduce Android screen-share latency
This commit is contained in:
@@ -32,6 +32,25 @@ interface UseHeliumStreamerResult {
|
||||
stopSharing: () => void;
|
||||
}
|
||||
|
||||
async function applyLowLatencyEncoding(
|
||||
sender: ReturnType<RTCPeerConnection["addTrack"]>,
|
||||
): Promise<void> {
|
||||
const parameters = sender.getParameters();
|
||||
|
||||
if (!parameters.encodings || parameters.encodings.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
parameters.degradationPreference = "maintain-framerate";
|
||||
|
||||
const [firstEncoding] = parameters.encodings;
|
||||
firstEncoding.maxBitrate = 1_200_000;
|
||||
firstEncoding.maxFramerate = 24;
|
||||
firstEncoding.scaleResolutionDownBy = 2;
|
||||
|
||||
await sender.setParameters(parameters);
|
||||
}
|
||||
|
||||
function serializeIceCandidate(candidate: RTCIceCandidate): NativeIceCandidateInit {
|
||||
const raw = candidate as unknown as {
|
||||
candidate?: string;
|
||||
@@ -125,7 +144,11 @@ export function useHeliumStreamer(
|
||||
setViewerCount(Object.keys(peersRef.current).length);
|
||||
|
||||
localStream.getTracks().forEach((track) => {
|
||||
peer.addTrack(track, localStream);
|
||||
const sender = peer.addTrack(track, localStream);
|
||||
|
||||
if (track.kind === "video") {
|
||||
void applyLowLatencyEncoding(sender);
|
||||
}
|
||||
});
|
||||
|
||||
peerWithHandlers.onicecandidate = (event): void => {
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
Text,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { RTCView } from "react-native-webrtc";
|
||||
|
||||
import { useHeliumStreamer } from "../hooks/useHeliumStreamer";
|
||||
import { useAppTheme } from "../lib/theme";
|
||||
@@ -30,7 +29,6 @@ export function StreamerScreen() {
|
||||
status,
|
||||
roomCode,
|
||||
viewerCount,
|
||||
streamUrl,
|
||||
isSharing,
|
||||
startSharing,
|
||||
stopSharing,
|
||||
@@ -150,16 +148,12 @@ export function StreamerScreen() {
|
||||
</View>
|
||||
|
||||
<View style={styles.preview}>
|
||||
{isSharing && streamUrl ? (
|
||||
<RTCView
|
||||
mirror={false}
|
||||
objectFit="cover"
|
||||
streamURL={streamUrl}
|
||||
style={styles.video}
|
||||
zOrder={0}
|
||||
/>
|
||||
{isSharing ? (
|
||||
<Text style={styles.previewPlaceholder}>
|
||||
Screen capture active. Preview disabled to reduce latency.
|
||||
</Text>
|
||||
) : (
|
||||
<Text style={styles.previewPlaceholder}>Screen preview appears after sharing starts</Text>
|
||||
<Text style={styles.previewPlaceholder}>Start sharing to broadcast this phone screen</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
@@ -278,10 +272,6 @@ function createStyles(theme: ReturnType<typeof useAppTheme>) {
|
||||
justifyContent: "center",
|
||||
overflow: "hidden",
|
||||
},
|
||||
video: {
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
},
|
||||
previewPlaceholder: {
|
||||
color: theme.mutedForeground,
|
||||
paddingHorizontal: 16,
|
||||
|
||||
Reference in New Issue
Block a user