WidgetAlerts and AlertRuntime
No-code alerts (the Alerts template) are designed on the editor canvas and saved in alerts of
manifest.json. Two global objects put them on screen, and both let you add your own code.
WidgetAlerts
Section titled “WidgetAlerts”The interpreter that draws the manifest.alerts design using Widget.queue.
It only exists if the manifest has alerts.
WidgetAlerts.start(hooks?): starts the design alerts. Hooks are optional.WidgetAlerts.clear(): empties the alert queue, removes the one on screen and cuts its sound, like “Clear alerts” from Streamer.bot.
The start hooks:
before(alert): before an alert goes in the queue. Returnfalseto skip it.after(alert): when the alert is removed from the screen.layer(layer, element, alert): every layer once built, to change it your way. Hidden layers (hidden) are not built.
WidgetAlerts.start({ before(alert) { return alert.data.user !== "annoying_bot"; },});AlertRuntime
Section titled “AlertRuntime”The engine of the visual editor alerts. It lives inside the generated part of script.js (the one marked with
⟦estudio⟧), so your code goes outside that mark, in your part of the file.
AlertRuntime.features: what this engine carries according to the design (sound, video, follow folding…).AlertRuntime.alerts: the design alerts (manifest.alerts); they can be changed on the fly.AlertRuntime.show(event, data?): queues the alert that listens to that event with this data, as if it came from Streamer.bot. Returnsfalseif nothing is shown.AlertRuntime.render(alertId, variantId, sample?): draws a variant still, with sample data, and returns its element.AlertRuntime.clear(): empties the queue, removes the alert on screen and cuts its sound.
Hooks: AlertRuntime.hooks
Section titled “Hooks: AlertRuntime.hooks”Assign them from your part of script.js:
AlertRuntime.hooks.before(alert): before an alert goes in the queue;falseskips it.AlertRuntime.hooks.after(alert): when the alert is removed from the screen.AlertRuntime.hooks.layer(name, element, alert): every layer and group once built, by their name in the code.
AlertRuntime.hooks.layer = (name, element, alert) => { if (name === "title") element.style.letterSpacing = "0.05em";};Playback: AlertRuntime.timeline
Section titled “Playback: AlertRuntime.timeline”This is what the editor uses to play an alert outside the queue and without sound.
AlertRuntime.timeline.state:status("idle","playing"or"paused"),phase("enter","active","exit"ornull),alertId,variantIdandnodes.AlertRuntime.timeline.play(alertId, variantId, options?): enter, active phase and exit. Withnodesonly those nodes are animated. Returnstrueif it finishes andfalseif it stops early.AlertRuntime.timeline.pause(): stops at the exact moment, including the active phase clock;falseif it was not playing.AlertRuntime.timeline.resume(): continues from where it stopped;falseif it was not paused.AlertRuntime.timeline.restart(): starts the last one again, with the same options.AlertRuntime.timeline.stop(): stops and removes the one playing.AlertRuntime.timeline.watch(callback): notifies each state change; returns how to stop listening.