-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-MTA.js
66 lines (52 loc) · 1.47 KB
/
MMM-MTA.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
/* global Module */
/* Magic Mirror
* Module: MMM-MTA
*
* By Nicholas Konecny
* MIT Licensed.
*/
Module.register('MMM-MTA', {
start: function() {
this.linesData = [];
this.nextTrainData = [];
this.lastUpdated = 'Loading...';
this.getStatus(this);
},
getStyles: function() {
return ['MTA.css', 'moment.js'];
},
getStatus: function(self) {
self.sendSocketNotification('GET_MTA_STATUS', self.config);
},
getScripts: function() {
return [this.file('public/mta-view.js'), this.file('public/mta-helper.js')];
},
getDom: function() {
const view = document.createElement('div');
view.className = 'medium mta-container';
const mtaView = new MtaView(this.linesData, this.lastUpdated, this.config);
view.appendChild(mtaView.build(this.nextTrainData));
return view;
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'LINE_DATA') {
this.linesData = payload.data;
this.lastUpdated = payload.updated;
this.updateDom();
}
if (notification === 'NEXT_TRAIN_DATA') {
this.mtaRealtime.updateTrains(payload);
}
if (notification === 'UPDATE_CLOCK') {
var minutes = payload.data.minutes;
var seconds = payload.data.seconds;
if (minutes < 10) {
minutes = `0${minutes}`;
}
if (seconds < 10) {
seconds = `0${seconds}`;
}
var formattedTime = moment.unix(payload.time).format('hh:mm:ss a');
}
},
});