btnexus-node
Version:
Baseline libary for btNexus development.
51 lines (42 loc) • 1.15 kB
JavaScript
/**
* Ophion Cloud Blackout Protocol message
*
* @author Marc Fiedler
* @copyright 2020 Blackout Technologies, all rights reserved, all rights reserved
*/
"use_strict";
const uniqid = require('uniqid');
const os = require('os');
module.exports = class Message {
constructor(intent) {
this.data = {};
this.protocolVersion = "5.0";
if( intent != undefined ){
// build a standadized header
this.data = {
api: {
version: this.protocolVersion,
intent: intent,
time: new Date().getTime(),
id: uniqid()
},
host: os.hostname()
}
}
}
updateIntent(intent){
if( this.data.api != undefined ){
this.data.api.intent = intent;
}
}
parse(data){
this.data = JSON.parse(data);
if( this.data.api.id == undefined ){
// not all clients support unique ID's
this.data.api.id = uniqid();
}
}
toString(){
return JSON.stringify(this.data);
}
}