VibHub-Browser

From VibHub Wiki
Revision as of 11:58, 29 January 2026 by Jasx (talk | contribs)
Jump to navigation Jump to search

The library can be cloned from here.

Setup

Start by importing the library:

import {default as VH, VhProgram as Program, VhStage as Stage} from 'vh-socket.js';

Next you'll want to extend VH with a class of your own.

class App extends VH{

Constructor:

constructor(...args){
	super(...args);
}

All done for our VibHub manager class! Let's set all ports on our device to max!

(async () => { const manager = new App(); manager.onDeviceOnline = function(device){ device.set(255); // Sets all ports on the device to max intensity (or 1/4 if you enable high res) }; await manager.addDevice("<your device ID>"); })();

VhSocket

Versions:

  • m - 2026 VibHub Micro
  • o - Original VibHub 4x AA battery version.

Overridable

These methods are meant to be overridden by your extended class or on the fly.

Method Versions Args Async Description
onDeviceOnline m,o VhDevice device Raised when a device has come online.
onDeviceOffline m,o VhDevice device Raised when a device has gone offline.
onDeviceBattery m VhDevice device Battery status has been updated
onCustomMessage m string device_ID, string socket_ID, var data Raised when a custom message has been received (advanced).
onConnected m,o Raised when the app itself has connected to a VibHub server.
onDisconnected m,o Raised when the app itself has disconnected from the VibHub server.
onTick m,o Raised n times per second (based on what you passed to constructor).

Methods

Method Versions Args Returns Async Description
constructor m,o string appName, string server = "https://vibhub.io", int port = 443, int fps = 30, bool autoHighRes VhSocket Library constructor.

- appName can be anything you'd like to call your app (mainly used for debugging. - server is the server to connect to. - port is the port (hurdur). Usually 443 (SSL) or 80 - fps sets a max limit on how often we can send messages to the device. I don't recommend setting this to more than 60. - autoHighRes tries to automatically enable High Res mode if the device supports it. High Res gives you a resolution of 1024 instead of 256, for more granular control.

begin m,o VhSocket Yes Starts the app, connecting via socket.io and binding events.
isConnected m,o bool Returns true if we're connected to the server.
setName m,o bool Yes Sends the app name to the server (auto handled in begin). Returns true on success.
handleNewIndex m,o array devices Yes Internal handler for the server refreshing our managed devices.
handleDeviceOnline m,o array data Internal handler for device data received. Data is an array of: string id, string socketID, var metadata
handleDeviceOffline m,o data Internal handler for device disconnect. Data is an array of: string id
handleDeviceBattery m data Internal handler for device battery updates. Data is an object with {string id, bool batteryLow, int mv(millivolts), int xv(max millivolts)}