All Projects → obs-websocket-community-projects → obs-websocket-java

obs-websocket-community-projects / obs-websocket-java

Licence: MIT license
A java library for obs-websocket

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to obs-websocket-java

obs-face-tracker
Face tracking plugin for OBS Studio
Stars: ✭ 185 (+302.17%)
Mutual labels:  obs, obs-studio, obs-studio-plugin
go-obs-websocket
Go client for obs-websocket
Stars: ✭ 86 (+86.96%)
Mutual labels:  obs, obs-studio
obs-studio
This is a community-supported modified build of OBS Studio.
Stars: ✭ 86 (+86.96%)
Mutual labels:  obs, obs-studio
XION-ChaseCam
This is a free-to-use HTML/javascript based overlay for roleplay streamers. Basically it mimics the overlay of the AXON bodycam, but since most folks play in 3rd person, it's a ChaseCam. I've included a logo, and the html file. The html file has the css, html, and javascript all in one file for ease of editing. Goto line 81 of the html file to c…
Stars: ✭ 27 (-41.3%)
Mutual labels:  obs, obs-studio
obs-text-slideshow
OBS plugin inspired by the built in image slideshow, except for text sources instead. Both Free Type 2 and GDI+ are supported.
Stars: ✭ 45 (-2.17%)
Mutual labels:  obs, obs-studio
obs-zoom-and-follow
Dynamic zoom and mouse tracking script for OBS Studio
Stars: ✭ 126 (+173.91%)
Mutual labels:  obs, obs-studio
OBS-ChatSpam
Python script for OBS Studio that posts messages in Twitch chat
Stars: ✭ 26 (-43.48%)
Mutual labels:  obs, obs-studio
meme-box
Manage and trigger media in OBS as a browser source
Stars: ✭ 82 (+78.26%)
Mutual labels:  obs, obs-studio
kiwi
Kiwi turns your Pimoroni Keybow into a fully customizable poor-man's Elgato Stream Deck!
Stars: ✭ 40 (-13.04%)
Mutual labels:  obs, obs-studio
obs-golang-plugin
OBS Studio Golang Plugin
Stars: ✭ 50 (+8.7%)
Mutual labels:  obs, obs-studio
character-overlay
Web App for adding an OBS overlay with character information such as name, picture, and health for your favorite role-playing game.
Stars: ✭ 17 (-63.04%)
Mutual labels:  obs, obs-studio
obs-websocket-js
Consumes https://github.com/obsproject/obs-websocket
Stars: ✭ 521 (+1032.61%)
Mutual labels:  obs, obs-studio
obs-streamlink
OBS source plugin to receive stream using streamlink.
Stars: ✭ 110 (+139.13%)
Mutual labels:  obs-studio, obs-studio-plugin
obs blade
Make use of the OBS WebSocket Plugin (https://github.com/obsproject/obs-websocket) and control your stream
Stars: ✭ 182 (+295.65%)
Mutual labels:  obs, obs-studio
obs-text-pthread
Rich text source plugin for OBS Studio
Stars: ✭ 15 (-67.39%)
Mutual labels:  obs-studio, obs-studio-plugin
obs-screenshot-plugin
An OBS Studio filter plugin to save screenshots of a source/scene
Stars: ✭ 93 (+102.17%)
Mutual labels:  obs, obs-studio
CounterStrike-GlobalOffensive-LiveStat-for-OBS-Studio
Showing you LIVEstats of CS:GO in your Stream like OBS-Studio while playing/streaming.
Stars: ✭ 24 (-47.83%)
Mutual labels:  obs, obs-studio
BeatRecorder
Easily record your BeatSaber gameplay!
Stars: ✭ 20 (-56.52%)
Mutual labels:  obs, obs-studio
OBS
No description or website provided.
Stars: ✭ 42 (-8.7%)
Mutual labels:  obs
obs-websocket-gd
Control OBS from inside a Godot game or app.
Stars: ✭ 42 (-8.7%)
Mutual labels:  obs

OBS WebSocket Java


A Java library for the OBS-Studio WebSocket plugin initiated by Palakis.

Software Requirements

  • OBS version 27+
  • OBS Websocket version 5+

Note: Streamlabs OBS (SLOBS) is not supported

Dependencies

Include the library in your project from Maven Central:

Maven

<dependency>
  <groupId>io.obs-websocket.community</groupId>
  <artifactId>client</artifactId>
  <version>2.0.0</version>
</dependency>

Gradle

dependencies {
    implementation 'io.obs-websocket.community:client:2.0.0'
}

Basic Usage & Examples

The OBSRemoteController is the client entrypoint, providing methods to interact with OBS. Construct an (immutable) instance via the builder and then connect.

OBSRemoteController controller = OBSRemoteController.builder()
  // set options, register for events, etc.
  // continue reading for more information
  .build();
controller.connect();

Take a look at the example project for a full example.

A description of every request and event can be found in the plugin's protocol.md file.

Authentication / OBS Details

By default, the builder connects to localhost on port 4455 without a password, and will wait 3 seconds for an initial response from OBS.

Version 5+ of OBS Websockets requires a password by default, so we recommend setting a password.

OBSRemoteController controller = OBSRemoteController.builder()
  .host("localhost")                  // Default host
  .port(4455)                         // Default port
  .password("your secure password")   // Provide your password here
  .connectionTimeout(3)               // Seconds the client will wait for OBS to respond
  .build();

OBS Event Registration

Listeners for OBS events can also be registered on the builder by specifying the event class and a callback that accepts the event.

OBSRemoteController controller = OBSRemoteController.builder()
  // with a method reference; better practice.
  .registerEventListener(
    StudioModeStateChangedEvent.class, someInstance::someMethod
  )
  // with an anonymous lambda; useful for exploring/debugging.
  .registerEventListener(
    CurrentProfileChangedEvent.class, (event) -> System.out.println(event)
  )
  // ...     
.build();

Connecting and Client Lifecycle Events

Connecting is non-blocking and by default the client will not connect until you call connect().

There are many lifecycle-related events available, however we recommend registering at least the onReady callback, as this is invoked once the client is ready to accept requests.

// Build the controller
OBSRemoteController controller = OBSRemoteController.builder()
  // ...
  .lifecycle()
    .onReady(someClassInstance::yourMethodMakingRequests)
    .and()
  .autoConnect(false) // Default; do not connect when built
  // ...     
.build();

// Connect to OBS
controller.connect();

We do not recommend interacting with the controller outside the onReady callback; the main thread will likely complete before the client is ready to accept requests, and this will throw an error.

// Build the controller
OBSRemoteController controller = OBSRemoteController.builder()
  // ...     
.build();

// Connect to OBS
controller.connect();

// Do NOT do this!
// This will cause an ERROR and shut-down the client
controller.getVersion(version -> System.out.println(version));

If you want to block main until the controller is ready, you can use a CompletableFuture; however, this is a poor practice so we do not show it here.

Error Handling

When the OBS Websocket encounters a significant problem (failed authentication, unknown message type, etc) it will close the connection. These events can be observed in the onClose lifecycle event.

Individual requests will include a status code(SourceNotFound, HotkeyNotFound, etc) as part of the response and do not result in the connection being closed.

The onError communicator and controller lifecycle events are reserved for exceptional events (null pointers and other exceptions) and for failure to connect to OBS (for example, if OBS Websocket isn't installed, if OBS isn't running, or it isn't accessible over the network).

Logging

This project ships with SLF4J as the logging facade.

As with any project using SLF4J, you are expected to setup a logger implementation. There are many examples of how to do this online; for your convenience we demonstrate below how to configure Maven to use Logback:

<dependencies>
    <dependency>
       <groupId>io.obs-websocket.community</groupId>
        <artifactId>client</artifactId>
        <version>...</version>
      </dependency>
    </dependency>
    
    <!-- Add your desired logging implementation -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.7</version>
    </dependency>
</dependencies>

Or with Gradle:

dependencies {
    implementation('io.obs-websocket.community:client:2.0.0')
    implementation 'ch.qos.logback:logback-classic:1.1.7'
}

Migrating from Twasi 1.X.X

Versions 1.X.X of this library were published under Twasi and were intended for OBS Websocket 4.X.X.

The current version of the library (2.0.0+) is published under io.obs-websocket.community, requires OBS Websocket 5.0.0+, and is not backwards compatible with 1.X.X.

There are several key differences to be aware of, for full details please see the current protocol for OBS Websocket.

📘 Notice to Developers: Repository Transfer 📘

On June 21st, 2021, this repository was transferred from the Twasi Organization to the obs-websocket-community-projects Organization. This was done to better align this library with the greater OBS Websocket plugin community, and provide better administrative tools.

Remotes will continue to operate as normal, due to GitHub automatic redirects. However, to avoid confusion GitHub strongly recommends you update those remotes.

If you haven't updated your remote, you can check like so; the below example shows an old remote:

C:\Users\...\websocket-obs-java>git remote -v
origin  https://github.com/Twasi/websocket-obs-java.git (fetch)
origin  https://github.com/Twasi/websocket-obs-java.git (push)

You can update and verify your remote is correct like this:

C:\Users\...\websocket-obs-java>git remote set-url origin https://github.com/obs-websocket-community-projects/websocket-obs-java.git
(no output)
C:\Users\...\websocket-obs-java>git remote -v
origin  https://github.com/obs-websocket-community-projects/websocket-obs-java.git (fetch)
origin  https://github.com/obs-websocket-community-projects/websocket-obs-java.git (push)

See Transferring a repository for more information.

Requests, Events, and Subscriptions

Most events and requests changed between the two libraries, due to changes in the OBS Websocket protocol. You can view the current protocol for the full list of available requests and events.

One new feature for events is Subscriptions. This feature reduces the performance impact for both OBS and your client by only sending event notifications you intend to receive (some events send messages several times per second, continuously).

Building

While the protocol requires subscriptions to be specified when identifying with OBS, you are not required to do this; our client library computes this for you based on what events you've registered listeners for.

Authentication and Error Handling

Prior to OBS Websocket 5+, authentication was optionally driven by the client. Now, the server drives the conversation; it sends a Hello response on first connect, requires the client to respond with an Identify, and then either drops the connection (failed authentication) or responds with an Identified success response.

This process is mirrored in the order of lifecycle events on the client. During successful authentication the sequence would look like this:

onConnect -> onHello -> onIdentified -> onReady

And in the case of failed authentication, the server closes the connection:

onConnect -> onHello -> onClose -> onDisconnect

Note that this is a change in this library from 1.X.X, which conflated connecting and authenticating in a single step, and relegated authentication failures to the error callback.

The onConnect callback only denotes that OBS could be reached over the network and not that it is authenticated and ready to accept requests.

The onError callback is only be used to monitor for critical exceptions (null pointers, failure to reach OBS, etc...), and not any authentication failures. Any call to onError will cause the client to automatically disconnect/stop.

See the protocol at OBS Websocket 5 Protocol for more detailed information, including WebSocketCloseCode and enumerations.

Blocking/Non-Blocking Connections

In 1.X.X, there was an isFailed blocking method available that could be called to block the main thread until the client was ready to send requests to OBS.

This has since been removed, as blocking the main thread is a poor way to handle program flow. Please use the onReady lifecycle event callback instead, as described above.


Contributing / Issues

Feedback and help are greatly appreciated!

If you want to contribute on this project, we ask you to:

  1. File a GitHub Issue to track it
  2. Fork the repo and make a pull-request

Please see CONTRIBUTING for more information.


Thanks to OBS WebSocket team for the great plugin!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].