-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-Bose-Soundtouch.js
137 lines (131 loc) · 4.94 KB
/
MMM-Bose-Soundtouch.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
130
131
132
133
134
135
136
137
/* Magic Mirror
* Module: MagicMirror-Bose-Soundtouch
*
* By SpoturDeal https://github.com/SpoturDeal
* updated by MartinKooij 2021 (list of bose speakers)
* MIT Licensed.
*/
Module.register('MMM-Bose-Soundtouch', {
defaults: {
updateInterval: 10, // every 5 seconds
apiBase: '192.168.xxx.xxx', // the IPaddress(es) of the Bose Soundtouch in your home network
hideImage: false,
},
start: function() {
Log.info('Starting module: ' + this.name);
this.sendSocketNotification('BOSE_READ',
{
boselist: this.config.apiBase,
interval: this.config.updateInterval * 1000
}
);
},
render: function(data){
var json=xml2json(data);
var music = json.nowPlaying;
if (this.config.hideImage === false ){
var sArt = $(data).find('art').text().trim();
var htmlImage='<img src="' + sArt + '"/>';
} else {
var sArt = false;
var htmlImage='';
}
//var sArt = $(data).find('art').text().trim();
var sTitle='';
var sAlbum = '';
var lenAlbum=30;
var showMusic = false;
if (music.source == "SPOTIFY"){
sTitle = '<i class="fa fa-spotify" style="color:#1ED760;"></i> ' + music.ContentItem.itemName;
showMusic = true;
sAlbum=music.album;
} else if (music.source == "AMAZON" || music.source == "ALEXA"){
sTitle = '<i class="fa fa-amazon" style="color:#232F3E;"></i> ' + music.ContentItem.itemName;
showMusic = true;
sAlbum=music.album;
} else if (music.source == "DEEZER" || music.source == "ITUNES" || music.source == "TUNEIN" || music.source == "PRODUCT" || music.source == "AIRPLAY"){
sTitle = '<i class="fa fa-music" style="color:#FFFFFF;"></i> ' + music.ContentItem.itemName;
showMusic = true;
sAlbum=music.album;
} else if (music.source == "INTERNET_RADIO"){
sTitle = "Internet radio ";
showMusic = true;
sAlbum = music.stationName;
} else if (music.source == "BLUETOOTH"){
sTitle = music.ContentItem.itemName;
showMusic = true;
sAlbum = music.album;
sArt = true ;
htmlImage='<img src="https://cdn.osxdaily.com/wp-content/uploads/2013/12/bluetooth-icon.png" width="100" height="100" />' ;
}
else if (music.source == "STANDBY"|| music.source == "INVALID_SOURCE"){
sTitle ='<i class="fa fa-spotify"></i> stand by';
} else if (music.source == "STORED_MUSIC"){
sTitle = '<i class="fa fa-music"></i> Soundtouch ';
showMusic = true;
sAlbum = false;
} else if (music.source == "AUX"){
sTitle = "AUX Input ";
sAlbum = "Playing from aux input.";
showMusic = true;
} else {
sTitle = "Soundtouch - Your help is needed";
sAlbum = "Please send me a message with the contents of<br>http:/" + this.config.apiBase + ':8090/now_playing<br>I can add the unknown service.';
showMusic = false;
lenAlbum=150;
}
var text = '<div>';
text +='<header class="module-header">' + sTitle + '</header>';
text +='<table>';
text +='<tr><td class="small">' + (music.track?this.maxSize(music.track,30):'') + '</td><td class="small"><i class="fa fa-music"></i><td></td><td class="small" rowspan="3">' + (sArt?htmlImage:'') + '</td></tr>'
text += (music.artist?'<tr><td class="small">' + this.maxSize(music.artist,30) + '</td><td class="small"><i class="fa fa-user-o"></i></td></tr>':'');
text += (sAlbum?'<tr><td class="small">' + this.maxSize(sAlbum,lenAlbum) + '</td><td class="small"><i class="fa fa-file-audio-o"></i></td></tr>':'');
text += '</table></div>';
// if no source found show nothing
if (showMusic===false) {
text=' ';
}
this.loaded = true;
// only update dom if content changed
if(this.dom !== text){
this.dom = text;
this.updateDom(this.config.animationSpeed);
}
},
html: {
loading: '<div class="dimmed light small"></div>'
},
getScripts: function() {
return [
'String.format.js',
'xml2json.js',
'//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js'
];
},
getStyles: function() {
return ['bose.css'];
},
maxSize: function(sTr,len){
if(sTr.length > len) {
sTr = sTr.substring(0,len-1)+"...";
}
return sTr;
},
getDom: function() {
var content = '';
if (!this.loaded) {
content = this.html.loading;
}else if(this.data.position.endsWith("left")){
content = '<ul class="flip">'+this.dom+'</ul>';
}else{
content = '<ul>'+this.dom+'</ul>';
}
return $('<div class="bose">'+content+'</div>')[0];
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'BOSE_DATA') {
console.log('received BOSE_DATA');
this.render(payload);
}
}
});