Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop
This commit is contained in:
commit
7de74f89af
|
|
@ -48,6 +48,7 @@ module ValidationMessages
|
|||
INVITE_REQUIRED = "You must be invited to join this session"
|
||||
FANS_CAN_NOT_JOIN = "Fans can not join this session"
|
||||
CANT_JOIN_RECORDING_SESSION = "is currently recording"
|
||||
CANT_JOIN_MULTIPLE_SESSIONS = 'You cannot join more than one music session'
|
||||
|
||||
# recordings
|
||||
ALREADY_BEING_RECORDED = "already being recorded"
|
||||
|
|
|
|||
|
|
@ -101,6 +101,17 @@ module JamRuby
|
|||
if music_session.is_recording?
|
||||
errors.add(:music_session, ValidationMessages::CANT_JOIN_RECORDING_SESSION)
|
||||
end
|
||||
|
||||
unless user.admin?
|
||||
num_sessions = Connection.where(:user_id => user_id)
|
||||
.where(["(music_session_id IS NOT NULL) AND (aasm_state != ?)",EXPIRED_STATE.to_s])
|
||||
.count
|
||||
if 0 < num_sessions
|
||||
errors.add(:music_session, ValidationMessages::CANT_JOIN_MULTIPLE_SESSIONS)
|
||||
return false;
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ describe ConnectionManager do
|
|||
end
|
||||
|
||||
it "can't create two client_ids of same value" do
|
||||
|
||||
client_id = "client_id1"
|
||||
user_id = create_user("test", "user1", "user1@jamkazam.com")
|
||||
|
||||
|
|
@ -425,5 +424,36 @@ describe ConnectionManager do
|
|||
|
||||
assert_num_connections(client_id, 0)
|
||||
end
|
||||
|
||||
it "join_music_session fails if user has music_session already active" do
|
||||
user_id = create_user("test", "user11", "user11@jamkazam.com")
|
||||
|
||||
user = User.find(user_id)
|
||||
music_session = MusicSession.find(create_music_session(user_id))
|
||||
|
||||
client_id = Faker::Number.number(20)
|
||||
@connman.create_connection(user_id, client_id, "1.1.1.1")
|
||||
connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS)
|
||||
|
||||
client_id = Faker::Number.number(20)
|
||||
@connman.create_connection(user_id, client_id, Faker::Internet.ip_v4_address)
|
||||
music_session = MusicSession.find(create_music_session(user_id))
|
||||
connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS)
|
||||
|
||||
connection.errors.size.should == 1
|
||||
connection.errors.get(:music_session).should == [ValidationMessages::CANT_JOIN_MULTIPLE_SESSIONS]
|
||||
|
||||
user.update_attribute(:admin, true)
|
||||
client_id = Faker::Number.number(20)
|
||||
@connman.create_connection(user_id, client_id, "1.1.1.1")
|
||||
music_session = MusicSession.find(create_music_session(user_id))
|
||||
connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS)
|
||||
client_id = Faker::Number.number(20)
|
||||
@connman.create_connection(user_id, client_id, Faker::Internet.ip_v4_address)
|
||||
music_session = MusicSession.find(create_music_session(user_id))
|
||||
connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS)
|
||||
connection.errors.size.should == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@
|
|||
context.jamClient.OnLoggedIn(payload.user_id, payload.token);
|
||||
|
||||
$.cookie('client_id', payload.client_id);
|
||||
app.initAfterConnect();
|
||||
|
||||
heartbeatMS = payload.heartbeat_interval * 1000;
|
||||
logger.debug("jamkazam.js.loggedIn(): clientId now " + app.clientId + "; Setting up heartbeat every " + heartbeatMS + " MS");
|
||||
|
|
|
|||
|
|
@ -103,9 +103,10 @@
|
|||
JK.currentUserName = null;
|
||||
<% end %>
|
||||
|
||||
|
||||
// Some things can't be initialized until we're connected. Put them here.
|
||||
function _initAfterConnect() {
|
||||
if (this.didInitAfterConnect) return;
|
||||
this.didInitAfterConnect = true
|
||||
|
||||
var recordingManager = new JK.RecordingManager();
|
||||
|
||||
|
|
@ -217,6 +218,7 @@
|
|||
}
|
||||
|
||||
JK.app = JK.JamKazam();
|
||||
JK.app.initAfterConnect = _initAfterConnect;
|
||||
|
||||
// If no jamClient (when not running in native client)
|
||||
// create a fake one.
|
||||
|
|
@ -241,12 +243,16 @@
|
|||
|
||||
// Run a check to see if we're logged in yet. Only after that should
|
||||
// we initialize the other screens.
|
||||
// TODO: There should be a timeout, and a "could not connect" message.
|
||||
function testConnected() {
|
||||
this.numCalls = (this.numCalls || 0) + 1;
|
||||
if (JK.clientId) {
|
||||
_initAfterConnect();
|
||||
JK.app.initAfterConnect();
|
||||
} else {
|
||||
window.setTimeout(testConnected, 100);
|
||||
if (50 <= this.numCalls) { // 5 second max
|
||||
JK.notifyAlert('Server Error', 'Could not connect to server. Please try again later.')
|
||||
} else {
|
||||
window.setTimeout(testConnected, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
testConnected();
|
||||
|
|
|
|||
Loading…
Reference in New Issue