* session broadcast widget working decently well

This commit is contained in:
Seth Call 2014-02-28 02:50:17 +00:00
parent 51f955fc74
commit 56ce4c9fe8
4 changed files with 51 additions and 4 deletions

View File

@ -3,6 +3,7 @@
"use strict";
context.JK = context.JK || {};
context.JK.FeedItemSessionTimer = null;
context.JK.FeedItemSession = function($parentElement, options){
var logger = context.JK.logger;
@ -135,6 +136,11 @@
$status.text('SERVER ERROR');
stopPlay();
}
else if(state == 'concurrent_stop') {
console.log("CONCURRENT STOP")
$status.text('SESSION IN PROGRESS');
stopPlay();
}
else {
logger.error("unknown state: " + state)
}
@ -158,6 +164,20 @@
$feedItem.data('original-max-height', $feedItem.css('height'));
events();
// this is a bit lame, because this is a singleton. the idea is, if there are any session widgets on the page, then we start ticking time
if(!context.JK.FeedItemSessionTimer) {
context.JK.FeedItemSessionTimer = setInterval(function() {
$.each($('.feed-entry.music-session-history-entry .inprogress .session-duration'), function(index, item) {
var $duration = $(item);
var createdAt = new Date($duration.attr('data-created-at'))
var millisElapsed = (new Date()).getTime() - createdAt.getTime();
$duration.text(context.JK.prettyPrintSeconds( parseInt(millisElapsed / 1000)));
});
}, 333);
}
}
initialize();

View File

@ -38,7 +38,8 @@
var audioDomElement = null;
var musicSessionId = null;
var waitForBufferingTimeout = null;
var retryAttempts = 0;
var retryAttempts = 0;
var self = this;
var destroyed = false;
@ -53,8 +54,8 @@
var PlayStateFailedPlaying = 'failed_playing'; // failed while playing.
var PlayStateSessionOver = 'session_over'; // session is done
var PlayStateNetworkError = 'network_error'; // network error
var PlayStateServerError = 'server_error'; // network error
var PlayStateServerError = 'server_error'; // server error
var PlayStateConcurrentStop = 'concurrent_stop'; // stopped by another play attempt
var playState = PlayStateNone; // tracks if the stream is actually playing
@ -68,6 +69,12 @@
if(!audioDomElement) throw "no audio element supplied; the user should not be able to attempt a play"
if(context.JK.ListenBroadcastCurrentlyPlaying) {
context.JK.ListenBroadcastCurrentlyPlaying.forcedPause();
}
context.JK.ListenBroadcastCurrentlyPlaying = self;
rest.getSession(musicSessionId)
.done(function(response) {
audioDomElement.play();
@ -92,6 +99,10 @@
})
}
function forcedPause() {
transition(PlayStateConcurrentStop);
pause();
}
function pause(e) {
if(e) {
@ -146,6 +157,16 @@
clearBufferTimeout();
if( playState == PlayStateNone ||
playState == PlayStateEnded ||
playState == PlayStateFailedStart ||
playState == PlayStateFailedPlaying ||
playState == PlayStateSessionOver ||
playState == PlayStateNetworkError ||
playState == PlayStateServerError ) {
context.JK.ListenBroadcastCurrentlyPlaying = null;
}
$parent.triggerHandler('statechange.listenBroadcast', {state: playState, retryCount: retryAttempts});
}
@ -302,10 +323,13 @@
this.play = play;
this.pause = pause;
this.forcedPause = forcedPause; // meant only be called by this code; not from external
return this;
}
context.JK.ListenBroadcastCurrentlyPlaying = null;
$.fn.listenBroadcast = function(options) {
new context.JK.ListenBroadcast(this, options);
}

View File

@ -88,6 +88,9 @@ body.web {
.recording-current {
top:8px;
}
.session-duration {
top:8px;
}
.recording-controls, .session-controls {
margin-top:0px;

View File

@ -25,7 +25,7 @@
.session-status
= feed_item.is_over? ? 'SESSION ENDED' : 'SESSION IN PROGRESS'
/ current playback time
= session_duration(feed_item, class: 'recording-current')
= session_duration(feed_item, class: 'session-duration recording-current', 'data-created-at' => feed_item.created_at)
/ end recording play controls
/ genre and social
.left.small