You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2017/11/25 03:55:52 UTC

[whimsy] 02/02: close websocket when offline

This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git

commit e37f3ff21607dbf2a014621dc39c3ff48ac0534f
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Fri Nov 24 22:55:22 2017 -0500

    close websocket when offline
---
 www/board/agenda/views/models/events.js.rb  | 15 ++++++++++++++-
 www/board/agenda/views/models/pending.js.rb |  6 ++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/www/board/agenda/views/models/events.js.rb b/www/board/agenda/views/models/events.js.rb
index f5dc73c..46c3b82 100644
--- a/www/board/agenda/views/models/events.js.rb
+++ b/www/board/agenda/views/models/events.js.rb
@@ -118,7 +118,20 @@ class Events
     # proof of life; maintain connection to the server
     setInterval 25_000 do
       localStorage.setItem("#{@@prefix}-timestamp", Date.new().getTime())
-      self.connectToServer()
+
+      if not Server.offline
+        self.connectToServer()
+      elsif @@socket
+        @@socket.close()
+      end
+    end
+
+    window.addEventListener :offlineStatus do |event|
+      if event.detail == true
+        @@socket.close() if @@socket
+      else
+        self.connectToServer()
+      end
     end
 
     # close connection on exit
diff --git a/www/board/agenda/views/models/pending.js.rb b/www/board/agenda/views/models/pending.js.rb
index 7f86723..9eebc51 100644
--- a/www/board/agenda/views/models/pending.js.rb
+++ b/www/board/agenda/views/models/pending.js.rb
@@ -168,6 +168,9 @@ class Pending
     localStorage.setItem(Pending.offline_var, status.to_s)
     Server.offline = (status.to_s == 'true')
     Main.refresh()
+
+    event = CustomEvent.new('offlineStatus', detail: Server.offline)
+    window.dispatchEvent(event)
   end
 
   # synchronize offline status with other windows
@@ -185,6 +188,9 @@ class Pending
       window.addEventListener :storage do |event|
 	if event.key == Pending.offline_var
 	  Server.offline = (event.newValue == 'true')
+
+          event = CustomEvent.new('offlineStatus', detail: Server.offline)
+          window.dispatchEvent(event)
 	end
       end
     end

-- 
To stop receiving notification emails like this one, please contact
"commits@whimsical.apache.org" <co...@whimsical.apache.org>.