whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: return list of attendees
Date Fri, 14 Oct 2016 13:20:55 GMT
This is an automated email from the ASF dual-hosted git repository.

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

The following commit(s) were added to refs/heads/master by this push:
       new  2609daa   return list of attendees
2609daa is described below

commit 2609daaec2dd1666e497320495b2e5cb7621d0a4
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Fri Oct 14 09:20:29 2016 -0400

    return list of attendees
---
 www/board/agenda/daemon/channel.rb         | 20 ++++++++++++++++----
 www/board/agenda/daemon/session.rb         |  2 +-
 www/board/agenda/models/ipc.rb             | 12 +++++++++++-
 www/board/agenda/views/models/events.js.rb |  6 +++---
 4 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/www/board/agenda/daemon/channel.rb b/www/board/agenda/daemon/channel.rb
index 0a5b967..df34f5f 100644
--- a/www/board/agenda/daemon/channel.rb
+++ b/www/board/agenda/daemon/channel.rb
@@ -6,18 +6,20 @@
 require 'json'
 require 'concurrent'
 
+require_relative './session'
+
 class Channel
   @@sockets = Concurrent::Map.new
   @@users = Concurrent::Map.new {|map,key| map[key]=[]}
 
   # add a new socket/userid pair
   def self.add(ws, id)
-    if @@users[id].empty?
+    @@users[id] << ws
+    @@sockets[ws] = id
+    if @@users[id].length == 1
       self.post_all(type: :arrive, user: id, present: self.present,
         timestamp: Time.now.to_f*1000)
     end
-    @@users[id] << ws
-    @@sockets[ws] = id
   end
 
   # send a message to a list of clients
@@ -57,7 +59,17 @@ class Channel
 
   # return a list of active users
   def self.present
-    @@users.keys
+    users = @@users.keys
+    path = File.join(Session::WORKDIR, 'present.yml')
+
+    File.open(path, File::RDWR|File::CREAT, 0644) do |fh|
+      fh.flock(File::LOCK_EX)
+      fh.write(YAML.dump(users))
+      fh.flush
+      fh.truncate(fh.pos)
+    end
+
+    users
   end
 
   # close all open sockets
diff --git a/www/board/agenda/daemon/session.rb b/www/board/agenda/daemon/session.rb
index 7e99dfd..4fbb8f3 100644
--- a/www/board/agenda/daemon/session.rb
+++ b/www/board/agenda/daemon/session.rb
@@ -70,10 +70,10 @@ class Session
         @@sessions.keys.map {|secret| File.join(WORKDIR, secret)}
 
       files.uniq.each do |file|
+        next if file =~ /\.yml$/
         secret = File.basename(file)
         session = @@sessions[secret]
 
-
         if File.exist? file
           if File.mtime(file) < Time.now - 2 * DAY
             File.delete file 
diff --git a/www/board/agenda/models/ipc.rb b/www/board/agenda/models/ipc.rb
index a87da8c..aea7e85 100644
--- a/www/board/agenda/models/ipc.rb
+++ b/www/board/agenda/models/ipc.rb
@@ -1,3 +1,5 @@
+require 'yaml'
+
 module IPC
 
   if Dir.exist? '/etc/letsencrypt'
@@ -31,7 +33,15 @@ module IPC
     end
   end
 
+  @@present = []
+  @@mtime = nil
   def self.present
-    [] # TBD
+    file = File.join(AGENDA_WORK, 'sessions', 'present.yml')
+    if not File.exist?(file) or File.mtime(file) == @@mtime
+      @@present
+    else
+      @@mtime = File.mtime(file)
+      @@present = YAML.load_file(file)
+    end
   end
 end
diff --git a/www/board/agenda/views/models/events.js.rb b/www/board/agenda/views/models/events.js.rb
index ddcbd06..f2c82ac 100644
--- a/www/board/agenda/views/models/events.js.rb
+++ b/www/board/agenda/views/models/events.js.rb
@@ -127,6 +127,7 @@ class Events
 
     def @@socket.onopen(event)
       @@socket.send "session: #{Server.session}\n\n"
+      console.log 'WebSocket connection established'
     end
 
     def @@socket.onmessage(event)
@@ -135,16 +136,15 @@ class Events
     end
 
     def @@socket.onerror(event)
-      console.log 'WebSocket connection terminated' unless @@socket
+      console.log 'WebSocket connection terminated' if @@socket
       @@socket = nil
     end
 
     def @@socket.onclose(event)
-      console.log 'WebSocket connection terminated' unless @@socket
+      console.log 'WebSocket connection terminated' if @@socket
       @@socket = nil
     end
 
-    console.log 'WebSocket connection established'
   rescue => e
     console.log e
   end

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

Mime
View raw message