Skip to content

Commit

Permalink
Adds error logging to stream parser
Browse files Browse the repository at this point in the history
  • Loading branch information
J909 committed Nov 28, 2018
1 parent c856851 commit c70d31d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions radio-blaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const moment = require('moment');
const RadioParser = require('icecast-parser');
var cloneDeep = require('lodash.clonedeep');
const cloneDeep = require('lodash.clonedeep');

var radioblaster = {};
let radioblaster = {};

const radioParser = new RadioParser({
url: process.env.RADIO_STREAM_URL,
Expand All @@ -15,16 +15,19 @@ const radioParser = new RadioParser({
metadataInterval: 5 // update metadata after 5 seconds
});

var currentMeta = {};
let currentMeta = {};

radioblaster.start = function() {
var currentTitle;
let currentTitle;
radioParser.on('metadata', function(metadata) {
if (currentTitle !== metadata.StreamTitle) {
currentTitle = metadata.StreamTitle;
updateCurrentMeta(currentTitle);
}
});
radioParser.on('error', function(error) {
log(error);
});
}

radioblaster.getStreamUrl = function() {
Expand All @@ -50,13 +53,13 @@ function updateCurrentMeta(currentTitle) {
}

function logMeta(meta) {
var time = new moment().format("HH:mm:ss");
let time = new moment().format("HH:mm:ss");
console.log(time + ': Artist=' + meta['artist'] + ' Title=' + meta['title']);
}

function log(message) {
var time = new moment().format("HH:mm:ss");
console.log(time + ': ' + message);
let time = new moment().format("HH:mm:ss");
console.log(time + ': ', message);
}

function logBlip() {
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const app = express();
radioBlaster.start();

app.get('/', (req, res) => {
var metadata = radioBlaster.getCurrentMeta();
let metadata = radioBlaster.getCurrentMeta();
res.send('<b>RadioBlaster</b> is listening...<br>'
+ 'Artist: ' + metadata.artist + '<br>'
+ 'Title: ' + metadata.title + '<br>');
Expand Down

0 comments on commit c70d31d

Please sign in to comment.