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"; import { getCurrentMedia, settings } from "./utils";
let hasStreamed; let hasStreamed, isStreaming, streamKey;
const startStream = findByCodeLazy('type:"STREAM_START"'); const startStream = findByCodeLazy('type:"STREAM_START"');
const stopStream = findByCodeLazy('type:"STREAM_STOP"');
const StreamPreviewSettings = getUserSettingLazy("voiceAndVideo", "disableStreamPreviews")!; const StreamPreviewSettings = getUserSettingLazy("voiceAndVideo", "disableStreamPreviews")!;
const ApplicationStreamingSettingsStore = findStoreLazy("ApplicationStreamingSettingsStore"); const ApplicationStreamingSettingsStore = findStoreLazy("ApplicationStreamingSettingsStore");
@ -44,14 +45,18 @@ async function autoStartStream(instant = true) {
let sourceId = streamMedia.id; let sourceId = streamMedia.id;
if (streamMedia.type === "video_device") sourceId = `camera:${streamMedia.id}`; if (streamMedia.type === "video_device") sourceId = `camera:${streamMedia.id}`;
startStream(channel.guild_id ?? null, selected, { if (isStreaming && streamKey.endsWith(UserStore.getCurrentUser().id)) {
"pid": null, stopStream(streamKey);
"sourceId": sourceId, } else {
"sourceName": streamMedia.name, startStream(channel.guild_id ?? null, selected, {
"audioSourceId": streamMedia.name, "pid": null,
"sound": soundshareEnabled, "sourceId": sourceId,
"previewDisabled": preview "sourceName": streamMedia.name,
}); "audioSourceId": streamMedia.name,
"sound": soundshareEnabled,
"previewDisabled": preview
});
}
} }
export default definePlugin({ export default definePlugin({
@ -122,6 +127,14 @@ export default definePlugin({
break; 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 definePlugin, { OptionType } from "@utils/types";
import { findCssClassesLazy } from "@webpack"; import { findCssClassesLazy } from "@webpack";
import { ComponentDispatch, FocusLock, Menu, useEffect, useRef } from "@webpack/common"; 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"; import fullHeightStyle from "./fullHeightContext.css?managed";
@ -154,8 +154,8 @@ export default definePlugin({
predicate: () => settings.store.organizeMenu, predicate: () => settings.store.organizeMenu,
replacement: [ replacement: [
{ {
match: /(\i)=(.{0,20}openUserSettings\)\(\i\)\));/, match: /children:\[(\i),(?<=\1=.{0,30}\.openUserSettings.+?)/,
replace: "$1=$self.transformSettingsElements($2);", replace: "children:[$self.transformSettingsEntries($1),",
}, },
] ]
}, },
@ -179,8 +179,8 @@ export default definePlugin({
return <Layer {...props} />; return <Layer {...props} />;
}, },
transformSettingsElements(list) { transformSettingsEntries(list) {
const items: any[] = []; const items: ReactNode[] = [];
for (const item of list) { for (const item of list) {
const { key, props } = item; const { key, props } = item;
@ -199,7 +199,7 @@ export default definePlugin({
} else if (key.endsWith("_section") && props.label) { } else if (key.endsWith("_section") && props.label) {
items.push( items.push(
<Menu.MenuItem key={key} label={props.label} id={props.label}> <Menu.MenuItem key={key} label={props.label} id={props.label}>
{this.transformSettingsElements(props.children)} {this.transformSettingsEntries(props.children)}
</Menu.MenuItem> </Menu.MenuItem>
); );
} else { } else {