forked from ferferga/MMM-GoogleCast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
47 lines (42 loc) · 1.96 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const NodeHelper = require('node_helper');
const PythonShell = require('python-shell');
var pythonStarted = false
module.exports = NodeHelper.create({
python_start: function () {
const self = this;
const pyshell = new PythonShell("modules/" + this.name + '/lib/Cast.py', { mode: 'json', args: [JSON.stringify(this.config)], pythonPath: 'python3'});
pyshell.on('message', function (message) {
if (message.hasOwnProperty('deviceStatus'))
{
self.sendSocketNotification('deviceStatus', {type: "deviceStatus", id: message.deviceStatus.id, app: message.deviceStatus.app, volume: message.deviceStatus.volume})
}
if (message.hasOwnProperty('mediaStatus'))
{
self.sendSocketNotification('mediaStatus', {type: "mediaStatus", id: message.mediaStatus.id, albumArtist: message.mediaStatus.albumArtist, image: message.mediaStatus.image,
title: message.mediaStatus.title, state: message.mediaStatus.state, album: message.mediaStatus.album, artist: message.mediaStatus.artist});
}
if (message.hasOwnProperty('status'))
{
self.sendSocketNotification('status', {type: "status", message: message.status})
}
if (message.hasOwnProperty('importError'))
{
self.sendSocketNotification('importError', {type: "importError"})
console.log("[" + self.name + "] Error while loading MMM-GoogleCast. The environment was not set up correctly")
}
console.log("[" + self.name + "] Update received! Details:\n", message)
});
pyshell.end(function (err) {
if (err) throw err;
console.log("[" + self.name + "] " + 'finished running...');
self.sendSocketNotification('status', {type: "status", message: "error"})
});
},
socketNotificationReceived: function(notification, payload) {
if(notification === 'CONFIG') {
this.config = payload
this.python_start();
};
}
});