From cbe8f98a7c19c7e84e5737d3a97e404898dd8fd9 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 22 Mar 2011 01:29:23 -0400 Subject: [PATCH] CC-1990: Widget to display schedule and "Now Playing" on any website -initial checkin, some hardcoded values --- application/controllers/ApiController.php | 13 ++ plugins/jquery.showinfo.js | 214 ++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 plugins/jquery.showinfo.js diff --git a/application/controllers/ApiController.php b/application/controllers/ApiController.php index aa4696f89..1ef0d1155 100644 --- a/application/controllers/ApiController.php +++ b/application/controllers/ApiController.php @@ -101,6 +101,19 @@ class ApiController extends Zend_Controller_Action exit; } + public function liveInfoAction(){ + global $CC_CONFIG; + + // disable the view and the layout + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $result = Schedule::GetPlayOrderRange(0, 1); + //echo json_encode($result); + header("Content-type: text/javascript"); + echo $_GET['callback'].'('.json_encode($result).')'; + } + public function scheduleAction() { global $CC_CONFIG; diff --git a/plugins/jquery.showinfo.js b/plugins/jquery.showinfo.js new file mode 100644 index 000000000..da5be1af8 --- /dev/null +++ b/plugins/jquery.showinfo.js @@ -0,0 +1,214 @@ +(function($){ + $.fn.airtimeShowSchedule = function(options) { + + var defaults = { + updatePeriod: 5, //seconds + }; + var options = $.extend(defaults, options); + + return this.each(function() { + var obj = $(this); + + obj.append("

On air today

"); + obj.append( + ""+ + "" + + "" + + "" + + ""+ + ""+ + ""+ + ""+ + ""+ + "
13:15 - 13:30Program name Listen
13:15 - 13:30Lorem ipsum dolor
"); + }); + }; +})(jQuery); + + +(function($){ + $.fn.airtimeLiveInfo = function(options) { + + var defaults = { + updatePeriod: 5, //seconds + sourceDomain: "http://localhost/", //where to get show status from + audioStreamSource: "" //where to get audio stream from + }; + var options = $.extend(defaults, options); + + return this.each(function() { + var obj = $(this); + var sd; + getServerData(); + + function updateWidget(){ + var currentShow = sd.getCurrentShowName(); + var timeRemaining = sd.getCurrentShowTimeRemaining(); + var timeElapsed = sd.getCurrentShowTimeElapsed(); + var showStatus = sd.getCurrentShowStatus(); + + var nextShow = sd.getNextShowName(); + var nextShowRange = sd.getNextShowRange(); + + obj.empty(); + obj.append("Listen WADR Live"); + obj.append("

"+showStatus+" >>

"); + obj.append(""); + + //refresh the UI + setTimeout(updateWidget, 1000); + } + + function processData(data){ + sd = new ScheduleData(data); + updateWidget(); + } + + function getServerData(){ + $.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){ + processData(data); + }, error:function(jqXHR, textStatus, errorThrown){}}); + setTimeout(getServerData, defaults.updatePeriod*1000); + } + }); + }; +})(jQuery); + +/* The rest of this file is the ScheduleData class */ +function ScheduleData(data){ + this.data = data; + this.estimatedSchedulePosixTime; + + this.schedulePosixTime = this.convertDateToPosixTime(data.schedulerTime); + this.schedulePosixTime += parseInt(data.timezoneOffset)*1000; + var date = new Date(); + this.localRemoteTimeOffset = date.getTime() - this.schedulePosixTime; +} + + +ScheduleData.prototype.secondsTimer = function(){ + var date = new Date(); + this.estimatedSchedulePosixTime = date.getTime() - this.localRemoteTimeOffset; +} + +ScheduleData.prototype.getCurrentShowName = function() { + var currentShow = this.data.currentShow; + if (currentShow.length > 0){ + return "Current: " + currentShow[0].name; + } else { + return ""; + } +}; + +ScheduleData.prototype.getCurrentShowStatus = function() { + var currentShow = this.data.currentShow; + if (currentShow.length > 0){ + return "On Air Now"; + } else { + return "Offline"; + } +}; + +ScheduleData.prototype.getNextShowName = function() { + var nextShow = this.data.nextShow; + if (nextShow.length > 0){ + return "Next: " + nextShow[0].name; + } else { + return ""; + } +}; + +ScheduleData.prototype.getNextShowRange = function() { + var nextShow = this.data.nextShow; + if (nextShow.length > 0){ + return this.getTime(nextShow[0].start_timestamp) + " - " + this.getTime(nextShow[0].end_timestamp); + } else { + return ""; + } +}; + +ScheduleData.prototype.getCurrentShowTimeElapsed = function() { + this.secondsTimer(); + var currentShow = this.data.currentShow; + if (currentShow.length > 0){ + var showStart = this.convertDateToPosixTime(currentShow[0].start_timestamp); + return this.convertToHHMMSS(this.estimatedSchedulePosixTime - showStart); + } else { + return ""; + } +}; + +ScheduleData.prototype.getCurrentShowTimeRemaining = function() { + this.secondsTimer(); + var currentShow = this.data.currentShow; + if (currentShow.length > 0){ + var showEnd = this.convertDateToPosixTime(currentShow[0].end_timestamp); + return this.convertToHHMMSS(showEnd - this.estimatedSchedulePosixTime); + } else { + return ""; + } +}; + +ScheduleData.prototype.getTime = function(timestamp) { + return timestamp.split(" ")[1]; +}; + + +/* Takes an input parameter of milliseconds and converts these into + * the format HH:MM:SS */ +ScheduleData.prototype.convertToHHMMSS = function(timeInMS){ + var time = parseInt(timeInMS); + + var hours = parseInt(time / 3600000); + time -= 3600000*hours; + + var minutes = parseInt(time / 60000); + time -= 60000*minutes; + + var seconds = parseInt(time / 1000); + + hours = hours.toString(); + minutes = minutes.toString(); + seconds = seconds.toString(); + + if (hours.length == 1) + hours = "0" + hours; + if (minutes.length == 1) + minutes = "0" + minutes; + if (seconds.length == 1) + seconds = "0" + seconds; + if (hours == "00") + return minutes + ":" + seconds; + else + return hours + ":" + minutes + ":" + seconds; +} + +/* Takes in a string of format similar to 2011-02-07 02:59:57, + * and converts this to epoch/posix time. */ +ScheduleData.prototype.convertDateToPosixTime = function(s){ + var datetime = s.split(" "); + + var date = datetime[0].split("-"); + var time = datetime[1].split(":"); + + var year = date[0]; + var month = date[1]; + var day = date[2]; + var hour = time[0]; + var minute = time[1]; + var sec = 0; + var msec = 0; + + if (time[2].indexOf(".") != -1){ + var temp = time[2].split("."); + sec = temp[0]; + msec = temp[1]; + } else + sec = time[2]; + + return Date.UTC(year, month, day, hour, minute, sec, msec); +}