From 4793ea701a391b9d632470213b33f3a18cd77356 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 16 Sep 2014 21:13:36 -0500 Subject: [PATCH 1/9] * VRFS-2209 - fix progress bar by fixing the update size variable. also show countdown --- web/app/assets/javascripts/clientUpdate.js | 41 ++++++++++++++----- .../stylesheets/client/clientUpdate.css.scss | 6 +++ web/app/views/clients/_client_update.html.erb | 11 +++-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/web/app/assets/javascripts/clientUpdate.js b/web/app/assets/javascripts/clientUpdate.js index a23529154..5df2ce32e 100644 --- a/web/app/assets/javascripts/clientUpdate.js +++ b/web/app/assets/javascripts/clientUpdate.js @@ -10,11 +10,11 @@ var logger = context.JK.logger; var ellipsesJiggleTimer = null; var forceShow = false; // manual test helper + // updated once a download is started var updateUri = null; + var updateSize = 0; app.clientUpdating = false; - // updated once a download is started - var updateSize = 0; function cancelUpdate(e) { if ((e.ctrlKey || e.metaKey) && e.keyCode == 78) { @@ -27,8 +27,10 @@ // responsible for updating the contents of the update dialog // as well as registering for any event handlers function updateClientUpdateDialog(templateId, options) { + options = options || {}; + var template = $('#template-' + templateId).html(); - var templateHtml = context.JK.fillTemplate(template, options); + var templateHtml = context._.template(template, options, {variable: 'data'}); $('#client_update .dialog-inner').html(templateHtml); @@ -69,12 +71,13 @@ /***************************************/ function clientUpdateDownloadProgress(bytesReceived, bytesTotal, downloadSpeedMegSec, timeRemaining) { // this fires way too many times to leave in. uncomment if debugging update feature - //logger.debug("bytesReceived: " + bytesReceived, ", bytesTotal: " + bytesTotal, ", downloadSpeed: " + downloadSpeedMegSec, ", timeRemaining: " + timeRemaining ); + //logger.debug("bytesReceived: " + bytesReceived, ", bytesTotal: " + bytesTotal, ", downloadSpeed: " + downloadSpeedMegSec, ", timeRemaining: " + timeRemaining + ", updateSize: " + updateSize); bytesReceived = Number(bytesReceived) bytesTotal = Number(bytesTotal) // bytesTotal from Qt is not trust worthy; trust server's answer instead - $('#progress-bar').width(((bytesReceived / updateSize) * 100).toString() + "%") + var progressWidth = ((bytesReceived / updateSize) * 100).toString() + "%"; + $('#progress-bar').width(progressWidth) //$("#progressbar_detail").text(parseInt(bytesReceived) + "/" + parseInt(updateSize)) } @@ -98,10 +101,27 @@ } - function clientUpdateLaunchSuccess(updateLocation) { - logger.debug("client update launched successfully to: " + updateLocation); + function clientUpdateLaunchSuccess(userTimeToRead) { + if(userTimeToRead === undefined) { + userTimeToRead = 1000; // older clients didn't pass this in, and exit very quickly + } - updateClientUpdateDialog("update-restarting"); + logger.debug("client update launching in: " + userTimeToRead); + + // set timer to update countdown + var rounded = Math.round(userTimeToRead / 1000); + + // simple countdown timer + var timer = setInterval(function(){ + var $countdown = $('#client_update .countdown-secs'); + var countdown = parseInt($countdown.text()); + $countdown.text(countdown - 1); + if(countdown == 0) { + clearInterval(timer); + } + }, rounded * 1000); + + updateClientUpdateDialog("update-restarting", {countdown: rounded, os: context.JK.GetOSAsString()}); } function clientUpdateLaunchFailure(errorMsg) { @@ -167,7 +187,7 @@ } } - function runCheck(product, version, uri, updateSize, currentVersion) { + function runCheck(product, version, uri, size, currentVersion) { if(currentVersion === undefined) { currentVersion = context.jamClient.ClientUpdateVersion(); @@ -191,6 +211,7 @@ if (shouldUpdate(currentVersion, version)) { app.clientUpdating = true; updateUri = uri; + updateSize = size; if(context.JK.CurrentSessionModel && context.JK.CurrentSessionModel.inSession()) { logger.debug("deferring client update because in session") @@ -210,7 +231,7 @@ // check if updated is needed function check() { - var os = context.jamClient.GetOSAsString(); + var os = context.JK.GetOSAsString(); // check kill switch before all other logic if (!gon.check_for_client_updates) { diff --git a/web/app/assets/stylesheets/client/clientUpdate.css.scss b/web/app/assets/stylesheets/client/clientUpdate.css.scss index b22d78295..cc0321127 100644 --- a/web/app/assets/stylesheets/client/clientUpdate.css.scss +++ b/web/app/assets/stylesheets/client/clientUpdate.css.scss @@ -22,6 +22,12 @@ display:block; } + .countdown-secs { + font-size:24px; + display:inline-block; + width:15px; + } + h2 { font-weight:bold; font-size:x-large; diff --git a/web/app/views/clients/_client_update.html.erb b/web/app/views/clients/_client_update.html.erb index 51987a3a2..17fe2b868 100644 --- a/web/app/views/clients/_client_update.html.erb +++ b/web/app/views/clients/_client_update.html.erb @@ -75,8 +75,13 @@

- This application will close automatically in a moment. - If it does not close, please restart it manually. + {% if(data.os == 'MacOSX') { %} + This application will close automatically in {{data.countdown}} {{data.countdown == 1 ? 'second' : 'seconds'}}. + If it does not close, please restart it manually or download the latest JamKazam from our downloads page. + {% } else { %} + The updater will launch automatically in {{data.countdown}} seconds. + If you do not see a Windows updater, please restart it manually or download the latest JamKazam from our downloads page. + {% } %}
@@ -90,7 +95,7 @@

Download the latest JamKazam from our downloads page.

- {error_msg} + {{data.error_msg}}
From 6b96bdcd05dfb47b5be1d71f459f7d4672abf592 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 10:09:53 -0500 Subject: [PATCH 2/9] * VRFS-2221 - fix bad reconnect path --- ruby/lib/jam_ruby/connection_manager.rb | 6 +++++- websocket-gateway/lib/jam_websockets/router.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index bca7d364e..b9e23adf9 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -84,8 +84,12 @@ module JamRuby conn.save!(validate: false) end + # if udp_reachable is nil, it means it's unknown. Since this is a reconnect, we'll, preserve existing value in this case + # otherwise, pass in the value of boolean udp_reachable var + udp_reachable_value = udp_reachable.nil? ? 'udp_reachable' : udp_reachable + sql =< Date: Wed, 17 Sep 2014 10:21:42 -0500 Subject: [PATCH 3/9] * adding tests for VRFS-2221 --- ruby/spec/jam_ruby/connection_manager_spec.rb | 44 ++++++++++++++++++- web/app/assets/javascripts/JamServer.js | 1 + .../lib/jam_websockets/router.rb | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ruby/spec/jam_ruby/connection_manager_spec.rb b/ruby/spec/jam_ruby/connection_manager_spec.rb index 99c5f1b25..5209dfbb3 100644 --- a/ruby/spec/jam_ruby/connection_manager_spec.rb +++ b/ruby/spec/jam_ruby/connection_manager_spec.rb @@ -104,14 +104,56 @@ describe ConnectionManager, no_transaction: true do cc.ip_address.should eql("1.1.1.1") cc.addr.should == 0x01010101 cc.locidispid.should == 17192000002 + cc.udp_reachable.should == true - @connman.reconnect(cc, channel_id, nil, "33.1.2.3", STALE_TIME, EXPIRE_TIME, REACHABLE) + @connman.reconnect(cc, channel_id, nil, "33.1.2.3", STALE_TIME, EXPIRE_TIME, false) cc = Connection.find_by_client_id!(client_id) cc.connected?.should be_true cc.ip_address.should eql("33.1.2.3") cc.addr.should == 0x21010203 cc.locidispid.should == 30350000003 + cc.udp_reachable.should == false + + count = @connman.delete_connection(client_id) + count.should == 0 + + @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result| + result.getvalue(0, 0).to_i.should == 0 + end + end + + it "create connection, reconnect via heartbeat" do + + client_id = "client_id3" + #user_id = create_user("test", "user2", "user2@jamkazam.com") + user = FactoryGirl.create(:user) + + count = @connman.create_connection(user.id, client_id, channel_id, "1.1.1.1", 'client', STALE_TIME, EXPIRE_TIME, false) + + count.should == 1 + + # make sure the connection is seen + + @conn.exec("SELECT count(*) FROM connections where user_id = $1", [user.id]) do |result| + result.getvalue(0, 0).to_i.should == 1 + end + + cc = Connection.find_by_client_id!(client_id) + cc.connected?.should be_true + cc.ip_address.should eql("1.1.1.1") + cc.addr.should == 0x01010101 + cc.locidispid.should == 17192000002 + cc.udp_reachable.should == false + + @connman.reconnect(cc, channel_id, nil, "33.1.2.3", STALE_TIME, EXPIRE_TIME, nil) # heartbeat passes nil in for udp_reachable + + cc = Connection.find_by_client_id!(client_id) + cc.connected?.should be_true + cc.ip_address.should eql("33.1.2.3") + cc.addr.should == 0x21010203 + cc.locidispid.should == 30350000003 + cc.udp_reachable.should == false count = @connman.delete_connection(client_id) count.should == 0 diff --git a/web/app/assets/javascripts/JamServer.js b/web/app/assets/javascripts/JamServer.js index 846a8d20e..24fe6b4f6 100644 --- a/web/app/assets/javascripts/JamServer.js +++ b/web/app/assets/javascripts/JamServer.js @@ -222,6 +222,7 @@ heartbeatMS = payload.heartbeat_interval * 1000; connection_expire_time = payload.connection_expire_time * 1000; logger.info("loggedIn(): clientId=" + app.clientId + " heartbeat=" + payload.heartbeat_interval + "s expire_time=" + payload.connection_expire_time + 's'); + heartbeatMS = 40 * 1000; heartbeatInterval = context.setInterval(_heartbeat, heartbeatMS); heartbeatAckCheckInterval = context.setInterval(_heartbeatAckCheck, 1000); lastHeartbeatAckTime = new Date(new Date().getTime() + heartbeatMS); // add a little forgiveness to server for initial heartbeat diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index cdcbf4bf0..5a6b42bfb 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -737,6 +737,7 @@ module JamWebsockets if connection.stale? ConnectionManager.active_record_transaction do |connection_manager| heartbeat_interval, connection_stale_time, connection_expire_time = determine_connection_times(context.user, context.client_type) + puts "RECONNECETETETETETETETET" connection_manager.reconnect(connection, connection.music_session_id, nil, connection_stale_time, connection_expire_time, nil) end end From a2738088658e808a553cb6cf9ee46782b55f1b11 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 10:26:58 -0500 Subject: [PATCH 4/9] * fix reconnect path again --- websocket-gateway/lib/jam_websockets/router.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index 5a6b42bfb..83447b9b9 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -738,7 +738,7 @@ module JamWebsockets ConnectionManager.active_record_transaction do |connection_manager| heartbeat_interval, connection_stale_time, connection_expire_time = determine_connection_times(context.user, context.client_type) puts "RECONNECETETETETETETETET" - connection_manager.reconnect(connection, connection.music_session_id, nil, connection_stale_time, connection_expire_time, nil) + connection_manager.reconnect(connection, client.channel_id, connection.music_session_id, nil, connection_stale_time, connection_expire_time, nil) end end end From 0b1ba57e1e37910a8a8e247167a0f92fdb9705a9 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 10:27:31 -0500 Subject: [PATCH 5/9] * remove puts --- websocket-gateway/lib/jam_websockets/router.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index 83447b9b9..f16dc1fd9 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -737,7 +737,6 @@ module JamWebsockets if connection.stale? ConnectionManager.active_record_transaction do |connection_manager| heartbeat_interval, connection_stale_time, connection_expire_time = determine_connection_times(context.user, context.client_type) - puts "RECONNECETETETETETETETET" connection_manager.reconnect(connection, client.channel_id, connection.music_session_id, nil, connection_stale_time, connection_expire_time, nil) end end From 9b6715d1015791b2560c55b57b180f8a4c4b38b8 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 10:43:10 -0500 Subject: [PATCH 6/9] * remove debugging heartbeat --- web/app/assets/javascripts/JamServer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web/app/assets/javascripts/JamServer.js b/web/app/assets/javascripts/JamServer.js index 24fe6b4f6..846a8d20e 100644 --- a/web/app/assets/javascripts/JamServer.js +++ b/web/app/assets/javascripts/JamServer.js @@ -222,7 +222,6 @@ heartbeatMS = payload.heartbeat_interval * 1000; connection_expire_time = payload.connection_expire_time * 1000; logger.info("loggedIn(): clientId=" + app.clientId + " heartbeat=" + payload.heartbeat_interval + "s expire_time=" + payload.connection_expire_time + 's'); - heartbeatMS = 40 * 1000; heartbeatInterval = context.setInterval(_heartbeat, heartbeatMS); heartbeatAckCheckInterval = context.setInterval(_heartbeatAckCheck, 1000); lastHeartbeatAckTime = new Date(new Date().getTime() + heartbeatMS); // add a little forgiveness to server for initial heartbeat From a1d3793ef44813fc6c13721762703550d8cba4bd Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 15:44:48 -0500 Subject: [PATCH 7/9] * poke --- web/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/web/README.md b/web/README.md index 81ad6e3d8..03b796614 100644 --- a/web/README.md +++ b/web/README.md @@ -11,4 +11,3 @@ $ rake jasmine Open browser to localhost:8888 - From f9c751605cc2c42617eb2d52e56a5bc052083aea Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 17:19:35 -0500 Subject: [PATCH 8/9] * VRFS-2016 - potential fix for flapping connections --- web/app/assets/javascripts/JamServer.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web/app/assets/javascripts/JamServer.js b/web/app/assets/javascripts/JamServer.js index 846a8d20e..e3f7f00dc 100644 --- a/web/app/assets/javascripts/JamServer.js +++ b/web/app/assets/javascripts/JamServer.js @@ -542,6 +542,7 @@ server.connecting = true; server.socket = new context.WebSocket(uri); + server.socket.channelId = channelId; server.socket.onopen = server.onOpen; server.socket.onmessage = server.onMessage; server.socket.onclose = server.onClose; @@ -620,6 +621,13 @@ server.onClose = function () { logger.info("Socket to server closed."); + var disconnectedSocket = this; + + if(disconnectedSocket.channelId != server.socket.channelId) { + logger.debug(" ignoring disconnect for non-current socket. current=" + server.socket.channelId + ", disc=" + disconnectedSocket.channelId) + return; + } + if (connectDeferred.state() === "pending") { connectDeferred.reject(); } From 609846c295d45baf7fbd7110d16e11d25bd5ca55 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 17 Sep 2014 20:31:58 -0500 Subject: [PATCH 9/9] * VRFS-2204 - udp_reachable showing now --- admin/app/admin/scoring_load.rb | 2 +- web/app/assets/javascripts/JamServer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/app/admin/scoring_load.rb b/admin/app/admin/scoring_load.rb index 089db30a2..e020a4316 100644 --- a/admin/app/admin/scoring_load.rb +++ b/admin/app/admin/scoring_load.rb @@ -5,7 +5,7 @@ ActiveAdmin.register_page "Current Scoring Load" do table_for GetWork.summary do column "Work", :work_count column "Who", Proc.new { |connection| "#{connection.first_name} #{connection.last_name} - #{connection.email}" } - column "Errors", Proc.new { |connection| "#{connection.udp_reachable != 'f' ? "" : "No STUN"} #{connection.in_timeout != 'f' ? "in timeout," : ""} #{connection.in_session != 'f' ? "in session" : ""}" } + column "Errors", Proc.new { |connection| "#{connection.udp_reachable != false ? "" : "No STUN,"} #{connection.in_timeout != 'f' ? "Timeout," : ""} #{connection.in_session != 'f' ? "In-Session," : ""}" } column "Total Timeouts", :scoring_timeout_occurrences column "Current Scoring Failures", :scoring_failures column "Offset", :scoring_failures_offset diff --git a/web/app/assets/javascripts/JamServer.js b/web/app/assets/javascripts/JamServer.js index e3f7f00dc..85fec6da1 100644 --- a/web/app/assets/javascripts/JamServer.js +++ b/web/app/assets/javascripts/JamServer.js @@ -626,7 +626,7 @@ if(disconnectedSocket.channelId != server.socket.channelId) { logger.debug(" ignoring disconnect for non-current socket. current=" + server.socket.channelId + ", disc=" + disconnectedSocket.channelId) return; - } + } if (connectDeferred.state() === "pending") { connectDeferred.reject();