17
ModuleServerAPI
Mees van der Wijk edited this page 2026-01-30 14:07:15 +01:00

ModuleServerAPI

The ModuleServerAPI is the powerful server-side foundation that brings your Getiyo modules to life. Every module you create relies on this API to handle the complex orchestration between users, data, and the Getiyo platform itself. Click here to view the introductions.

Sub Classes

GameLib

The GameLib inside the ModuleServerAPI.

api.GameLib;

Return GameLib The GameLib class

Libs

Standard libraries available through the ModuleServerAPI.

api.Libs;

Return Libs Included libraries

System

getModuleId

Get the current module id.

api.getModuleId();

Returns string Module ID

getChannelId

Get the current channel id.

api.getChannelId();

Returns string Channel ID

getChannelHostname

Get the current channel hostname.

api.getChannelHostname();

Returns string Channel Hostname

inDevelopmentMode

Check if Getiyo is running in development mode.

api.inDevelopmentMode();

Returns boolean Development mode active

onDestroy

Register a listener for when the module is destroyed from a channel. Make sure you stop your clocks and render loops here.

api.onDestroy(callback);
Argument Type Description
callback ( ):void Function that will be called when the module gets destroyed.

Communication

on

Register a listener for messages from the ModuleServerAPI.

api.on(header, callback);
Argument Type Description
header string To header of the messages the listener will receive.
callback ( client:Client, ...args:any[] ):void Function that receives the incomming message and arguments.

broadcast

Broadcasts a message to all connected ModuleClientAPI's.

api.broadcast(header, ...args);
Argument Type Description
header string The header of the message.
args any[] Data of any type.

registerWebhook

Register a webhook that can be called externally on address /:channelHostname/m/wh/:webhookId/:arg1?/:arg2?

api.registerWebhook(webhookId, callback);
Argument Type Description
webhookId string The ID the webhook will use.
callback (...args:any[] ):void Callback with arguments provided through the url.

Clients

getClients

Get all connected clients.

api.getClients(displays);
Argument Type Description
(Optional) displays string[] Array of displays to check, leave empty for all.

Returns { [clientId:string]:Client } Client list

getClient

Get a connected client.

api.getClient(clientId);
Argument Type Description
clientId string The id of the client.

Returns Client Client object

hasClient

Check if client is connceted.

api.hasClient(clientId);
Argument Type Description
clientId string The id of the client.

Returns boolean Client connected

onClientConnects

Assigns an event to be triggered when a new ModuleClientAPI connects.

api.onClientConnects(callback);
Argument Type Description
callback ( client:Client ):void Function will be called when a new ModuleClientAPI connects.

onClientDisconnects

Assigns an event to be triggered when a new ModuleClientAPI disconnects.

api.onClientDisconnects(callback);
Argument Type Description
callback ( client:Client ):void Function will be called when a new ModuleClientAPI disconnects.

Properties

onModulePropertyChange

Register a listener for when a module property changes. The listener will also be triggered on initial module creation and when the server starts up.

api.onModulePropertyChange(propertyId, callback);
Argument Type Description
propertyId string The property ID that the listener will receive.
callback ( property:Property ):void Function that receives the new property.

getModuleProperties

Get all properties of the module.

api.getModuleProperties();

Returns { [ propertyId:string ]: Property } All module properties

getModuleProperty

Get a property of the module.

api.getModuleProperty(propertyId);
Argument Type Description
propertyId string The id of the property you want to get.

Returns Property Module property

hasModuleProperty

Check if the module has a property.

api.hasModuleProperty(propertyId);
Argument Type Description
propertyId string The id of the property you want to check.

Returns boolean Has module property

onReferencePropertyChange

Register a listener for when a reference property changes.

api.onReferencePropertyChange(propertyId, callback);
Argument Type Description
propertyId string The property ID that the listener will receive.
callback ( sceneId:string, property:Property ):void Function that receives the new property.

getReferenceProperties

Get all module reference properties in a scene.

api.getReferenceProperties(sceneId);
Argument Type Description
sceneId string The id of the scene where you want to get the properties of.

Returns { [ propertyId:string ]: Property } All reference properties

getReferenceProperty

Get a module reference property in a scene.

api.getReferenceProperty(sceneId, propertyId);
Argument Type Description
sceneId string The id of the scene where you want to get the properties of.
propertyId string The id of the property you want to get.

Returns Property Reference property

hasReferenceProperty

Check if a module reference property exists in a scene.

api.hasReferenceProperty(sceneId, propertyId);
Argument Type Description
sceneId string The id of the scene where you want to get the properties of.
propertyId string The id of the property you want to check.

Returns boolean Has reference property

Modules

sendToModule

Send a message to another module within the channel.

api.sendToModule(moduleId, header, ...args);
Argument Type Description
module string The id of the module to send the message to.
header string The header of the message.
args any[] Additional arguments of the message.

receiveFromModule

Receive a message from another module within the channel.

api.receiveFromModule(header, callback);
Argument Type Description
header string The header of the messages to listen for.
callback ( moduleId:string, ...args:any[] ):void Callback when a message is received.

getChannelModules

Get all modules within the channel.

api.getChannelModules();

Returns {moduleId:string, type:string, name:string, moduleCommunicationHeaders:{header:string, arguments:number}}[] List of all modules

hasChannelModules

Check if a module exists within the channel.

api.hasChannelModules();

Returns boolean Module exists

Cues

finishServerCondition

Finish a server condition.

api.finishServerCondition(conditionId);
Argument Type Description
conditionId string The id of the condition.

forceClientCondition

Force a client condition.

api.forceClientCondition(conditionId);
Argument Type Description
conditionId string The id of the condition.

onTrigger

Register a listener for when a trigger is called from a cue list.

api.onTrigger(triggerId, callback);
Argument Type Description
triggerId string The trigger ID that the listener will receive.
callback ( finish:function, status: (text:string)=>void, ...args:any[] ):void Function will be called when the trigger is called from a cue list. The callback will receive the arguments in the same order they are defined in the module.json.

Scenes

getScenes

Get a list of all scenes this module is a part of.

api.getScenes();

Returns string[] List of scene IDs

getModuleScenes

Get a list of all scenes this module is in.

api.getModuleScenes();

Returns string[] List of scene IDs

onSceneChange

Register for a listener when the module is part of a scene change.

api.onSceneChange(callback);
Argument Type Description
callback ( displayId:string, origin:string, destination:string ):void Function will be called when a scene change occures.

Snapshots

onSnapshotRestore

Register a listener that will be called when a snapshot is recalled and the runtime storage is restored.

api.ononSnapshotRestore(callback);
Argument Type Description
callback Function Callback will be called when a snapshot is restored.

onSnapshotCreate

Register a listener that will be called before a snapshot is taken, this makes it possible to add variable to the storage before the snapshot happens.

api.onSnapshotCreate(callback);
Argument Type Description
callback Function Callback will be called before the snapshot is created.

getRuntimeStorage

Get the variable storage object.

api.getRuntimeStorage();

Returns RuntimeStorage The runtime storage object.

Last State

getLastState

Get the last state of the module. This is last version that has been edited, this is used for the default data for new reference of this modules.

api.getLastState();

Returns ModuleData The last state

setLastState

Set the last state of the module. This is used for the default data for new reference of this modules.

api.setLastState(state);
Argument Type Description
state ModuleData New laststate of the module.

Filesystem

readJSON

Read a file as JSON.

api.readJSON(scope, filename, callback);
Argument Type Description
scope 'static' | 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.
callback ( json:any ):void Function will be called with the JSON once it's loaded.

Returns Promise<any> Loaded JSON data

writeJSON

Write a file as JSON.

api.writeJSON(scope, filename, json, callback?);
Argument Type Description
scope 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.
json object The JSON data to write.
(Optional) callback function Function will be called with the JSON was saved.

Returns Promise<boolean> Write successful

readFile

Read a file.

api.readJSON(scope, filename, callback);
Argument Type Description
scope 'static' | 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.
callback ( json:any ):void Function will be called with the JSON once it's loaded.

Returns Promise<string> Loaded data

writeFile

Write a file.

api.writeFile(scope, filename, data, options, callback?);
Argument Type Description
scope 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.
data string | Buffer | TypedArray | DataView | Object The data to write. See fs.writeFile.
options Object | string Writing options/mode to use. See fs.writeFile.
(Optional) callback function Function will be called with the JSON was saved.

Returns Promise<boolean> Write successful

fileExists

Check if a file exists.

api.fileExists(scope, filename, callback);
Argument Type Description
scope 'static' | 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.
(Optional) callback ( exists:boolean ):void Function will be called when the file exists check has finished.

Return Promise<boolean> File exists

loadDatabase

Load a database into memory. Will create a new one if it does not exist yet.

api.loadDatabase(scope, filename, specification);
Argument Type Description
scope 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.
specification DatabaseSpecification Specification of the database.

Return Database Database instance

addHost

Make a file accessable through the webserver.

api.addHost(scope, filename);
Argument Type Description
scope 'module' | 'channel' | 'static' The scope of the file.
filename string The name of the file.

*Returns { hostID:string, relativeUrl:string, downloadUrl:string } The data of the hosted file.

removeHost

Remove a file that is currently hosted.

api.removeHost(hostId);
Argument Type Description
hostId string The host id of the hosted file you want to remove.

hasHost

Check if host ID is still being hosted.

api.hasHost(hostId);
Argument Type Description
hostId string The host id of the hosted file you want to check.

Returns boolean *Host ID is active.

onFileUpload

Register for a listener for when a file is uploaded through the module file upload route. To use this send a HTTP post with the files in formData as the body to http://serverIp:4080/:CHANNELNAME/upload/:MODULEID.

api.onFileUpload(callback);
Argument Type Description
callback ( files: { filename:string, originalFilename:string, byUser:string, size:number }[] ):void Function will be called when a file upload has finished.

Information

File Scopes

For every API call you make that uses the filesystem you have to specify a scope and a filename. The scope is used to differentiate between different locations the file can be in. Below is table with the scope's, their description and in which API calls they can be used.

Scope Description readJSON writeJSON writeFile fileExists addHost
static Target static files inside the build. See static files. x x x
module Target files that can only be accessed by a specific instance of this module. x x x x x
channel Target files that can accessed by all module of this type in the channel. x x x x x