ars stuff
This commit is contained in:
parent
466b4e5092
commit
1ccb6c8a6e
|
|
@ -0,0 +1,5 @@
|
|||
ActiveAdmin.register JamRuby::Ars, :as => 'Ars' do
|
||||
|
||||
menu :label => 'NAS', :parent => 'Operations'
|
||||
|
||||
end
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
ActiveAdmin.register JamRuby::Band, :as => 'Band' do
|
||||
menu :label => 'Bands', :parent => 'Misc'
|
||||
|
||||
collection_action :autocomplete_band_name, :method => :get
|
||||
|
||||
controller do
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
create sequence connections_client_id_int_seq;
|
||||
alter table connections add column client_id_int int not null default nextval('connections_client_id_int_seq');
|
||||
--ALTER SEQUENCE connections_client_id_int_seq OWNED BY connections.id;
|
||||
|
||||
create sequence music_sessions_id_int_seq;
|
||||
alter table connections add column id_int int not null default nextval('music_sessions_id_int_seq');
|
||||
|
||||
CREATE TABLE arses (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
name VARCHAR(20) NOT NULL,
|
||||
id_int SMALLINT,
|
||||
public_ip VARCHAR(200),
|
||||
active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
|
@ -12,3 +12,23 @@ ON music_sessions FOR EACH ROW EXECUTE PROCEDURE
|
|||
tsvector_update_trigger(description_tsv, 'public.jamenglish', description, name, genre_id);
|
||||
|
||||
UPDATE music_sessions set description = description where id in (select music_sessions.id from music_sessions inner join active_music_sessions on active_music_sessions.id = music_sessions.id);
|
||||
|
||||
|
||||
------
|
||||
|
||||
create sequence connections_client_id_int_seq;
|
||||
alter table connections add column client_id_int int not null default nextval('connections_client_id_int_seq');
|
||||
--ALTER SEQUENCE connections_client_id_int_seq OWNED BY connections.id;
|
||||
|
||||
create sequence music_sessions_id_int_seq;
|
||||
alter table music_sessions add column music_session_id_int int not null default nextval('music_sessions_id_int_seq');
|
||||
|
||||
CREATE TABLE arses (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
name VARCHAR(20) NOT NULL UNIQUE NOT NULL,
|
||||
id_int SMALLINT UNIQUE NOT NULL,
|
||||
ip VARCHAR(200) UNIQUE NOT NULL,
|
||||
active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
|
@ -276,6 +276,8 @@ message LoginAck {
|
|||
optional int32 connection_expire_time = 8; // this is how long the server gives you before killing your connection entirely after missing heartbeats
|
||||
optional ClientUpdate client_update = 9;
|
||||
optional string username = 10;
|
||||
optional int32 client_id_int = 11;
|
||||
repeated Ars arses = 12;
|
||||
}
|
||||
|
||||
message ConnectAck {
|
||||
|
|
@ -807,6 +809,12 @@ message ClientUpdate {
|
|||
optional int32 size = 4;
|
||||
}
|
||||
|
||||
message Ars {
|
||||
optional int32 id = 1;
|
||||
optional string ip = 2;
|
||||
optional string name = 3;
|
||||
}
|
||||
|
||||
// target: client
|
||||
// this is meant to be a way to poke clients and do something meaningful that we didn't plan in advance
|
||||
message GenericMessage {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ module JamRuby
|
|||
end
|
||||
|
||||
# create a login ack (login was successful)
|
||||
def login_ack(public_ip, client_id, token, heartbeat_interval, music_session_id, reconnected, user_id, connection_expire_time, username, client_update_data = nil)
|
||||
def login_ack(public_ip, client_id, token, heartbeat_interval, music_session_id, reconnected, user_id, connection_expire_time, username, client_id_int, client_update_data = nil, ars_list = nil)
|
||||
client_update = Jampb::ClientUpdate.new(
|
||||
product: client_update_data[:product],
|
||||
version: client_update_data[:version],
|
||||
|
|
@ -77,6 +77,17 @@ module JamRuby
|
|||
size: client_update_data[:size]
|
||||
) if client_update_data
|
||||
|
||||
arses = []
|
||||
|
||||
ars_list.each do |ars|
|
||||
arses << Jampb::Ars.new(
|
||||
:id => ars.id_int,
|
||||
:ip => ars.ip,
|
||||
:name => ars.name
|
||||
)
|
||||
end if ars_list
|
||||
|
||||
|
||||
login_ack = Jampb::LoginAck.new(
|
||||
:public_ip => public_ip,
|
||||
:client_id => client_id,
|
||||
|
|
@ -87,7 +98,9 @@ module JamRuby
|
|||
:user_id => user_id,
|
||||
:connection_expire_time => connection_expire_time,
|
||||
:client_update => client_update,
|
||||
:username => username
|
||||
:username => username,
|
||||
:client_id_int => client_id_int,
|
||||
:arses => arses
|
||||
)
|
||||
|
||||
Jampb::ClientMessage.new(
|
||||
|
|
|
|||
|
|
@ -831,6 +831,9 @@ module JamRuby
|
|||
music_session.music_notations
|
||||
end
|
||||
|
||||
def music_session_id_int
|
||||
music_session.music_session_id_int
|
||||
end
|
||||
# Verifies that the specified user can join this music session
|
||||
def can_join? user, as_musician
|
||||
music_session.can_join? user, as_musician
|
||||
|
|
|
|||
|
|
@ -2,32 +2,10 @@
|
|||
module JamRuby
|
||||
class Ars < ActiveRecord::Base
|
||||
|
||||
attr_accessible :active, :name, :id_int, :ip, as: :admin
|
||||
|
||||
self.table_name = "arses"
|
||||
@@log = Logging.logger[Ars]
|
||||
|
||||
STATUS_COMPLETED = 'complete'
|
||||
STATUS_ABANDONED = 'abandoned'
|
||||
STATUS_REVOKED = 'revoked'
|
||||
STATUS_DELETED = 'deleted'
|
||||
|
||||
DONE_STATUSES = [STATUS_ABANDONED, STATUS_REVOKED, STATUS_DELETED, STATUS_COMPLETED]
|
||||
belongs_to :music_session, :class_name => 'JamRuby::MusicSession'
|
||||
|
||||
def self.current_broadcast(music_session)
|
||||
Broadcast.where(music_session_id: music_session.id).where('broadcast_status not in (?)', Broadcast::DONE_STATUSES).first
|
||||
end
|
||||
|
||||
def self.unlink_broadcast(music_session)
|
||||
broadcast = current_broadcast(music_session)
|
||||
if broadcast
|
||||
broadcast.broadcast_status = STATUS_DELETED
|
||||
broadcast.save
|
||||
end
|
||||
end
|
||||
|
||||
# data should be JSON hash from google API
|
||||
def update_broadcast_data(data)
|
||||
self.broadcast_status = data["status"]["lifeCycleStatus"]
|
||||
self.broadcast_data = data.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -243,7 +243,17 @@
|
|||
|
||||
if (isClientMode() && context.jamClient) {
|
||||
// tell the backend that we have logged in
|
||||
context.jamClient.OnLoggedIn(payload.user_id, payload.token, payload.username); // ACTS AS CONTINUATION
|
||||
try {
|
||||
var msg = {user_id: payload.user_id, token: payload.token, username: payload.username, arses: payload.arses, client_id_int: payload.client_id_int}
|
||||
console.log("logged with new msg", msg)
|
||||
context.jamClient.OnLoggedIn(msg); // ACTS AS CONTINUATION
|
||||
}
|
||||
catch(e) {
|
||||
console.log("fallback to old callback", e)
|
||||
context.jamClient.OnLoggedIn(payload.user_id, payload.token, payload.username); // ACTS AS CONTINUATION
|
||||
}
|
||||
|
||||
|
||||
$.cookie('client_id', payload.client_id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -780,7 +780,8 @@ ConfigureTracksActions = @ConfigureTracksActions
|
|||
|
||||
@recordingModel.reset(@currentSessionId);
|
||||
|
||||
context.jamClient.JoinSession({sessionID: @currentSessionId});
|
||||
joinSessionMsg = {sessionID: @currentSessionId, music_session_id_int: response.music_session_id_int}
|
||||
context.jamClient.JoinSession(joinSessionMsg);
|
||||
|
||||
#@refreshCurrentSession(true);
|
||||
|
||||
|
|
@ -1034,6 +1035,7 @@ ConfigureTracksActions = @ConfigureTracksActions
|
|||
{
|
||||
userID: "",
|
||||
clientID: participant.client_id,
|
||||
client_id_int: participant.client_id_int,
|
||||
tcpPort: 0,
|
||||
udpPort: 0,
|
||||
localIPAddress: participant.ip_address, # ?
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ $session-screen-divider: 1190px;
|
|||
a.video-tutorial {
|
||||
position:absolute;
|
||||
right:0;
|
||||
top:0;
|
||||
top:1px;
|
||||
}
|
||||
.session-media-tracks {
|
||||
width: 34%;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ if !current_user
|
|||
}
|
||||
else
|
||||
|
||||
attributes :id, :name, :description, :musician_access, :approval_required, :friends_can_join, :fan_access, :fan_chat, :band_id, :user_id, :claimed_recording_initiator_id, :track_changes_counter, :max_score, :backing_track_path, :metronome_active, :jam_track_initiator_id, :jam_track_id
|
||||
attributes :id, :name, :description, :musician_access, :approval_required, :friends_can_join, :fan_access, :fan_chat, :band_id, :user_id, :claimed_recording_initiator_id, :track_changes_counter, :max_score, :backing_track_path, :metronome_active, :jam_track_initiator_id, :jam_track_id, :music_session_id_int
|
||||
|
||||
node :can_join do |session|
|
||||
session.can_join?(current_user, true)
|
||||
|
|
@ -50,7 +50,7 @@ else
|
|||
|
||||
child(:connections => :participants) {
|
||||
collection @music_sessions, :object_root => false
|
||||
attributes :ip_address, :client_id, :joined_session_at, :audio_latency, :id, :metronome_open, :is_jamblaster, :client_role, :parent_client_id
|
||||
attributes :ip_address, :client_id, :joined_session_at, :audio_latency, :id, :metronome_open, :is_jamblaster, :client_role, :parent_client_id, :client_id_int
|
||||
|
||||
node :user do |connection|
|
||||
{ :id => connection.user.id, :photo_url => connection.user.photo_url, :name => connection.user.name, :is_friend => connection.user.friends?(current_user), :connection_state => connection.aasm_state }
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ module JamWebsockets
|
|||
@maximum_minutely_heartbeat_rate_browser = nil
|
||||
@maximum_minutely_heartbeat_rate_client = nil
|
||||
@gateway_name = nil
|
||||
@stored_ars = nil
|
||||
@ar_base_logger = ::Logging::Repository.instance[ActiveRecord::Base]
|
||||
@message_stats = {}
|
||||
@time_it_sums = {}
|
||||
|
|
@ -671,7 +672,7 @@ module JamWebsockets
|
|||
context
|
||||
end
|
||||
|
||||
def handle_latency_tester_login(client_id, client_type, client, override_ip)
|
||||
def handle_latency_tester_login(client_id, client_type, client, override_ip, client_id_int)
|
||||
|
||||
# respond with LOGIN_ACK to let client know it was successful
|
||||
remote_ip = extract_ip(client, override_ip)
|
||||
|
|
@ -693,6 +694,7 @@ module JamWebsockets
|
|||
client.client_id = client_id
|
||||
client.user_id = latency_tester.id if latency_tester
|
||||
|
||||
|
||||
@semaphore.synchronize do
|
||||
|
||||
context = add_tracker(latency_tester, client, client_type, client_id)
|
||||
|
|
@ -707,7 +709,8 @@ module JamWebsockets
|
|||
false,
|
||||
latency_tester.id,
|
||||
connection_expire_time,
|
||||
"latency_tester")
|
||||
"latency_tester",
|
||||
client_id_int)
|
||||
stats_logged_in
|
||||
send_to_client(client, login_ack)
|
||||
end
|
||||
|
|
@ -733,6 +736,10 @@ module JamWebsockets
|
|||
send_to_client(client, logout_ack)
|
||||
end
|
||||
|
||||
def ars_list
|
||||
@stored_ars
|
||||
end
|
||||
|
||||
def handle_login(client, options, override_ip = nil, connecting = true)
|
||||
username = options["username"]
|
||||
password = options["password"]
|
||||
|
|
@ -745,6 +752,7 @@ module JamWebsockets
|
|||
jamblaster_serial_no = options["jamblaster_serial_no"]
|
||||
ipv4_link_local = options["ipv4_link_local"]
|
||||
ipv6_link_local = options["ipv6_link_local"]
|
||||
client_id_int = options["client_id_int"]
|
||||
|
||||
# it's nice to have client_ids not flap in the wind, and we can do that with jamblasters
|
||||
if jamblaster_serial_no && client_id.nil?
|
||||
|
|
@ -758,9 +766,9 @@ module JamWebsockets
|
|||
client.subscriptions = Set.new # list of subscriptions that this client is watching in real-time
|
||||
|
||||
serial_no_debug = jamblaster_serial_no ? "serial_no=#{jamblaster_serial_no}" : ''
|
||||
@log.info("handle_login: type=#{client_type} username=#{username} password=#{password ? '*' : 'null' } token=#{token} client_id=#{client_id} channel_id=#{client.channel_id} udp_reachable=#{udp_reachable} #{serial_no_debug}")
|
||||
@log.info("handle_login: type=#{client_type} username=#{username} password=#{password ? '*' : 'null' } token=#{token} client_id=#{client_id} client_id_int=#{client_id_int} channel_id=#{client.channel_id} udp_reachable=#{udp_reachable} #{serial_no_debug}")
|
||||
if client_type == Connection::TYPE_LATENCY_TESTER
|
||||
handle_latency_tester_login(client_id, client_type, client, override_ip)
|
||||
handle_latency_tester_login(client_id, client_type, client, override_ip, client_id_int)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -931,7 +939,8 @@ module JamWebsockets
|
|||
# log this connection in the database
|
||||
ConnectionManager.active_record_transaction do |connection_manager|
|
||||
connection_manager.create_connection(user.id, client.client_id, client.channel_id, remote_ip, client_type, connection_stale_time, connection_expire_time, udp_reachable, @gateway_name, jamblaster ? true : false) do |conn, count|
|
||||
user.update_addr_loc(Connection.find_by_client_id(client.client_id), User::JAM_REASON_LOGIN)
|
||||
connection = Connection.find_by_client_id(client.client_id)
|
||||
user.update_addr_loc(connection, User::JAM_REASON_LOGIN)
|
||||
if count == 1
|
||||
Notification.send_friend_update(user.id, true, conn)
|
||||
end
|
||||
|
|
@ -944,6 +953,8 @@ module JamWebsockets
|
|||
|
||||
client_update = update.update_data if update
|
||||
|
||||
arses = ars_list()
|
||||
|
||||
login_ack = @message_factory.login_ack(remote_ip,
|
||||
client_id,
|
||||
user.remember_token,
|
||||
|
|
@ -953,7 +964,9 @@ module JamWebsockets
|
|||
user.id,
|
||||
connection_expire_time,
|
||||
user.name,
|
||||
client_update)
|
||||
connection.client_id_int,
|
||||
client_update,
|
||||
arses)
|
||||
stats_logged_in
|
||||
send_to_client(client, login_ack)
|
||||
|
||||
|
|
@ -1341,6 +1354,9 @@ module JamWebsockets
|
|||
def periodical_check_clients
|
||||
# it's possible that a client will not be represented in the database anymore, due to hard to trace/guess scenario
|
||||
# usually involve reconnects. Double-check that all clients in memory are actually in the database. if not, delete them from memory
|
||||
|
||||
@stored_ars = Ars.where(active: true).all
|
||||
|
||||
if @client_lookup.length == 0
|
||||
return
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue