mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Configurable encoding. #126
This commit is contained in:
@@ -70,6 +70,13 @@ The following properties can be configured:
|
|||||||
<br><b>Default value:</b> <code>2000</code> (2.5 seconds)
|
<br><b>Default value:</b> <code>2000</code> (2.5 seconds)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>encoding</code></td>
|
||||||
|
<td>The encoding of the news feed.<br>
|
||||||
|
<br><b>Possible values:</b><code>'UTF-8'</code>, <code>'ISO-8859-1'</code>, etc ...
|
||||||
|
<br><b>Default value:</b> <code>'UTF-8'</code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@@ -14,7 +14,7 @@ var NewsFetcher = require('./newsfetcher.js');
|
|||||||
* attribute reloadInterval number - Reload interval in milliseconds.
|
* attribute reloadInterval number - Reload interval in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Fetcher = function(url, reloadInterval) {
|
var Fetcher = function(url, reloadInterval, encoding) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var newsFetcher = new NewsFetcher();
|
var newsFetcher = new NewsFetcher();
|
||||||
if (reloadInterval < 1000) {
|
if (reloadInterval < 1000) {
|
||||||
@@ -44,7 +44,7 @@ var Fetcher = function(url, reloadInterval) {
|
|||||||
}, function(error) {
|
}, function(error) {
|
||||||
fetchFailedCallback(self, error);
|
fetchFailedCallback(self, error);
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
});
|
}, encoding);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* scheduleTimer()
|
/* scheduleTimer()
|
||||||
|
@@ -16,6 +16,7 @@ Module.register('newsfeed',{
|
|||||||
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
||||||
updateInterval: 7.5 * 1000,
|
updateInterval: 7.5 * 1000,
|
||||||
animationSpeed: 2.5 * 1000,
|
animationSpeed: 2.5 * 1000,
|
||||||
|
encoding: 'UTF-8' //ISO-8859-1
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
@@ -56,6 +57,13 @@ Module.register('newsfeed',{
|
|||||||
getDom: function() {
|
getDom: function() {
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
|
|
||||||
|
// wrapper.className = "small";
|
||||||
|
// for (var n in this.newsItems) {
|
||||||
|
// var item = this.newsItems[n];
|
||||||
|
// wrapper.innerHTML += item.title + '<br>';
|
||||||
|
// }
|
||||||
|
// return wrapper;
|
||||||
|
|
||||||
if (this.activeItem >= this.newsItems.length) {
|
if (this.activeItem >= this.newsItems.length) {
|
||||||
this.activeItem = 0;
|
this.activeItem = 0;
|
||||||
}
|
}
|
||||||
@@ -90,7 +98,8 @@ Module.register('newsfeed',{
|
|||||||
Log.log('Add news feed to fetcher: ' + this.config.feedUrl);
|
Log.log('Add news feed to fetcher: ' + this.config.feedUrl);
|
||||||
this.sendSocketNotification('ADD_FEED', {
|
this.sendSocketNotification('ADD_FEED', {
|
||||||
url: this.config.feedUrl,
|
url: this.config.feedUrl,
|
||||||
reloadInterval: this.config.reloadInterval
|
reloadInterval: this.config.reloadInterval,
|
||||||
|
encoding: this.config.encoding
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -43,10 +43,10 @@ var NewsFetcher = function() {
|
|||||||
* attribute success function(items) - Callback on succes.
|
* attribute success function(items) - Callback on succes.
|
||||||
* attribute error function(error) - Callback on error.
|
* attribute error function(error) - Callback on error.
|
||||||
*/
|
*/
|
||||||
self.fetchNews = function(url, success, error) {
|
self.fetchNews = function(url, success, error, encoding) {
|
||||||
self.successCallback = success;
|
self.successCallback = success;
|
||||||
self.errorCallback = error;
|
self.errorCallback = error;
|
||||||
request({uri:url, encoding:null}).pipe(iconv.decodeStream('ISO-8859-1')).pipe(parser);
|
request({uri:url, encoding:null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ module.exports = NodeHelper.create({
|
|||||||
// Subclass socketNotificationReceived received.
|
// Subclass socketNotificationReceived received.
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
if(notification === 'ADD_FEED') {
|
if(notification === 'ADD_FEED') {
|
||||||
this.createFetcher(payload.url, payload.reloadInterval);
|
this.createFetcher(payload.url, payload.reloadInterval, payload.encoding);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ module.exports = NodeHelper.create({
|
|||||||
* attribute reloadInterval number - Reload interval in milliseconds.
|
* attribute reloadInterval number - Reload interval in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
createFetcher: function(url, reloadInterval) {
|
createFetcher: function(url, reloadInterval, encoding) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!validUrl.isUri(url)){
|
if (!validUrl.isUri(url)){
|
||||||
@@ -43,7 +43,7 @@ module.exports = NodeHelper.create({
|
|||||||
var fetcher;
|
var fetcher;
|
||||||
if (typeof self.fetchers[url] === 'undefined') {
|
if (typeof self.fetchers[url] === 'undefined') {
|
||||||
console.log('Create new news fetcher for url: ' + url + ' - Interval: ' + reloadInterval);
|
console.log('Create new news fetcher for url: ' + url + ' - Interval: ' + reloadInterval);
|
||||||
fetcher = new Fetcher(url, reloadInterval);
|
fetcher = new Fetcher(url, reloadInterval, encoding);
|
||||||
|
|
||||||
fetcher.onReceive(function(fetcher) {
|
fetcher.onReceive(function(fetcher) {
|
||||||
self.sendSocketNotification('NEWS_ITEMS', {
|
self.sendSocketNotification('NEWS_ITEMS', {
|
||||||
|
Reference in New Issue
Block a user