Skip to content

Commit

Permalink
Feat: OBS Connected and OBS Disconnected Events (#2618)
Browse files Browse the repository at this point in the history
* Implemented `OBS Connected` and `OBS Disconnected` Events

* Removed line for consistency

---------

Co-authored-by: Erik Bigler <erikbigler@gmail.com>
  • Loading branch information
Oceanity and ebiggz authored Jul 18, 2024
1 parent ea04f5e commit 2a63807
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/backend/integrations/builtin/obs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export const OBS_INPUT_AUDIO_BALANCE_CHANGED_EVENT_ID = "input-audio-balance-cha
export const OBS_INPUT_AUDIO_SYNC_OFFSET_CHANGED_EVENT_ID = "input-audio-sync-offset-changed";
export const OBS_INPUT_AUDIO_TRACKS_CHANGED_EVENT_ID = "input-audio-tracks-changed";
export const OBS_INPUT_AUDIO_MONITOR_TYPE_CHANGED_EVENT_ID = "input-audio-monitor-type-changed";
export const OBS_CONNECTED_EVENT_ID = "connected";
export const OBS_DISCONNECTED_EVENT_ID = "disconnected";
14 changes: 14 additions & 0 deletions src/backend/integrations/builtin/obs/events/obs-event-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
OBS_CURRENT_SCENE_TRANSITION_CHANGED_EVENT_ID,
OBS_CURRENT_SCENE_TRANSITION_DURATION_CHANGED_EVENT_ID,
OBS_EVENT_SOURCE_ID,
OBS_CONNECTED_EVENT_ID,
OBS_DISCONNECTED_EVENT_ID,
OBS_RECORDING_STARTED_EVENT_ID,
OBS_RECORDING_STOPPED_EVENT_ID,
OBS_REPLAY_BUFFER_SAVED_EVENT_ID,
Expand Down Expand Up @@ -34,6 +36,18 @@ export const OBSEventSource: EventSource = {
id: OBS_EVENT_SOURCE_ID,
name: "OBS",
events: [
{
id: OBS_CONNECTED_EVENT_ID,
name: "OBS Connected",
description: "When OBS websocket is connected",
manualMetadata: {}
},
{
id: OBS_DISCONNECTED_EVENT_ID,
name: "OBS Disconnected",
description: "When OBS websocket is disconnected",
manualMetadata: {}
},
{
id: OBS_SCENE_CHANGED_EVENT_ID,
name: "OBS Scene Changed",
Expand Down
8 changes: 7 additions & 1 deletion src/backend/integrations/builtin/obs/obs-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
OBS_INPUT_AUDIO_BALANCE_CHANGED_EVENT_ID,
OBS_INPUT_AUDIO_SYNC_OFFSET_CHANGED_EVENT_ID,
OBS_INPUT_AUDIO_MONITOR_TYPE_CHANGED_EVENT_ID,
OBS_INPUT_AUDIO_TRACKS_CHANGED_EVENT_ID
OBS_INPUT_AUDIO_TRACKS_CHANGED_EVENT_ID,
OBS_CONNECTED_EVENT_ID,
OBS_DISCONNECTED_EVENT_ID
} from "./constants";
import logger from "../../../logwrapper";

Expand Down Expand Up @@ -371,14 +373,18 @@ async function maintainConnection(
logger.info("Successfully connected to OBS.");

connected = true;
eventManager?.triggerEvent(OBS_EVENT_SOURCE_ID, OBS_CONNECTED_EVENT_ID, {});

setupRemoteListeners();

obs.on("ConnectionClosed", () => {
if (!connected) {
return;
}

connected = false;
eventManager?.triggerEvent(OBS_EVENT_SOURCE_ID, OBS_DISCONNECTED_EVENT_ID, {});

if (isForceClosing) {
return;
}
Expand Down

0 comments on commit 2a63807

Please sign in to comment.