welsonjs/defaultService.example.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

// defaultService.example.js
// https://github.com/gnh1201/welsonjs
var SYS = require("lib/system");
2024-10-14 18:00:06 +00:00
// Examples of class (prototype) and instance referencing .env values
function examplePrototype() {
this.env = {};
this.setEnv = function(k, v) {
this.env[k] = v;
};
}
var exampleInstance = new examplePrototype();
2024-10-13 19:52:22 +00:00
function main(args) {
console.log("WelsonJS.Service required.");
}
function getDeviceID() {
return SYS.getUUID();
}
2024-09-20 01:56:28 +00:00
function onServiceStart(args) {
2024-10-13 19:52:22 +00:00
// load the environment file
FILE.loadEnvFromArgs(args, function(envConfig) {
2024-10-14 18:00:06 +00:00
// In Node.js and recent JavaScript engines, it is common to assign .env values globally, such as with `process.env`.
// However, WelsonJS is designed to limit the scope to specific areas.
for (var envKey in envConfig) {
exampleInstance.setEnv(envKey, envConfig[envKey]);
2024-10-13 19:52:22 +00:00
}
});
2024-10-14 18:00:06 +00:00
return "onServiceStart recevied. " + args.join(', ') + ", env: " + JSON.stringify(exampleInstance.env);
}
function onServiceStop() {
return "onServiceStop recevied";
}
function onServiceElapsedTime() {
return "onServiceElapsedTime recevied";
}
function onMessageReceived() {
2024-08-25 06:28:03 +00:00
return "onMessageReceived recevied. " + args.join(', ');
2024-08-20 04:42:44 +00:00
}
function onScreenNextTemplate(args) {
return "example.png";
}
function onScreenTemplateMatched(args) {
return "onScreenTemplateMatched recevied. " + args.join(', ');
2024-07-29 12:43:14 +00:00
}
function onFileCreated(args) {
2024-08-13 08:05:48 +00:00
return "onFileCreated recevied. " + args.join(', ');
}
2024-09-09 07:47:51 +00:00
function onNetworkConnected(args) {
return "onNetworkConnected recevied. " + args.join(', ');
2024-08-13 08:05:48 +00:00
}
2024-09-09 08:09:31 +00:00
function onRegistryModified(args) {
return "onRegistryModified recevied. " + args.join(', ');
}
function onAvScanResult(args) {
return "onAvScanResult recevied. " + args.join(', ');
}
2024-09-09 08:09:31 +00:00
exports.main = main;
2024-08-20 04:42:44 +00:00
exports.getDeviceID = getDeviceID;
exports.onServiceStart = onServiceStart;
exports.onServiceStop = onServiceStop;
exports.onServiceElapsedTime = onServiceElapsedTime;
exports.onScreenNextTemplate = onScreenNextTemplate;
exports.onScreenTemplateMatched = onScreenTemplateMatched;
2024-08-13 08:05:48 +00:00
exports.onFileCreated = onFileCreated;
2024-09-09 07:47:51 +00:00
exports.onNetworkConnected = onNetworkConnected;
2024-09-09 08:09:31 +00:00
exports.onRegistryModified = onRegistryModified;
exports.onAvScanResult = onAvScanResult;