-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
node_helper.js
43 lines (34 loc) · 1.09 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
/* MagicMirror²
* Module: MMM-OlympicGames
*
* By fewieden https://github.com/fewieden/MMM-OlympicGames
* MIT Licensed.
*/
/* eslint-env node */
const NodeHelper = require('node_helper');
const Log = require('logger');
const providers = require('./providers');
module.exports = NodeHelper.create({
requiresVersion: '2.15.0',
socketNotificationReceived(notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
this.getCountryMedals();
setInterval(() => {
this.getCountryMedals();
}, this.config.reloadInterval);
}
},
async getCountryMedals() {
try {
const provider = providers[this.config.provider];
if (!provider) {
throw new Error(`Unsupported provider: ${this.config.provider}`);
}
const countries = await provider.getCountryMedals();
this.sendSocketNotification('COUNTRIES', countries);
} catch (e) {
Log.error('Error getting olympic game medals', e);
}
}
});