Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
aitum.js
Advanced tools
Readme
JS/TS library for Aitum's Public API. This library requires Aitum to be installed and running. You can read the API documentation here.
The main goal of this library is to provide an easy-to-use wrapper for using Aitum's public API, instead of having to spend the time implementing your own logic to make requests.
If you are looking for a more integrated way to do custom code with Aitum, please take a look at our Custom Code Wrapper project.
To install this module, please follow the steps below for your package manager of choice:
# npm
npm i -s aitum.js
# yarn
yarn add aitum.js
To get started, import and instantiate the library via its get
method.
import { AitumJS } from 'aitum.js';
import { DeviceType } from 'aitum.js/lib/enums';
// Instantiate the library
// You can optionally provide an IP address to the machine running Aitum. It will default to 127.0.0.1
const lib = AitumJS.get();
// Example: Trigger an Aitum rule using its ID
// Grab all devices, filtered by Aitum devices, grab the first one.
const aitumDevice = (await lib.getDevices(DeviceType.Aitum))[0];
await aitumDevice.triggerRule('rule-id');
// Example: Change to a specific scene on OBS
// Grab all devices, filtered by OBS devices, grab the first one.
const obsDevice = (await lib.getDevices(DeviceType.OBS))[0];
await obsDevice.changeScene('my awesome scene');
NOTE: REWRITE IN PROGRESS, BELOW IS NOT COMPLETE AND MAY BE INCORRECT
The methods in this library mostly correspond to the methods listed in the Public API documentation.
There are multiple ways to filter down to get a single device, below are a few examples:
import { AitumJS } from 'aitum.js';
import { DeviceType } from 'aitum.js/lib/enums';
// Instantiate the library
// You can optionally provide an IP address to the machine running Aitum. It will default to 127.0.0.1
const lib = AitumJS.get();
// Filter all devices by the type we want to find
const allOBSDevices = await lib.getDevices(DeviceType.OBSV5);
// If you have more info for filtering ahead of time
const singleOBSDevice = (await lib.getDevices(DeviceType.OBSV5, { host: 'aitum-host-id', name: 'device-name' }))[0];
For interfacing with OBS (WS 5 and later) devices.
changeScene(scene: string)
- Change the current OBS scenechangeFilterVisibility(source: string, filter: string, enabled: boolean)
- Change a source filter's visibilitychangeSceneItemVisibility(scene: string, item: string, visible: boolean)
- Change the visibility of a specific source in a scenemuteAudio(input: string, mute: boolean)
- Change the mute state of an audio deviceplayPauseMedia(source: string, play: boolean)
- Change the play/pause state of a media sourcerestartMedia(source: string)
- Restart a media sourcestopMedia(source: string)
- Stop a media sourcenextMediaItem(source: string)
- Play the next media itempreviousMediaItem(source: string)
- Play the previous media itemrefreshBrowserSource(source: string)
- Refresh a browser sourcesetRecording(state: boolean)
- Set recording statetoggleRecording()
- Toggle recording statesetStreaming(state: boolean)
- Set streaming statetoggleStreaming()
- Toggle streaming statesetReplayBuffer(state: boolean)
- Set replay buffer statetoggleReplayBuffer()
- Toggle replay buffer statesaveReplayBuffer()
- Save current replay buffersendCustomMessage(data: object)
- Send a custom obs-websocket
message. This is usually not very useful unless you have code interfacing directly with obs-websocketsetBrowserSourceProperties(source: string, options: { url?: string, fps?: number, routeAudio?: boolean })
- Set browser source propertiessetDisplaySourceProperties(source: string, options: { display?: number, showCursor?: boolean })
- Set display source propertiessetTextSourceProperties(source: string, options: { text?: string, dropShadow?: boolean, outline?: boolean, antiAliasing?: boolean, wordWrap?: boolean, colour?: string, colourTwo?: string })
- Set text source propertiessetSourceFilterProperties(source: string, filter: string, options: object)
- Set source filter propertiessendVendorRequest(vendorName: string, eventType: string, eventData?: object)
- Send vendor requestFor interfacing with MIDI devices.
noteOn(channel: number, note: number, velocity: number)
- Send a Note OnnoteOff(channel: number, note: number, velocity: number)
- Send a Note OffnoteOnOff(channel: number, note: number, velocity: number, hold: number)
- Send a Note On followed by a Note OffcontrolChange(channel: number, value: number, controller: number)
- Send a Control Changeprogram(channel: number, number: number)
- Send a ProgrampolyAftertouch(channel: number, note: number, velocity: number)
- Send a Poly AftertouchchannelAftertouch(channel: number, pressure: number)
- Send a Channel Aftertouchpitch(channel: number, value: number)
- Send a Pitchposition(value: number)
- Send a Positionselect(song: number)
- Send a Selectstart()
- Send a Startcontinue()
- Send a Continuestop()
- Send a StopactiveSense()
- Send an Active Sensereset()
- Send a ResetFor interfacing with Twitch.
If you're looking for how to interact with Twitch Redemptions, please check here.
startCommercial(length: number)
- Start a CommercialcreateStreamMarker()
- Create a Stream MarkerstartPoll(title: string, duration: number, choices: string[], pointsVoting = false, pointsPerVote?: number)
- Starts a new PollendPoll()
- Ends a poll if one is activegetPoll()
- Gets the active poll if one is runningannouncement(message: string, colour?: TwitchChatAnnounceColour)
- Sends an announcementsetBanStatus(ban: boolean, username: string, reason?: string)
- Ban/unbans a useremoteOnly(enabled: boolean)
- Sets emote only modefollowerOnly(enabled: boolean)
- Sets follower only modesetVIP(vip: boolean, username: string)
- VIPs/unVIPs a userraid(username: string)
- Starts a raidsubOnlyMode(enabled: boolean)
- Sets subscriber only modesetTimeoutStatus(timeout: boolean, username: string, reason?: string)
- Timeouts/untimeouts a userclearChat()
- Clear chatsetModStatus(mod: boolean, username: string)
- Mod/unmod a useruniqueChat(enabled: boolean)
- Sets unique chat modesendMessage(message: string)
- Sends a message as the broadcastersetTitle(title: string)
- Sets the stream titleFor interfacing with Aitum's in built tools.
triggerRule(rule: string | Rule)
- Trigger a rule in Aitum. (Note: When triggering a rule with this method, any triggers and checks in the rule are ignored, and the actions are immediately executed)playSound(path: string, volume: number)
- Play a sound in AitumstopAllSounds()
- Stop all sounds playing in AitumFor interfacing with Elgato Key Lights & Light Strips.
setState(on: boolean)
- Set the light statesetColour(colour: string)
- Set the light coloursetColourTemperature(temperature: number, brightness: number)
- Set the light colour temperatureFor interfacing with OSC devices.
float(address: string, value: number)
- Send a Floatinteger(address: string, value: number)
- Send a Integerstring(address: string, value: string)
- Send a Stringboolean(address: string, value: boolean)
- Send a Booleannull(address: string)
- Send a NullUse your AitumJS instance to get Redemptions, e.g.
await AitumJS.get().getRedemptions();
update(data: Partial<ITwitchRedemption>)
- Update a RedemptionUse your AitumJS instance to get Redemption Groups, e.g.
await AitumJS.get().getRedemptionGroups();
getRedemptions()
- Get all Redemptions in this Groupenable()
- Enable the Redemption Groupdisable()
- Disable the Redemption GroupUse your AitumJS instance to get Rules, e.g.
await AitumJS.get().getRules();
trigger()
- Trigger the ruleUse your AitumJS instance to get Global Variables, e.g.
await AitumJS.get().getVariables();
update(value: string | string[] | number | boolean)
- Update the variableFor ease of use, we expose the library axios
for you to use yourself in any HTTP requests you would like to make (even non-Aitum ones). You can call it by using:
// GET request
const get = await AitumJS.http.get('https://api.example.com');
// POST request
const post = await AitumJS.http.post('https://api.example.com', {foo: 'bar'}, {
headers: {
'User-Agent': 'My Example User Agent'
}
});
You can learn more about how to use axios
and its methods on its documentation.
As we expect that some people using this library may be new to JavaScript/TypeScript, we recommend learning the core concepts of the language before diving straight in. We also recommend this video series. Here's some common mistakes:
Everything in aitum.js is a class object. However, if you are writing your own code and making requests to other API services, you may need to serialise and de-serialise JSON. If you use our exposed HTTP client (axios
), this should be done automatically for you. If you need to serialise and de-serialise JSON, use:
// Serialise to string
const d = {foo: "bar"};
const asString = JSON.stringify(d); // returns {foo: "bar"} as a string
// Deserialise to JS object
const d2 = '{foo: "bar"}';
const asObject = JSON.parse(d2); // returns {foo: "bar"} as an object
This library is designed with TypeScript in mind, so provides various TypeScript interface definitions for objects returned by methods in this library. You can import them from aitum.js/lib/interfaces/
.
FAQs
API Wrapper library for Aitum's Public API
The npm package aitum.js receives a total of 4 weekly downloads. As such, aitum.js popularity was classified as not popular.
We found that aitum.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.