From 6f79878f91e910be506f5bdc7c1988def6906d6c Mon Sep 17 00:00:00 2001 From: Seth Call Date: Thu, 31 Jul 2014 10:32:20 -0500 Subject: [PATCH] * VRFS-1975/VRFS-2003 - don't send two participant creates back-to-back --- .../assets/javascripts/scheduled_session.js | 41 ++++--------------- web/app/assets/javascripts/session.js | 6 +++ web/app/assets/javascripts/sessionModel.js | 13 ++++-- .../participant_create.rabl | 11 +++++ .../api_music_sessions/participant_show.rabl | 5 +-- 5 files changed, 35 insertions(+), 41 deletions(-) create mode 100644 web/app/views/api_music_sessions/participant_create.rabl diff --git a/web/app/assets/javascripts/scheduled_session.js b/web/app/assets/javascripts/scheduled_session.js index 8d4227e6d..4075157cb 100644 --- a/web/app/assets/javascripts/scheduled_session.js +++ b/web/app/assets/javascripts/scheduled_session.js @@ -571,7 +571,7 @@ function startSessionClicked() { var $btn = $(this); - if($btn.is('.disabled')) { return; } + if($btn.is('.disabled')) { return false; } $btn.addClass('disabled') if(willOptionStartSession()) { @@ -590,6 +590,8 @@ else { startSession($btn); } + + return false; } // did the user have to pick the RSVP slots explicitely? @@ -687,39 +689,12 @@ } var joinSession = function(sessionId) { - var tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient); - - var options = {}; - options.client_id = app.clientId; - options.session_id = sessionId; - options.as_musician = true; - options.tracks = tracks; - rest.joinSession(options) - .done(function(response) { - var invitationCount = data.invitations.length; - - context.location = '/client#/session/' + sessionId; - - context.JK.GA.trackSessionCount(data.musician_access, data.fan_access, invitationCount); - context.JK.GA.trackSessionMusicians(context.JK.GA.SessionCreationTypes.create); - }) - .fail(function(jqXHR) { - $startBtn.removeClass('disabled'); - var handled = false; - if(jqXHR.status = 422) { - var response = JSON.parse(jqXHR.responseText); - if(response["errors"] && response["errors"]["tracks"] && response["errors"]["tracks"][0] == "Please select at least one track") { - app.notifyAlert("No Inputs Configured", $('You will need to reconfigure your audio device.')); - handled = true; - } - } - if(!handled) { - app.notifyServerError(jqXHR, "Unable to Create Session"); - } - }) - .always(function() { - }) + var invitationCount = data.invitations.length; + context.JK.GA.trackSessionCount(data.musician_access, data.fan_access, invitationCount); + // we redirect to the session screen, which handles the REST call to POST /participants. + logger.debug("joining session screen: " + sessionId) + context.location = '/client#/session/' + sessionId; }; if (createSessionSettings.createType == 'start-scheduled') { diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index 4a6d11ace..51f28cf5c 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -315,6 +315,12 @@ null, true); } + else if(xhr.status == 422) { + var response = JSON.parse(jqXHR.responseText); + if(response["errors"] && response["errors"]["tracks"] && response["errors"]["tracks"][0] == "Please select at least one track") { + app.notifyAlert("No Inputs Configured", $('You will need to reconfigure your audio device.')); + } + } else { app.notifyServerError(xhr, 'Unable to Join Session'); } diff --git a/web/app/assets/javascripts/sessionModel.js b/web/app/assets/javascripts/sessionModel.js index 0adb1fdc9..d7fb0a424 100644 --- a/web/app/assets/javascripts/sessionModel.js +++ b/web/app/assets/javascripts/sessionModel.js @@ -87,17 +87,22 @@ var deferred = joinSessionRest(sessionId); deferred - .done(function(){ + .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 if(!alreadyInSession()) { - // on temporary disconnect scenarios, a user may already be in a session when they enter this path - // so we avoid double counting + if(response.music_session.participant_count == 1) { + context.JK.GA.trackSessionMusicians(context.JK.GA.SessionCreationTypes.create); + } + else { context.JK.GA.trackSessionMusicians(context.JK.GA.SessionCreationTypes.join); + } } recordingModel.reset(); client.JoinSession({ sessionID: sessionId }); - refreshCurrentSession(); + refreshCurrentSession(true); server.registerMessageCallback(context.JK.MessageType.SESSION_JOIN, trackChanges); server.registerMessageCallback(context.JK.MessageType.SESSION_DEPART, trackChanges); server.registerMessageCallback(context.JK.MessageType.TRACKS_CHANGED, trackChanges); diff --git a/web/app/views/api_music_sessions/participant_create.rabl b/web/app/views/api_music_sessions/participant_create.rabl new file mode 100644 index 000000000..6d8c26c70 --- /dev/null +++ b/web/app/views/api_music_sessions/participant_create.rabl @@ -0,0 +1,11 @@ +object @connection + +extends "api_music_sessions/participant_show" + +child(:music_session => :music_session) { + attributes :id + + node :participant_count do |music_session| + music_session.connections.length + end +} \ No newline at end of file diff --git a/web/app/views/api_music_sessions/participant_show.rabl b/web/app/views/api_music_sessions/participant_show.rabl index cbbf29c87..1805cf45d 100644 --- a/web/app/views/api_music_sessions/participant_show.rabl +++ b/web/app/views/api_music_sessions/participant_show.rabl @@ -1,11 +1,8 @@ object @connection -attributes :ip_address, :client_id +attributes :ip_address, :client_id, :user_id attribute :aasm_state => :connection_state -node(:user_id, :if => lambda { |connection| connection.user.friends?(current_user) }) do |connection| - connection.user_id -end child(:tracks => :tracks) { attributes :id, :instrument_id, :sound } \ No newline at end of file