From 1c0a6b2138b112c45069e0c9fe46d02c0365c6b8 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 16 Mar 2024 10:52:32 +0530 Subject: [PATCH 1/7] change default value setting change users migration not to lock the table by directly setting the default value of the accept_desktop_notifications colums when running the migration --- .../20240121174150_add_accept_desktop_notifications_to_users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb b/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb index 750dec0e4..c83cd5896 100644 --- a/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb +++ b/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb @@ -1,6 +1,6 @@ class AddAcceptDesktopNotificationsToUsers < ActiveRecord::Migration def self.up - execute("ALTER TABLE public.users ADD COLUMN accept_desktop_notifications BOOLEAN DEFAULT false;") + execute("ALTER TABLE public.users ADD COLUMN accept_desktop_notifications BOOLEAN; UPDATE public.users SET accept_desktop_notifications = FALSE;") end def self.down execute("ALTER TABLE public.users DROP COLUMN accept_desktop_notifications;") From 4144d6d12395334421f1dbad5eefde4435b30fe2 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 16 Mar 2024 14:18:31 +0530 Subject: [PATCH 2/7] extract changes to artifacts from promised based branch --- ruby/lib/jam_ruby/models/artifact_update.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ruby/lib/jam_ruby/models/artifact_update.rb b/ruby/lib/jam_ruby/models/artifact_update.rb index ae6f66596..7eed4ee59 100644 --- a/ruby/lib/jam_ruby/models/artifact_update.rb +++ b/ruby/lib/jam_ruby/models/artifact_update.rb @@ -3,8 +3,17 @@ module JamRuby DEFAULT_ENVIRONMENT = 'public' CLIENT_PREFIX = 'JamClient' + CLIENT_PREFIX_MODERN = 'JamClientModern' - PRODUCTS = ["#{CLIENT_PREFIX}/Win32", "#{CLIENT_PREFIX}/MacOSX", "#{CLIENT_PREFIX}/JamBlaster", "#{CLIENT_PREFIX}/JamBlasterClient"] + PRODUCTS = [ + "#{CLIENT_PREFIX}/Win32", + "#{CLIENT_PREFIX}/MacOSX", + "#{CLIENT_PREFIX}/JamBlaster", + "#{CLIENT_PREFIX}/JamBlasterClient", + "#{CLIENT_PREFIX_MODERN}/Win32", + "#{CLIENT_PREFIX_MODERN}/MacOSX-Intel", + "#{CLIENT_PREFIX_MODERN}/MacOSX-M" + ] self.primary_key = 'id' attr_accessible :version, :uri, :sha1, :environment, :product, as: :admin @@ -34,8 +43,8 @@ module JamRuby Notification.send_client_update(product, version, determine_url, size) end - def self.find_client_by_os(os, environment=DEFAULT_ENVIRONMENT) - ArtifactUpdate.find_by_product_and_environment("#{CLIENT_PREFIX}/#{os}", environment) + def self.find_client_by_os(product, os, environment=DEFAULT_ENVIRONMENT) + ArtifactUpdate.find_by_product_and_environment("#{product}/#{os}", environment) end def determine_url From 52c8b48d81ac9ea0e3dd1be4535ee0d659150484 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 16 Mar 2024 14:34:03 +0530 Subject: [PATCH 3/7] merge websocket-gateway changes from promised branch get the changes on router file and apply on develop branch --- .../lib/jam_websockets/router.rb | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index 489351cda..b616ca98b 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -95,8 +95,7 @@ module JamWebsockets # this thread runs forever while WSG runs, and should do anything easily gotten out of critical message handling path @background_thread = Thread.new { - client_check_count = 0 - user_last_seen_count = 0 + count = 0 while true @@ -104,17 +103,11 @@ module JamWebsockets periodical_check_connections periodical_notification_seen - if client_check_count == 30 + if count == 30 periodical_check_clients - client_check_count = 0 + count = 0 end - client_check_count = client_check_count + 1 - - if user_last_seen_count == 120 - periodical_update_user_last_seen - user_last_seen_count = 0 - end - user_last_seen_count = user_last_seen_count + 1 + count = count + 1 rescue => e @log.error "unhandled error in thread #{e}" @@ -790,6 +783,7 @@ module JamWebsockets end def handle_login(client, options, override_ip = nil, connecting = true) + puts("====handle_login====", options) username = options["username"] password = options["password"] token = options["token"] @@ -798,6 +792,8 @@ module JamWebsockets client_type = options["client_type"] machine_fingerprint = options["machine"] os = options["os"] + product = options["product"].nil? ? JamRuby::ArtifactUpdate::CLIENT_PREFIX : options[' +product'] udp_reachable = options["udp_reachable"].nil? ? true : options["udp_reachable"] == 'true' jamblaster_serial_no = options["jamblaster_serial_no"] ipv4_link_local = options["ipv4_link_local"] @@ -1001,9 +997,13 @@ module JamWebsockets end end end - + + puts "=========================" + puts "O/S = #{os}" + puts "=========================" # if we have OS data, try to grab client update data and let the client have it - update = ArtifactUpdate.find_client_by_os(os) if client_type == Connection::TYPE_CLIENT && os + update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection: + :TYPE_CLIENT && os client_update = update.update_data if update @@ -1053,7 +1053,8 @@ module JamWebsockets end end # if we have OS data, try to grab client update data and let the client have it - update = ArtifactUpdate.find_client_by_os(os) if client_type == Connection::TYPE_CLIENT && os + update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection: + :TYPE_CLIENT && os client_update = update.update_data if update @@ -1536,6 +1537,21 @@ module JamWebsockets end end + def periodical_update_user_last_seen + active_users_ids = @client_lookup.map { |client_id, client_context| client_context.active ? client_context.user.id : nil }.compact.uniq + + if active_users_ids.any? + sql = %{ + update users set last_jam_updated_at = now(), last_jam_updated_reason='#{User::JAM_REASON_PRESENT}' where users.id in (#{active_users_ids.map{|id| "'#{id}'"}.join(',')}); + } + @log.info("SQL #{sql}") + + ConnectionManager.active_record_transaction do |connection_manager, conn| + conn.exec(sql) + end + end + end + def periodical_stats_dump # assume 60 seconds per status dump From e5dc8b57ecc8e5332e996de40dae9f226ae70666 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 16 Mar 2024 16:38:33 +0530 Subject: [PATCH 4/7] fix syntax typo in websocket-gateway router.rb --- websocket-gateway/lib/jam_websockets/router.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index b616ca98b..5aecbe467 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -1002,8 +1002,7 @@ product'] puts "O/S = #{os}" puts "=========================" # if we have OS data, try to grab client update data and let the client have it - update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection: - :TYPE_CLIENT && os + update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection::TYPE_CLIENT && os client_update = update.update_data if update @@ -1053,8 +1052,7 @@ product'] end end # if we have OS data, try to grab client update data and let the client have it - update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection: - :TYPE_CLIENT && os + update = ArtifactUpdate.find_client_by_os(product, os) if client_type == Connection::TYPE_CLIENT && os client_update = update.update_data if update From 0476e5ebb638345817d4d249328986de729a465d Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 16 Mar 2024 22:47:15 +0530 Subject: [PATCH 5/7] set default for accept_desktop_notifications --- .../20240121174150_add_accept_desktop_notifications_to_users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb b/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb index c83cd5896..4d0573009 100644 --- a/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb +++ b/ruby/db/migrate/20240121174150_add_accept_desktop_notifications_to_users.rb @@ -1,6 +1,6 @@ class AddAcceptDesktopNotificationsToUsers < ActiveRecord::Migration def self.up - execute("ALTER TABLE public.users ADD COLUMN accept_desktop_notifications BOOLEAN; UPDATE public.users SET accept_desktop_notifications = FALSE;") + execute("ALTER TABLE public.users ADD COLUMN accept_desktop_notifications BOOLEAN; UPDATE public.users SET accept_desktop_notifications = FALSE; ALTER TABLE public.users ALTER COLUMN accept_desktop_notifications SET DEFAULT FALSE;") end def self.down execute("ALTER TABLE public.users DROP COLUMN accept_desktop_notifications;") From 2459b3d4474aca75737af6ff13862d6d9abccca0 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sat, 16 Mar 2024 22:53:15 +0530 Subject: [PATCH 6/7] websocket-gateway copy updates to init --- websocket-gateway/lib/jam_websockets/router.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index 5aecbe467..5f1d5a740 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -95,7 +95,8 @@ module JamWebsockets # this thread runs forever while WSG runs, and should do anything easily gotten out of critical message handling path @background_thread = Thread.new { - count = 0 + client_check_count = 0 + user_last_seen_count = 0 while true @@ -103,11 +104,17 @@ module JamWebsockets periodical_check_connections periodical_notification_seen - if count == 30 + if client_check_count == 30 periodical_check_clients - count = 0 + client_check_count = 0 end - count = count + 1 + client_check_count = client_check_count + 1 + + if user_last_seen_count == 120 + periodical_update_user_last_seen + user_last_seen_count = 0 + end + user_last_seen_count = user_last_seen_count + 1 rescue => e @log.error "unhandled error in thread #{e}" @@ -116,7 +123,7 @@ module JamWebsockets sleep 1 end } - end + end def start(connect_time_stale_client, connect_time_expire_client, connect_time_stale_browser, connect_time_expire_browser, options={:host => "localhost", :port => 5672, :max_connections_per_user => 10, :gateway => 'default', :allow_dynamic_registration => true, :chat_enabled => true, :chat_blast => true}, &block) From 6ad9aed71f714ddea1b2a132d6c98738aa8345f0 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Mon, 18 Mar 2024 08:44:40 +0530 Subject: [PATCH 7/7] use var instead of let/const let and const keywords in javascript can not use because the code based is also been used in the production client. --- .../javascripts/scheduled_session.js.erb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/web/app/assets/javascripts/scheduled_session.js.erb b/web/app/assets/javascripts/scheduled_session.js.erb index 54f6f9415..1cd5f643e 100644 --- a/web/app/assets/javascripts/scheduled_session.js.erb +++ b/web/app/assets/javascripts/scheduled_session.js.erb @@ -1531,13 +1531,13 @@ //this custom url scheme is loaded and as a result the JamKazam app loads create session window. function initCustomUrlScheme(){ //an example URL would be: https://www.jamkazam.com/client#/createSession/custom~yes|privacy~2|description~hello|inviteeIds~1,2,3,4 - const hash = decodeURIComponent(context.location.hash); - const qStr = hash.substring(hash.lastIndexOf('/') + 1); + var hash = decodeURIComponent(context.location.hash); + var qStr = hash.substring(hash.lastIndexOf('/') + 1); //decode the query params according to the custom format - const qParamsArr = qStr.split('|'); - let isCustom, privacy, description, inviteeIds; + var qParamsArr = qStr.split('|'); + var isCustom, privacy, description, inviteeIds; qParamsArr.forEach(function(q){ - const qp = q.split('~') + var qp = q.split('~') if(qp[0] === 'custom') isCustom = qp[1] if(qp[0] === 'privacy') privacy = qp[1] if(qp[0] === 'description') description = qp[1] @@ -1567,9 +1567,9 @@ waitUntilSessionCreated().then(function(){ //now async send invitations if(createSessionSettings.newSessionId && inviteeIds !== undefined){ - const inviteUserIds = inviteeIds.split(','); + var inviteUserIds = inviteeIds.split(','); inviteUserIds.forEach(function(inviteId){ - const invite = { + var invite = { music_session: createSessionSettings.newSessionId, receiver: inviteId }; @@ -1587,10 +1587,10 @@ function waitUntilSessionCreated(){ return new Promise(function(resolve, reject){ - const maxAttempts = 5; - let attempt = 0; + var maxAttempts = 5; + var attempt = 0; try{ - const sessionCreateInterval = setInterval(function(){ + var sessionCreateInterval = setInterval(function(){ attempt++; console.log('_DEBUG_ trying to get the sessionId....', attempt) if(createSessionSettings.newSessionId){