Lifecycle
There are two types of communication available to you. Messages sent from the DashMon Player to your application and the vice-versa. A custom application lifecycle consists of IPC messages and the functions we created for you.
init - IPC Message
If a user’s playlist contains a content of your application, the DashMon Player boots up your app and sends the IPC message of type ‘init’.
process.on('message', async (data) => {
switch (data.type){
case 'init':
let {content, orientation, port, user} = data;
await init({content, orientation, port, user});
createServer({content, orientation, port, user});
break;
When received, boilerplate calls the method ‘Init’ to allow you to make your initializations.
After you make your initialization, createServer is called with data including port number.
init – function
Takes all the information sent from the DashMon Player as properties.
async function init({content, orientation, port, user}){
// Initialization
}
createServer – function
Creates a local server on port given by the DashMon Player.
You are free to add more endpoints to customize the behaviour of your application.
This method must call ready() function when it is successful. You shouldn’t remove this call to ready method or your app submission will be rejected.
function createServer({content, orientation, port, user}){
app.get('/', (req, res) => {
res.render('index', { title: 'DashMon Application', message: 'Sample App', content })
});
app.get('/info', (req, res) => {
res.send(content);
});
app.listen(port, () => {
log({message: `Listening on port ${port}`});
ready();
});
}
ready - function
Simply notifies DashMon Player that your application is ready to be used.
function ready(){
if(isDevMode) return;
process.send({type: 'isReady'});
}
display - IPC Message
When your app receives the display ipc message from the DashMon Player, it must call the display method with a URL property.
case 'display':
log({message: 'App received display'});
display({URL: `http://localhost:${_port}`});
break;
display - function
This method simply sends back a response to the display ipc message received from the DashMon Player.
It sends the URL of the local server to display your html file on the DashMon Player.
function display({URL}){
if(isDevMode) return;
log({message: 'display sent back with path: ' + URL});
process.send({type: 'display', path: URL});
}
log - function
Allows you to send logs to the DashMon Player.
It is advised to use this at specific points to let our tech team know about what’s going wrong in case of a bug/issue.
function log({message}){
if(isDevMode) return console.log(message);
process.send({type: 'log', message});
}
update – function
The only difference between calling the update function and the display function is that the display should be called only when the DashMon Player requests it.
The ‘update’ function allows you to send another URL information to the DashMon Player without a request.
As long as your content is on the screen, URL sent by ‘update’ will be shown on the screen.
function update({URL}){
if(isDevMode) return;
process.send({type: 'update', path: URL});
}
error - function
You should call this function when an exception happens on your code so the DashMon Player can handle accordingly.
function error({message}){
if(isDevMode) return;
process.send({type: 'error', message});
}