From 506c7ad9f7d2396290ff9ae0bc2edcb8dc9d4e97 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 12 Mar 2015 14:54:52 -0400 Subject: [PATCH] Streaming stuff... rewrite this message --- 2015/assets/js/stream.js | 87 ++++++++++++++++++++++++++++++++++++++++ 2015/live/room123.html | 25 +++++++----- 2 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 2015/assets/js/stream.js diff --git a/2015/assets/js/stream.js b/2015/assets/js/stream.js new file mode 100644 index 00000000..06db08f9 --- /dev/null +++ b/2015/assets/js/stream.js @@ -0,0 +1,87 @@ +/** + * @licstart The following is the entire license notice for the JavaScript code in this page. + * + * IceCast Stream Monitor + * Copyright © 2015 David Thompson + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * . + * + * @licend The above is the entire license notice for the JavaScript code in this page + */ + +/** + * Call a function with the statistics from an IceCast mount. + */ +function withStreamStats(serverUrl, mount, callback) { + var statsUrl = serverUrl.concat('/status-json.xsl'); + + return $.ajax({ + url: statsUrl, + type: 'GET', + crossDomain: true, + success: function(data) { + // Match the end of the listen URL for the mount point. + var regexp = new RegExp(mount.concat('$')); + + // Due to , we must + // explicitly test if icestats.source is an array. + if(!data.icestats.source.isArray()) { + data.icestats.source = [data.icestats.source]; + } + + var stats = data.icestats.source.find(function(source) { + return regexp.test(source.listenurl); + }); + + if(stats) { + callback(stats); + } + } + }); +} + +/** + * Schedule a thunk... forever! + */ +function scheduleEvery(duration, thunk) { + thunk(); + setTimeout(function() { + scheduleEvery(duration, thunk); + }, duration); +} + +/** + * Update the document with stats from an IceCast mount. + */ +function renderStreamStats(stats) { + function viewCountMessage(viewers) { + var noun = viewers === 1 ? 'viewer' : 'viewers'; + return [viewers.toString(), noun].join(' '); + } + + $('#viewer-counter').html(viewCountMessage(stats.listeners)); + $('#speaker-name').html(stats.server_name); + $('#talk-title').html(stats.server_description); +} + +/** + * Update the document every 10 seconds with stats from an IceCast + * mount. + */ +function monitorStream(mount) { + scheduleEvery(10000, function() { + withStreamStats('http://live.fsf.org', mount, renderStreamStats); + }); +} diff --git a/2015/live/room123.html b/2015/live/room123.html index d3e0be86..e158bc2e 100755 --- a/2015/live/room123.html +++ b/2015/live/room123.html @@ -7,18 +7,19 @@

Room 123

+

Now presenting: - ""

+

+
-
- -
+
+ +
@@ -49,7 +50,9 @@ + -- 2.25.1