diff --git a/app/server/libs/actions/types/obs.js b/app/server/libs/actions/types/obs.js index fc9e165e..d5c3b0eb 100644 --- a/app/server/libs/actions/types/obs.js +++ b/app/server/libs/actions/types/obs.js @@ -8,14 +8,20 @@ function create(action) { const actions = { ToggleAudio(action) { const { source } = action.widget.component.props; - return obs.send("ToggleMute", { source }); }, + AudioVolume(action) { + const { source } = action.widget.component.props; + const { volume, mute } = action.data || action.eventProps || "undefined"; + if (mute !== undefined) { + return obs.send("SetMute", { source, mute }); + } + return obs.send("SetVolume", { source, volume, useDecibel: false }); + }, ToggleScene(action) { const { currentScene } = obs.getState(); const { scene1, scene2 } = action.widget.component.props; const scene = currentScene === scene1 ? scene2 : scene1; - return obs.send("SetCurrentScene", { "scene-name": scene }); }, GoToScene(action) { diff --git a/app/server/libs/obs.js b/app/server/libs/obs.js index 714a279c..0731bfb1 100644 --- a/app/server/libs/obs.js +++ b/app/server/libs/obs.js @@ -25,6 +25,7 @@ let state = { recording: false, status: null, scenes: null, + sources: null, currentScene: null, }; diff --git a/app/server/libs/twitch/pushActions.js b/app/server/libs/twitch/pushActions.js index 74efa353..ecfe87a7 100644 --- a/app/server/libs/twitch/pushActions.js +++ b/app/server/libs/twitch/pushActions.js @@ -10,6 +10,7 @@ const types = { GoToScene: "obs", ToggleScene: "obs", ToggleAudio: "obs", + AudioVolume: "obs", AnimeTimeline: "anime", }; diff --git a/app/static/locales/en/app.json b/app/static/locales/en/app.json index 17b0de38..b9dd35fb 100644 --- a/app/static/locales/en/app.json +++ b/app/static/locales/en/app.json @@ -168,6 +168,7 @@ "go-to-scene": "OBS | Go to scene", "toggle-scene": "OBS | Toggle between two scenes", "toggle-audio": "OBS | Toggle audio source", + "audio-volume": "OBS | Audio volume", "no-scene-selected": "No scene selected", "connect-at-startup": "Connect OBS at startup", "first-start-install-sentence": "If you want to use OBS with Marv you need to install OBS WebSocket.", diff --git a/app/static/locales/es/app.json b/app/static/locales/es/app.json index b046a524..ae527393 100644 --- a/app/static/locales/es/app.json +++ b/app/static/locales/es/app.json @@ -167,6 +167,7 @@ "go-to-scene": "OBS | Ir a la escena", "toggle-scene": "OBS | Cambiar entre dos escenas", "toggle-audio": "OBS | Alternar fuente de audio", + "audio-volume": "OBS | Volumen de audio", "no-scene-selected": "Ninguna escena seleccionada", "connect-at-startup": "Conectar a OBS al inicio", "first-start-install-sentence": "Para conectar Marv a OBS, debes instalar OBS WebSocket.", diff --git a/app/static/locales/fr/app.json b/app/static/locales/fr/app.json index ca30764d..9fecfb08 100644 --- a/app/static/locales/fr/app.json +++ b/app/static/locales/fr/app.json @@ -168,6 +168,7 @@ "go-to-scene": "OBS | Aller à la scène", "toggle-scene": "OBS | Basculer entre deux scènes", "toggle-audio": "OBS | Basculer source audio", + "audio-volume": "OBS | Volume audio", "no-scene-selected": "Aucune scène sélectionnée", "connect-at-startup": "Connecter OBS au démarrage", "first-start-install-sentence": "Pour connecter Marv à OBS, tu dois installer OBS WebSocket.", diff --git a/front-src/client/components/Widgets/OBS/AudioVolume/Settings.svelte b/front-src/client/components/Widgets/OBS/AudioVolume/Settings.svelte new file mode 100644 index 00000000..f7f18aac --- /dev/null +++ b/front-src/client/components/Widgets/OBS/AudioVolume/Settings.svelte @@ -0,0 +1,32 @@ + + +
+ +
+ +
+
+ + {:else} +
{_('obs.no-source-selected')}
+ {/if} + + diff --git a/front-src/client/components/Widgets/OBS/AudioVolume/config.js b/front-src/client/components/Widgets/OBS/AudioVolume/config.js new file mode 100644 index 00000000..c975cd5d --- /dev/null +++ b/front-src/client/components/Widgets/OBS/AudioVolume/config.js @@ -0,0 +1,13 @@ +export default { + name: "AudioVolume", + label: "obs.audio-volume", + hasTrigger: true, + hasEvent: true, + minSize: { + w: 4, + h: 3, + }, + props: { + source: null, + }, +}; diff --git a/front-src/client/components/Widgets/OBS/AudioVolume/index.js b/front-src/client/components/Widgets/OBS/AudioVolume/index.js new file mode 100644 index 00000000..72c78896 --- /dev/null +++ b/front-src/client/components/Widgets/OBS/AudioVolume/index.js @@ -0,0 +1,3 @@ +export { default as Settings } from "./Settings.svelte"; +export { default as Widget } from "./Widget.svelte"; +export { default as config } from "./config"; diff --git a/front-src/client/components/Widgets/OBS/ToggleAudio/Widget.svelte b/front-src/client/components/Widgets/OBS/ToggleAudio/Widget.svelte index 5b644785..c050492e 100644 --- a/front-src/client/components/Widgets/OBS/ToggleAudio/Widget.svelte +++ b/front-src/client/components/Widgets/OBS/ToggleAudio/Widget.svelte @@ -3,19 +3,20 @@ import { onMount } from "svelte"; import { _ } from "@/libs/i18next"; import actions from "@/api/actions"; - import Icon from "@/components/UI/Icon.svelte"; import MdVolumeUp from "svelte-icons/md/MdVolumeUp.svelte"; import MdVolumeOff from "svelte-icons/md/MdVolumeOff.svelte"; import WidgetWrapper from "@/components/Widgets/OBS/WidgetWrapper.svelte"; export let widget; - let state = null; + let state = { volume: 0.5, muted: false }; $: source = widget.component.props.source; - $: icon = state && !state.muted ? MdVolumeUp : MdVolumeOff; + $: icon = !state.muted ? MdVolumeUp : MdVolumeOff; - $: if (source) { + $: if (source) getVolume(); + + function getVolume() { obs.emit("GetVolume", { source }).then((result) => (state = result)); } @@ -26,6 +27,10 @@ } onMount(async () => { + obs.on(`connected`, () => { + getVolume(); + }); + obs.on(`source.volume`, ({ sourceName, volume }) => { if (sourceName === source) { state.volume = volume; @@ -42,7 +47,7 @@
- {#if source && state} + {#if source}
diff --git a/front-src/client/components/Widgets/index.js b/front-src/client/components/Widgets/index.js index cbce7965..15c35f64 100644 --- a/front-src/client/components/Widgets/index.js +++ b/front-src/client/components/Widgets/index.js @@ -5,6 +5,7 @@ import * as SceneList from "./OBS/SceneList"; import * as GoToScene from "./OBS/GoToScene"; import * as ToggleScene from "./OBS/ToggleScene"; import * as ToggleAudio from "./OBS/ToggleAudio"; +import * as AudioVolume from "./OBS/AudioVolume"; import * as TwitchChat from "./Twitch/Chat"; import * as TwitchStream from "./Twitch/Stream"; @@ -18,6 +19,7 @@ const widgets = { GoToScene, ToggleScene, ToggleAudio, + AudioVolume, TwitchChat, TwitchStream, TwitchRewards,