use-obs-browser

0.0.11 • Public • Published

use-obs-browser


A thin React hooks library to use the javascript API from the obs-browser source plugin (at the commit d1fa35dcbc384136e9e883f2d6071b14fd8f9a65)

install

In your project folder:

npm install --save-dev use-obs-browser

or the shorter: npm i -SD use-obs-browser

Philosophy

I didn't want to overcomplicate everything, it's just a collection of hooks that plugs straight into the obs-browser source plugin js API when the app is opened in OBS as a browser source.

Exemple: you want to get the version of the plugin you're running with ? Just:

import { useOBSVersion } from "use-obs-browser";

return () => <p>OBS Browser source plugin version: {useOBSVersion()}</p>;

Why all those hooks and not just functions ? Because at some point in the loading of the page by the obs-browser plugin there are few things missing, first the window object, then event the obsstudio object is not directly available. Plus there is the right management, like, you can't access the output status if the right to access them is not bestowed by the plugin.

There shouldn't be any error or exception, everything is made to run smoothly and if something is not working, or you just don't have the rights to do it, it just return the default or undefined.

Outlines

  • CONTROL_LEVELS, their list, indexes are important:

    ["NONE", "OBS_STATE", "USER_INFORMATIONS", "BASIC", "ADVANCED", "TOTAL"];
  • hasAtLeastAccess: take the index of a an CONTROL_LEVELS and return a function that take an supposed CONTROL_LEVELS index (integer) as argument and check if it's equal or bigger than the former one. Mainly serve as building all the hasAtLeast[CONTROL_LEVEL]Access functions that ease the writing of access control code:

      hasAtLeastOBS_STATEAccess
      hasAtLeastUSER_INFORMATIONSAccess
      hasAtLeastBASICAccess
      hasAtLeastADVANCEDAccess
      hasAtLeastTOTALAccess
    
  • statesStates is a state object that contain the various states possible of the various states of OBS (yo dawg), so, in order, because the indexes are important:

    {
      "recording": ["stopped", "starting", "started", "paused", "stopping"],
      "replaybuffer": ["stopped", "starting", "started", "saved", "stopping"],
      "streaming": ["stopped", "starting", "started", "stopping"],
      "virtualcam": ["stopped", "started"]
    }
  • useOBSBrowser: return the obsstudio object.

  • useOBSControlLevel: return the current controlLevel.

  • useOBSCurrentScene: require the USER_INFORMATIONS control level, return the currentScene onject, containing: { height: [height of the scene in pixels], width: [width of the scene in pixels], name: [name of the scene] }.

  • useOBSCurrentTransition: require the USER_INFORMATIONS control level, return the currentTransition name.

  • useOBSoutputStatus: require the OBS_STATE control level, return the object containing the various status of the various outputs, see statesStates. By default:

    {
      recording: "stopped",
      replaybuffer: "stopped",
      streaming: "stopped",
      virtualcam: "stopped"
    }
  • useOBSScenes: require the USER_INFORMATIONS control level, return the array containing the various scenes name available.

  • useOBSTransitions: require the USER_INFORMATIONS control level, return the array containing the various transitions name available.

  • useOBSVersion: return the version string of the current OBS Browser source plugin.

[TO BE CONTINUED]

Package Sidebar

Install

npm i use-obs-browser

Weekly Downloads

3

Version

0.0.11

License

GPL-3.0

Unpacked Size

51.2 kB

Total Files

8

Last publish

Collaborators

  • kanethornwyrd