Skip to content

Commit

Permalink
Added button to control the OBS Virtual Webcam (#110)
Browse files Browse the repository at this point in the history
* Added button to control the OBS Virtual Webcam

* Convert to Virtual Camera to Events

- Remove virutalcam from heartbeat
- Sync isVirtualCamActive during initial connection
- Use VirtualcamStateChanged events to update isVirtualCamActive

* npm run lint fixes

Co-authored-by: Tim Donahue <tdonahue@nytechco.com>
  • Loading branch information
donahuetech and nytechco-tim authored Sep 20, 2022
1 parent c755a31 commit ecdcdb7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mdiBorderVertical, mdiArrowSplitHorizontal,
mdiAccessPoint, mdiAccessPointOff,
mdiRecord, mdiStop, mdiPause, mdiPlayPause,
mdiConnection,
mdiConnection, mdiCameraOff, mdiCamera,
mdiMotionPlayOutline, mdiMotionPlay
} from '@mdi/js'
import Icon from 'mdi-svelte'
Expand Down Expand Up @@ -80,6 +80,7 @@
let isFullScreen
let isStudioMode
let isSceneOnTop
let isVirtualCamActive
let isIconMode = window.localStorage.getItem('isIconMode') || false
let isReplaying
let editable = false
Expand Down Expand Up @@ -158,6 +159,14 @@
await sendCommand('StopRecord')
}
async function startVirtualCam () {
await sendCommand('StartVirtualCam')
}
async function stopVirtualCam () {
await sendCommand('StopVirtualCam')
}
async function pauseRecording () {
await sendCommand('PauseRecord')
}
Expand Down Expand Up @@ -218,6 +227,7 @@
// console.log(heartbeat);
}, 1000) // Heartbeat
isStudioMode = (await sendCommand('GetStudioModeEnabled')).studioModeEnabled || false
isVirtualCamActive = (await sendCommand('GetVirtualCamStatus')).outputActive || false
})
obs.on('ConnectionError', async () => {
Expand All @@ -230,6 +240,11 @@
}
})
obs.on('VirtualcamStateChanged', async (data) => {
console.log('VirtualcamStateChanged', data.outputActive)
isVirtualCamActive = data && data.outputActive
})
obs.on('StudioModeStateChanged', async (data) => {
console.log('StudioModeStateChanged', data.studioModeEnabled)
isStudioMode = data && data.studioModeEnabled
Expand Down Expand Up @@ -298,6 +313,15 @@
<span class="icon"><Icon path={mdiRecord} /></span>
</button>
{/if}
{#if isVirtualCamActive}
<button class="button is-danger" on:click={stopVirtualCam} title="Stop Virtual Webcam">
<span class='icon'><Icon path={mdiCameraOff} /></span>
</button>
{:else}
<button class="button is-danger is-light" on:click={startVirtualCam} title="Start Virtual Webcam">
<span class='icon'><Icon path={mdiCamera} /></span>
</button>
{/if}
<button class:is-light={!isStudioMode} class="button is-link" on:click={toggleStudioMode} title="Toggle Studio Mode">
<span class="icon"><Icon path={mdiBorderVertical} /></span>
</button>
Expand Down

0 comments on commit ecdcdb7

Please sign in to comment.