-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: OBS toggle audio source (#183)
- Loading branch information
Showing
13 changed files
with
186 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
front-src/client/components/Widgets/OBS/ToggleAudio/Settings.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script> | ||
import { _ } from "@/libs/i18next"; | ||
import { state } from "@/stores/obs"; | ||
import { update } from "@/libs/panels"; | ||
import Select from "@/components/UI/Select.svelte"; | ||
export let data; | ||
let sources = []; | ||
let { panel, widget } = data; | ||
let none = _("words.none"); | ||
$: if ($state.sources) { | ||
sources = $state.sources.filter((source) => source.caps.hasAudio); | ||
sources = [none, ...sources.map((source) => source.name)]; | ||
} | ||
$: props = widget.component.props; | ||
function onChange(key, { detail }) { | ||
props[key] = detail === none ? null : detail; | ||
update(panel); | ||
} | ||
</script> | ||
|
||
<div class="p-2 pt-0 space-y-2 flex flex-auto flex-col"> | ||
<Select | ||
items="{sources}" | ||
value="{props.source}" | ||
label="{_('words.source')}" | ||
on:change="{onChange.bind(null, 'source')}" | ||
/> | ||
</div> |
56 changes: 56 additions & 0 deletions
56
front-src/client/components/Widgets/OBS/ToggleAudio/Widget.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script> | ||
import obs from "@/api/obs"; | ||
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; | ||
$: source = widget.component.props.source; | ||
$: icon = state && !state.muted ? MdVolumeUp : MdVolumeOff; | ||
$: if (source) { | ||
obs.emit("GetVolume", { source }).then((result) => (state = result)); | ||
} | ||
function onClick() { | ||
actions.push({ type: "obs", widget }).catch((error) => { | ||
console.log(">>>Error:", error); | ||
}); | ||
} | ||
onMount(async () => { | ||
obs.on(`source.volume`, ({ sourceName, volume }) => { | ||
if (sourceName === source) { | ||
state.volume = volume; | ||
} | ||
}); | ||
obs.on(`source.muted`, ({ sourceName, muted }) => { | ||
if (sourceName === source) { | ||
state.muted = muted; | ||
} | ||
}); | ||
}); | ||
</script> | ||
|
||
<WidgetWrapper widget="{widget}" on:click="{onClick}"> | ||
<div class="flex flex-col h-full text-center"> | ||
{#if source && state} | ||
<div | ||
class="flex flex-col w-full h-full {state.muted ? 'text-red-600' : ''}" | ||
> | ||
<div class="p-2 break-words">{source}</div> | ||
<svelte:component this="{icon}" /> | ||
</div> | ||
{:else} | ||
<div class="p-2 bg-red-600">{_('obs.no-source-selected')}</div> | ||
{/if} | ||
</div> | ||
</WidgetWrapper> |
9 changes: 9 additions & 0 deletions
9
front-src/client/components/Widgets/OBS/ToggleAudio/config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
name: "ToggleAudio", | ||
label: "obs.toggle-audio", | ||
hasTrigger: true, | ||
hasEvent: true, | ||
props: { | ||
source: null, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as Settings } from "./Settings.svelte"; | ||
export { default as Widget } from "./Widget.svelte"; | ||
export { default as config } from "./config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters