2024-09-20 02:50:29 +00:00
|
|
|
// defaultService.example.js
|
|
|
|
// https://github.com/gnh1201/welsonjs
|
2024-09-09 07:42:48 +00:00
|
|
|
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
|
|
|
|
2024-07-23 04:13:33 +00:00
|
|
|
function main(args) {
|
|
|
|
console.log("WelsonJS.Service required.");
|
|
|
|
}
|
2024-09-09 07:42:48 +00:00
|
|
|
|
|
|
|
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);
|
2024-07-23 04:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onServiceStop() {
|
|
|
|
return "onServiceStop recevied";
|
|
|
|
}
|
|
|
|
|
|
|
|
function onServiceElapsedTime() {
|
|
|
|
return "onServiceElapsedTime recevied";
|
|
|
|
}
|
|
|
|
|
2024-08-25 14:21:58 +00:00
|
|
|
function onMessageReceived() {
|
2024-08-25 06:28:03 +00:00
|
|
|
return "onMessageReceived recevied. " + args.join(', ');
|
2024-08-20 04:42:44 +00:00
|
|
|
}
|
|
|
|
|
2024-09-20 07:53:50 +00:00
|
|
|
function onScreenNextTemplate(args) {
|
|
|
|
return "example.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
function onScreenTemplateMatched(args) {
|
|
|
|
return "onScreenTemplateMatched recevied. " + args.join(', ');
|
2024-07-29 12:43:14 +00:00
|
|
|
}
|
|
|
|
|
2024-08-25 14:21:58 +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(', ');
|
|
|
|
}
|
|
|
|
|
2024-09-14 17:54:18 +00:00
|
|
|
function onAvScanResult(args) {
|
|
|
|
return "onAvScanResult recevied. " + args.join(', ');
|
|
|
|
}
|
2024-09-09 08:09:31 +00:00
|
|
|
|
2024-07-23 04:13:33 +00:00
|
|
|
exports.main = main;
|
2024-08-20 04:42:44 +00:00
|
|
|
exports.getDeviceID = getDeviceID;
|
2024-07-23 04:13:33 +00:00
|
|
|
exports.onServiceStart = onServiceStart;
|
|
|
|
exports.onServiceStop = onServiceStop;
|
|
|
|
exports.onServiceElapsedTime = onServiceElapsedTime;
|
2024-09-20 07:53:50 +00:00
|
|
|
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;
|
2024-09-14 17:54:18 +00:00
|
|
|
exports.onAvScanResult = onAvScanResult;
|