forked from Leyo98765/ControllerNRJ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
131 lines (94 loc) · 2.97 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const libQ = require('kew');
const libFast = require('fast.js');
const fs = require('fs-extra');
const path = require('path');
const exec = require('child_process').exec;
const musicLibrary = '/mnt/USB';
module.exports = oled1;
function oled(context) {
const self = this;
self.context = context;
self.commandRouter = self.context.coreCommand;
self.logger = self.context.logger;
self.configManager = self.context.configManager;
}
oled1.prototype.onVolumioStart = function() {
const self = this;
self.configFile = self.commandRouter.pluginManager.getConfigurationFile(self.context, 'config.json');
self.getConf(self.configFile);
return libQ.resolve();
}
oled1.prototype.onStart = function() {
const self = this;
const defer = libQ.defer();
// Start the radio
self.startRadio();
// Set the OLED display to show the name of the currently playing track
self.setOledDisplay('Now Playing', 'NRJ');
// Resolve the promise
defer.resolve();
return defer.promise;
};
oled1.prototype.onStop = function() {
const self = this;
const defer=libQ.defer();
// Once the Plugin has successfull stopped resolve the promise
defer.resolve();
return libQ.resolve();
};
oled1.prototype.startRadio = function () {
const self = this;
// Get the radio URL from the plugin's configuration file
const radioUrl = 'https://www.nrj.fr/webradios';
// Launch the radio using the mplayer command
exec('mplayer -ao alsa:device=hw=1.0 ' + radioUrl, (error, stdout, stderr) => {
if (error) {
self.logger.error('Failed to start radio: ' + error);
}
});
};
oled1.prototype.setOledDisplay = function (line1, line2) {
const self = this;
// Use the oled1 plugin to set the OLED display text
self.commandRouter.executeOnPlugin('system_controller', 'oled1', 'write', [line1, line2]);
};
oled1.prototype.getConf = function (configFile) {
const self = this;
self.config = new (require('v-conf'))();
self.config.loadFile(configFile);
};
oled1.prototype.saveConf = function () {
const self = this;
self.commandRouter.pluginManager.savePluginConfiguration('radio', self.config.get(), function (err, data) {
if (err) {
self.logger.error('Error saving configuration: ' + err);
}
});
};
oled1.prototype.getUIConfig = function () {
const defer = libQ.defer();
const self = this;
const lang_code = self.commandRouter.sharedVars.get('language_code');
const configFile = self.commandRouter.pluginManager.getConfigurationFile(self.context, 'config.json');
const config = {
page: {
title: 'Radio Plugin Settings',
plugin: 'radio'
},
sections: []
};
defer.resolve(config);
return defer.promise;
};
oled1.prototype.setUIConfig = function (data) {
const self = this;
self.logger.info('Received UIConfig:', data);
};
oled1.prototype.getConfigurationFiles = function () {
return ['config.json'];
};
oled1.prototype.addToBrowseSources = function () {
const self = this;
return self.commandRouter.v
}