Appearance
Class: VariablesService
Shared channel variables for widgets, available via kapp.variables. Names are used unchanged, without automatic prefixes or ownership by an app. The channel has a shared limit of 100 variables by default; existing values remain writable at the limit. Widgets have no separate quota or app scopes. Apps use AppVariablesService to read a streamer-selected variable instead.
Implements
Constructors
Constructor
ts
new VariablesService(): VariablesService;Returns
VariablesService
Methods
create()
ts
create(name, value): Promise<ChannelVariable>;Creates a channel variable without overwriting an existing value. Widget-only. Rejects with 409 if the name exists or the channel limit is reached.
Parameters
name
string
Channel variable name, used unchanged (255 characters maximum).
value
string
Initial non-empty string (255 characters maximum).
Returns
Promise<ChannelVariable>
The created variable.
See
set to create or update.
get()
ts
get(name): Promise<ChannelVariable>;Reads a channel variable by name. Widget-only. Only a 404 becomes null; permission and network errors remain rejections.
Parameters
name
string
Exact channel variable name.
Returns
Promise<ChannelVariable>
The matching variable, or null if missing.
Example
ts
const score = await kapp.variables.get('score');
const count = score ? Number(score.value) : 0;set()
ts
set(name, value): Promise<ChannelVariable>;Creates a variable if missing, otherwise updates its value. Widget-only. Creation and quota checks are atomic on the server. A new name rejects with 409 at the channel limit; an existing name remains writable. A separate get() followed by set() is not an atomic increment.
Parameters
name
string
Channel variable name, used unchanged (255 characters maximum).
value
string
New non-empty string (255 characters maximum).
Returns
Promise<ChannelVariable>
The created or updated variable.
See
create to initialize without overwriting.