InstantScreenShare: Stop Stream If Already Streaming

This commit is contained in:
thororen1234 2026-03-06 14:38:08 -05:00
parent b7d7a6fda9
commit 7948d56c00
No known key found for this signature in database
2 changed files with 28 additions and 15 deletions

View file

@ -15,8 +15,9 @@ import { ChannelStore, MediaEngineStore, PermissionsBits, PermissionStore, Selec
import { getCurrentMedia, settings } from "./utils";
let hasStreamed;
let hasStreamed, isStreaming, streamKey;
const startStream = findByCodeLazy('type:"STREAM_START"');
const stopStream = findByCodeLazy('type:"STREAM_STOP"');
const StreamPreviewSettings = getUserSettingLazy("voiceAndVideo", "disableStreamPreviews")!;
const ApplicationStreamingSettingsStore = findStoreLazy("ApplicationStreamingSettingsStore");
@ -44,14 +45,18 @@ async function autoStartStream(instant = true) {
let sourceId = streamMedia.id;
if (streamMedia.type === "video_device") sourceId = `camera:${streamMedia.id}`;
startStream(channel.guild_id ?? null, selected, {
"pid": null,
"sourceId": sourceId,
"sourceName": streamMedia.name,
"audioSourceId": streamMedia.name,
"sound": soundshareEnabled,
"previewDisabled": preview
});
if (isStreaming && streamKey.endsWith(UserStore.getCurrentUser().id)) {
stopStream(streamKey);
} else {
startStream(channel.guild_id ?? null, selected, {
"pid": null,
"sourceId": sourceId,
"sourceName": streamMedia.name,
"audioSourceId": streamMedia.name,
"sound": soundshareEnabled,
"previewDisabled": preview
});
}
}
export default definePlugin({
@ -122,6 +127,14 @@ export default definePlugin({
break;
}
},
STREAM_CREATE: d => {
streamKey = d;
isStreaming = true;
},
STREAM_DELETE: d => {
streamKey = d;
isStreaming = false;
}
},

View file

@ -13,7 +13,7 @@ import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types";
import { findCssClassesLazy } from "@webpack";
import { ComponentDispatch, FocusLock, Menu, useEffect, useRef } from "@webpack/common";
import type { HTMLAttributes } from "react";
import type { HTMLAttributes, ReactNode } from "react";
import fullHeightStyle from "./fullHeightContext.css?managed";
@ -154,8 +154,8 @@ export default definePlugin({
predicate: () => settings.store.organizeMenu,
replacement: [
{
match: /(\i)=(.{0,20}openUserSettings\)\(\i\)\));/,
replace: "$1=$self.transformSettingsElements($2);",
match: /children:\[(\i),(?<=\1=.{0,30}\.openUserSettings.+?)/,
replace: "children:[$self.transformSettingsEntries($1),",
},
]
},
@ -179,8 +179,8 @@ export default definePlugin({
return <Layer {...props} />;
},
transformSettingsElements(list) {
const items: any[] = [];
transformSettingsEntries(list) {
const items: ReactNode[] = [];
for (const item of list) {
const { key, props } = item;
@ -199,7 +199,7 @@ export default definePlugin({
} else if (key.endsWith("_section") && props.label) {
items.push(
<Menu.MenuItem key={key} label={props.label} id={props.label}>
{this.transformSettingsElements(props.children)}
{this.transformSettingsEntries(props.children)}
</Menu.MenuItem>
);
} else {