* VRFS-2403 and VRFS-2403 - deal with leaving a session while joining, and with sync track info while joining

This commit is contained in:
Seth Call 2014-10-27 13:26:04 -05:00
parent 970401374b
commit a12e6335eb
1 changed files with 57 additions and 31 deletions

View File

@ -31,6 +31,7 @@
var sessionPageEnterDeferred = null;
var sessionPageEnterTimeout = null;
var startTime = null;
var joinDeferred = null;
server.registerOnSocketClosed(onWebsocketDisconnected);
@ -123,10 +124,18 @@
*/
function joinSession(sessionId) {
logger.debug("SessionModel.joinSession(" + sessionId + ")");
var deferred = joinSessionRest(sessionId);
joinDeferred = joinSessionRest(sessionId);
joinDeferred
.done(function(response){
if(!inSession()) {
// the user has left the session before they got joined. We need to issue a leave again to the server to make sure they are out
logger.debug("user left before fully joined to session. telling server again that they have left")
leaveSessionRest(response.id);
return;
}
deferred
.done(function(response){
logger.debug("calling jamClient.JoinSession");
// on temporary disconnect scenarios, a user may already be in a session when they enter this path
// so we avoid double counting
@ -153,7 +162,7 @@
updateCurrentSession(null);
});
return deferred;
return joinDeferred;
}
function performLeaveSession(deferred) {
@ -251,13 +260,15 @@
}
// universal place to clean up, reset items
function sessionEnded() {
// fullyJoined means the user stayed in the screen until they had a successful rest.joinSession
// you might not get a fully joined if you join/leave really quickly before the REST API completes
function sessionEnded(fullyJoined) {
//cleanup
server.unregisterMessageCallback(context.JK.MessageType.SESSION_JOIN, trackChanges);
server.unregisterMessageCallback(context.JK.MessageType.SESSION_DEPART, trackChanges);
server.unregisterMessageCallback(context.JK.MessageType.TRACKS_CHANGED, trackChanges);
server.registerMessageCallback(context.JK.MessageType.HEARTBEAT_ACK, trackChanges);
server.unregisterMessageCallback(context.JK.MessageType.HEARTBEAT_ACK, trackChanges);
if(sessionPageEnterDeferred != null) {
sessionPageEnterDeferred.reject('session_over');
@ -265,7 +276,10 @@
}
userTracks = null;
startTime = null;
$(document).trigger(EVENTS.SESSION_ENDED, {session: {id: currentSessionId}});
joinDeferred = null;
if(fullyJoined) {
$(document).trigger(EVENTS.SESSION_ENDED, {session: {id: currentSessionId}});
}
currentSessionId = null;
}
@ -280,8 +294,8 @@
currentSession = sessionData;
// the 'beforeUpdate != null' makes sure we only do a clean up one time internally
if(sessionData == null && beforeUpdate != null) {
sessionEnded();
if(sessionData == null) {
sessionEnded(beforeUpdate != null);
}
}
@ -559,32 +573,44 @@
return;
}
// this is a local change to our tracks. we need to tell the server about our updated track information
var inputTracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);
// wait until we are fully in session before trying to sync tracks to server
if(joinDeferred) {
joinDeferred.done(function() {
// create a trackSync request based on backend data
var syncTrackRequest = {};
syncTrackRequest.client_id = app.clientId;
syncTrackRequest.tracks = inputTracks;
syncTrackRequest.id = id();
rest.putTrackSyncChange(syncTrackRequest)
.done(function() {
})
.fail(function(jqXHR) {
if(jqXHR.status != 404) {
app.notify({
"title": "Can't Sync Local Tracks",
"text": "The client is unable to sync local track information with the server. You should rejoin the session to ensure a good experience.",
"icon_url": "/assets/content/icon_alert_big.png"
});
}
else {
logger.debug("Unable to sync local tracks because session is gone.")
// double check that we are in session, since a bunch could have happened since then
if(!inSession()) {
logger.debug("dropping queued up sync tracks because no longer in session");
return;
}
// this is a local change to our tracks. we need to tell the server about our updated track information
var inputTracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);
// create a trackSync request based on backend data
var syncTrackRequest = {};
syncTrackRequest.client_id = app.clientId;
syncTrackRequest.tracks = inputTracks;
syncTrackRequest.id = id();
rest.putTrackSyncChange(syncTrackRequest)
.done(function() {
})
.fail(function(jqXHR) {
if(jqXHR.status != 404) {
app.notify({
"title": "Can't Sync Local Tracks",
"text": "The client is unable to sync local track information with the server. You should rejoin the session to ensure a good experience.",
"icon_url": "/assets/content/icon_alert_big.png"
});
}
else {
logger.debug("Unable to sync local tracks because session is gone.")
}
})
})
}
}, 100);
}
else if(inSession() && (text == 'RebuildMediaControl' || text == 'RebuildRemoteUserControl')) {