Platforms
A platform, such as described previously, is defined using the Platform class exposed by the JavaScript file present at the following address:
https://obs.multistream.tools/v1/adapters.js
This file/module also exports a number of constants useful for modeling the Facebook, Kick, TikTok, Trovo, Twitch and YouTube platforms.
API
The TypeScript signature of the Platform class is as follows:
type Id = string;
type Event = string;
type Alerts = Event[];
type Filters = {
alerts?: false;
chat?: false;
session?: true;
other?: true;
[key: Event]: false;
};
declare class Platform {
constructor(id: Id, alerts: Alerts, filters?: Filters, extraAlerts?: Alerts);
get id(): Id;
has(event: Event): boolean;
}
Parameters
Each parameter listed below can no longer be modified once the platform has been instantiated (read only).
The id of a platform is a unique identifier of type string generally corresponding to the name of the platform in question; written in lowercase by convention. For example 'twitch' for Twitch, 'youtube' for YouTube, etc.
The alerts of a platform correspond to the list of alert category events that it supports, which can be disabled using filters. It is an array of which each element is of type string, corresponding to the name of a given alert; written in lowercase by convention. For example 'subscriber' for a paid subscription on Twitch, 'sponsor' for a paid subscription on YouTube, etc.
The optional filters parameter allows you to enable/disable certain events normally emitted by the platform. This is particularly useful when you are modeling a platform intended to be reused by other developers, as we did with the pre-configured platforms listed below . It is an object whose each property has the name of the event you want to enable/disable and the value true or false depending on whether the event is disabled or enabled by default.
Events that can be enabled/disabled correspond to alerts from a platform but also to entire categories of events: session, alerts, chat, and other. load events cannot be disabled, session and load ones are disabled by default. These categories are described on the page dedicated to adapters.
import {
chat,
subscriber,
Platform,
Twitch
} from 'https://obs.multistream.tools/v1/adapters.js';
const customAlert = 'alert';
class CustomPlatform extends Platform {
constructor(...args) {
super('custom', [customAlert], ...args);
}
}
const customPlatform = new CustomPlatform({
[chat]: false,
[customAlert]: false
});
const twitchPlatform = new Twitch({
[chat]: false,
[subscriber]: false
});
The optional extraAlerts parameter allows you to add alert category events to the list of those emitted by the platform. This is particularly useful when you are modeling a platform intended to be reused by other developers, as we did with the pre-configured platforms listed below. This is the same data type as for the alerts parameter.
import {
Platform,
Twitch
} from 'https://obs.multistream.tools/v1/adapters.js';
const customAlert = 'alert';
const commonAlerts = ['alert1', 'alert2', 'alert3'];
class CustomPlatform extends Platform {
constructor(...args) {
super('custom', [customAlert], ...args);
}
}
const customPlatform = new CustomPlatform(undefined, commonAlerts);
const twitchPlatform = new Twitch(undefined, commonAlerts);
Properties
It is possible to retrieve the value of the id of a platform after its creation. To do this, simply access the property (getter), simply named id, present on any instance of the Plaftorm class.
import {
twitch,
Platform,
Twitch
} from 'https://obs.multistream.tools/v1/adapters.js';
const customPlatformId = 'custom';
const customPlatform = new Platform(customPlatformId, ['alert']);
console.log(customPlatform.id === customPlatformId); // true
const twitchPlatform = new Twitch();
console.log(twitchPlatform.id === twitch); // true
Methods
It is also possible to know if a given platform supports a specific event by calling the method named has present on any instance of the Plaftorm class. This method will return true if the platform in question is capable of emitting the desired event or false if this is not the case (the latter is not supported or has been disabled thanks to filters).
import {
alerts,
subscriber,
Platform,
Twitch
} from 'https://obs.multistream.tools/v1/adapters.js';
const customAlert = 'alert';
class CustomPlatform extends Platform {
constructor(...args) {
super('custom', [customAlert], ...args);
}
}
let customPlatform = new CustomPlatform();
console.log(customPlatform.has(alerts)); // true
console.log(customPlatform.has(customAlert)); // true
console.log(customPlatform.has(subscriber)); // false
customPlatform = new CustomPlatform({ [customAlert]: false }, [subscriber]);
console.log(customPlatform.has(alerts)); // true
console.log(customPlatform.has(customAlert)); // false
console.log(customPlatform.has(subscriber)); // true
customPlatform = new CustomPlatform({ [alerts]: false }, [subscriber]);
console.log(customPlatform.has(alerts)); // false
console.log(customPlatform.has(customAlert)); // false
console.log(customPlatform.has(subscriber)); // false
let twitchPlatform = new Twitch();
console.log(twitchPlatform.has(alerts)); // true
console.log(twitchPlatform.has(subscriber)); // true
console.log(twitchPlatform.has(customAlert)); // false
twitchPlatform = new Twitch({ [subscriber]: false }, [customAlert]);
console.log(twitchPlatform.has(alerts)); // true
console.log(twitchPlatform.has(subscriber)); // false
console.log(twitchPlatform.has(customAlert)); // true
twitchPlatform = new Twitch({ [alerts]: false }, [customAlert]);
console.log(twitchPlatform.has(alerts)); // false
console.log(twitchPlatform.has(subscriber)); // false
console.log(twitchPlatform.has(customAlert)); // false
Pre-configured platforms
We provide the following platforms, exposed by the same JavaScript file cited throughout this page, to save you from having to model them yourself.
| class | id | events |
|---|---|---|
Facebook | 'facebook' | 'follower', 'fan', 'videolike', 'supporter', 'share', 'stars' |
Kick | 'kick' | 'subscriber', 'follower' |
TikTok | 'tiktok' | 'subscriber', 'gift', 'follower', 'share', 'like' |
Trovo | 'trovo' | 'subscriber', 'elixir', 'follower', 'raid' |
Twitch | 'twitch' | 'subscriber', 'cheer', 'follower', 'raid', 'reward' (channel points) |
YouTube | 'youtube' | 'sponsor', 'superchat', 'subscriber' |
Their TypeScript signatures are as follows:
declare class Facebook extends Platform {
constructor(filters?: Filters, extraAlerts?: Alerts);
}
declare class Kick extends Platform {
constructor(filters?: Filters, extraAlerts?: Alerts);
}
declare class TikTok extends Platform {
constructor(filters?: Filters, extraAlerts?: Alerts);
}
declare class Trovo extends Platform {
constructor(filters?: Filters, extraAlerts?: Alerts);
}
declare class Twitch extends Platform {
constructor(filters?: Filters, extraAlerts?: Alerts);
}
declare class YouTube extends Platform {
constructor(filters?: Filters, extraAlerts?: Alerts);
}