diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index 8ebe32436..663622fff 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -112,6 +112,19 @@ module JamRuby end end + # this should be used to cleanup a recording that we detect is no longer running + def abort + recording.music_session.claimed_recording_id = nil + recording.music_session.claimed_recording_initiator_id = nil + + # double check that there are no claims to this recording before destroying it + unless claimed_recordings.length > 0 + destroy + end + + + end + def not_still_finalizing_previous # after a recording is done, users need to keep or discard it. # this checks if the previous recording is still being finalized @@ -255,7 +268,14 @@ module JamRuby self.all_discarded = true # the feed won't pick this up; also background cleanup will find these and whack them later self.save(:validate => false) end + end + # only discard if the user has previously taken no action + def discard_if_no_action(user) + track = recorded_tracks_for_user(user).first + if track.discard.nil? + discard(user ) + end end # Find out if all the tracks for this recording have been uploaded diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index c3dbad3b9..9a8e1dd6a 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -244,7 +244,7 @@ notifyWithUserInfo(title, 'could not be signalled to start recording.', detail); } else if(data.reason == 'already-recording') { - app.notifyAlert(title, 'Already recording.'); + app.notifyAlert(title, 'Already recording. If this appears incorrect, try restarting JamKazam.'); } else if(data.reason == 'recording-engine-unspecified') { notifyWithUserInfo(title, 'had a problem writing recording data to disk.', detail); diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index 0f755358e..acf5560df 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -596,7 +596,21 @@ module JamWebsockets # if so, then we need to tell the others in the session that this user is now departed unless music_session_upon_reentry.nil? || music_session_upon_reentry.destroyed? recording = music_session_upon_reentry.stop_recording - recording_id = recording.id unless recording.nil? + unless recording.nil? + @log.debug "stopped recording: #{recording.id} because user #{user} reconnected" + recording.discard_if_no_action(user) # throw away this users vote for the + recording_id = recording.id unless recording.nil? + end + + # if the user was in a recording during the finializing phase (after stopped, but keep/discard still required in recordingFinishedDialog) + # then throw away the user's + most_recent_recording = music_session_upon_reentry.most_recent_recording + if most_recent_recording && most_recent_recording.users.exists?(user) + @log.debug "disarded user's vote for recording: #{most_recent_recording.id} because user #{user} reconnected" + # if this user was in the most recent recording associated with the session they were just in, discard any tracks they had + most_recent_recording.discard_if_no_action(user) # throw away this users vote for the + end + music_session_upon_reentry.with_lock do # VRFS-1297 music_session_upon_reentry.tick_track_changes end @@ -971,13 +985,29 @@ module JamWebsockets # remove this connection from the database ConnectionManager.active_record_transaction do |mgr| mgr.delete_connection(cid) { |conn, count, music_session_id, user_id| - @log.info "expiring stale connection client_id:#{cid}, user_id:#{user_id}" + user = User.find(user_id) + @log.info "expiring stale connection client_id:#{cid}, user_id:#{user}" Notification.send_friend_update(user_id, false, conn) if count == 0 music_session = ActiveMusicSession.find_by_id(music_session_id) unless music_session_id.nil? user = User.find_by_id(user_id) unless user_id.nil? - recording = music_session.stop_recording unless music_session.nil? # stop any ongoing recording, if there is one - recording_id = recording.id unless recording.nil? if music_session + + recording = music_session.stop_recording + unless recording.nil? + @log.debug "stopped recording: #{recording.id} because user #{user} reconnected" + recording.discard_if_no_action(user) # throw away this users vote for the + recording_id = recording.id unless recording.nil? + end + + # if the user was in a recording during the finializing phase (after stopped, but keep/discard still required in recordingFinishedDialog) + # then throw away the user's + most_recent_recording = music_session.most_recent_recording + if most_recent_recording && most_recent_recording.users.exists?(user) + @log.debug "disarded user's vote for recording: #{most_recent_recording.id} because user #{user} reconnected" + # if this user was in the most recent recording associated with the session they were just in, discard any tracks they had + most_recent_recording.discard_if_no_action(user) # throw away this users vote for the + end + music_session.with_lock do # VRFS-1297 music_session.tick_track_changes end