twitch-osc-bridge
v1.0.4
Published
A bridge between Twitch events (EventSub) and OSC messages.
Maintainers
Readme
Twitch Channel Points to OSC Bridge
1. Introduction
This project bridges Twitch channel point reward redemptions with OSC (Open Sound Control) messages, enabling real-time control of VRChat avatar parameters (or other OSC-compatible applications) via Twitch interactions. It listens for specific reward redemptions on a configured Twitch channel and triggers corresponding OSC actions.
Core technologies: Node.js, TypeScript, Twurple for Twitch integration, node-osc and oscquery for OSC communication.
2. Features
- Connects Twitch channel point redemptions to OSC messages.
- Maps specific reward titles to specific OSC parameter addresses.
- Supports two OSC action types:
set: Set an OSC parameter to a specific value (float, int, bool).toggle: Toggle a boolean OSC parameter.
- Optional
timeoutforsetactions to automatically revert the parameter to a specified value after a delay. - Dynamically discovers available VRChat avatar OSC parameters using OSCQuery.
- Dynamically fetches the list of available channel point rewards from the Twitch API.
- Reloads configuration and updates mappings automatically if
config/config.jsonis changed. - Adapts mappings if VRChat avatar OSC parameters change during runtime.
- Provides status updates and error reporting (via EventEmitter, potentially for integration with UIs like Electron).
3. Architecture Overview
Core Components
- TwitchOscIntegrationService: Orchestrates the application flow, initializes components, manages state, and handles updates.
- Twitch Integration (
@twurple):- TwitchAuth: Handles OAuth authentication with Twitch.
- TwitchApi: Interacts with the Twitch API (fetches user ID, channel rewards).
- TwitchEventSubListener: Listens for real-time events, specifically channel point redemptions.
- OSC Communication (
node-osc,oscquery):- OscClient: Sends OSC messages to the target application (e.g., VRChat).
- OscQuery: Discovers available OSC parameters from the target application.
- ConfigManager: Loads, manages, and provides access to settings from
config/config.json, including credentials and the crucial reward-to-OSC mapping.
Component Diagram
flowchart TD
TwitchOscIntegrationService
ConfigManager
TwitchAuth
TwitchApi
TwitchEventSubListener
OscClient
OscQuery
TwitchOscIntegrationService --> ConfigManager
TwitchOscIntegrationService --> TwitchAuth
TwitchOscIntegrationService --> TwitchApi
TwitchOscIntegrationService --> TwitchEventSubListener
TwitchOscIntegrationService --> OscClient
TwitchOscIntegrationService --> OscQuery
TwitchEventSubListener --> TwitchApi
TwitchAuth --> TwitchApi
OscClient --> OscQuerySequence Diagram
sequenceDiagram
participant User as Twitch User
participant Twitch as Twitch
participant TwitchEventSubListener as EventSubListener
participant ConfigManager as ConfigManager
participant OscClient as OscClient
participant VRChat as VRChat (OSC Target)
User->>Twitch: Redeem channel point reward
Twitch-->>TwitchEventSubListener: Event: reward redemption
TwitchEventSubListener->>ConfigManager: Lookup reward mapping
alt Mapping found
ConfigManager-->>TwitchEventSubListener: Mapping details
TwitchEventSubListener->>OscClient: Send OSC message (set/toggle)
OscClient->>VRChat: OSC message delivered
alt Set action with timeout
OscClient-->>OscClient: Wait for delay
OscClient->>VRChat: Revert OSC parameter
end
else No mapping
ConfigManager-->>TwitchEventSubListener: No action
end4. Setup & Installation
- Prerequisites:
- Node.js v18+ recommended
- pnpm (
npm install -g pnpm)
- Clone Repository:
git clone <repository-url> - Install Dependencies:
cd <repository-directory> pnpm install - Twitch Application:
- Register a new application on the Twitch Developer Console to obtain a Client ID and Client Secret.
- Set the OAuth Redirect URL in your Twitch app settings (e.g.,
http://localhost:3000/auth/callbackif using the default flow).
- Configuration:
- Locate the
config/directory. Ifconfig.jsondoes not exist, running the application once may generate a template. - Edit
config/config.jsonwith your details (see next section).
- Locate the
5. Configuration (config/config.json)
The configuration file defines Twitch credentials, OSC target, and reward mappings.
{
"twitch": {
"clientId": "your-twitch-client-id",
"clientSecret": "your-twitch-client-secret",
"tokenFilePath": "./tokens.json",
"channelName": "your-twitch-channel"
},
"osc": {
"serverAddress": "127.0.0.1",
"serverPort": 9000
},
"rewardMapping": [
{
"reward": {
"title": "Wave"
},
"osc": {
"type": "set",
"address": "/avatar/parameters/Wave",
"value": true
}
},
{
"reward": {
"title": "Toggle Hat"
},
"osc": {
"type": "toggle",
"address": "/avatar/parameters/Hat"
}
},
{
"reward": {
"title": "Big Mode"
},
"osc": {
"type": "set",
"address": "/avatar/parameters/BigMode",
"value": 1
},
"timeout": {
"delayMs": 10000,
"value": 0
}
}
]
}Configuration Fields
- twitch
clientId: Twitch application Client ID.clientSecret: Twitch application Client Secret.tokenFilePath: Path to store authentication tokens.channelName: Twitch channel name to monitor.
- osc
serverAddress: OSC target IP (usually127.0.0.1for VRChat).serverPort: OSC target port (usually9000for VRChat).
- rewardMapping: Array of reward-to-OSC mappings.
- Reward
title: Exact or substring of the Twitch reward title.
- OSC Action
type:"set"(default) or"toggle".address: OSC parameter address (e.g.,/avatar/parameters/YourParameterName).value: Value to set (forsettype).
- Timeout (optional, for
settype)delayMs: Delay in milliseconds before reverting.value: Value to revert to.
- Reward
Examples
- Set Value:
{ "reward": { "title": "Wave" }, "osc": { "type": "set", "address": "/avatar/parameters/Wave", "value": true } } - Toggle Boolean:
{ "reward": { "title": "Toggle Hat" }, "osc": { "type": "toggle", "address": "/avatar/parameters/Hat" } } - Set with Timeout:
{ "reward": { "title": "Big Mode" }, "osc": { "type": "set", "address": "/avatar/parameters/BigMode", "value": 1 }, "timeout": { "delayMs": 10000, "value": 0 } }
6. Usage
- Development:
Run with live reloading:pnpm dev - Production:
- Build the project:
pnpm build - Run the compiled code:
pnpm start
- Build the project:
- The application runs in the background, listening for Twitch events and sending OSC messages.
- Authentication:
On first run, the application will prompt you to authenticate with Twitch (usually by opening a browser window). Follow the instructions to grant the necessary permissions.
7. Contributing
Contributions are welcome!
To contribute:
- Fork the repository.
- Create a feature branch.
- Make your changes and commit with clear messages.
- Push to your fork and open a pull request.
Please ensure your code adheres to the project's style and includes relevant tests/documentation.
8. License
This project is licensed under the ISC License. See the LICENSE file for details.
