|
@@ -49,7 +49,7 @@ class WebsocketServer
|
|
def self.onopen(websocket, handshake)
|
|
def self.onopen(websocket, handshake)
|
|
headers = handshake.headers
|
|
headers = handshake.headers
|
|
client_id = websocket.object_id.to_s
|
|
client_id = websocket.object_id.to_s
|
|
- log 'notice', 'Client connected.', client_id
|
|
|
|
|
|
+ log 'info', 'Client connected.', client_id
|
|
Sessions.create( client_id, {}, { type: 'websocket' } )
|
|
Sessions.create( client_id, {}, { type: 'websocket' } )
|
|
|
|
|
|
return if @clients.include? client_id
|
|
return if @clients.include? client_id
|
|
@@ -64,7 +64,7 @@ class WebsocketServer
|
|
|
|
|
|
def self.onclose(websocket)
|
|
def self.onclose(websocket)
|
|
client_id = websocket.object_id.to_s
|
|
client_id = websocket.object_id.to_s
|
|
- log 'notice', 'Client disconnected.', client_id
|
|
|
|
|
|
+ log 'info', 'Client disconnected.', client_id
|
|
|
|
|
|
# removed from current client list
|
|
# removed from current client list
|
|
if @clients.include? client_id
|
|
if @clients.include? client_id
|
|
@@ -129,7 +129,7 @@ class WebsocketServer
|
|
end
|
|
end
|
|
|
|
|
|
def self.check_unused_connections
|
|
def self.check_unused_connections
|
|
- log 'notice', 'check unused idle connections...'
|
|
|
|
|
|
+ log 'info', 'check unused idle connections...'
|
|
|
|
|
|
idle_time_in_sec = 4 * 60
|
|
idle_time_in_sec = 4 * 60
|
|
|
|
|
|
@@ -138,7 +138,7 @@ class WebsocketServer
|
|
|
|
|
|
next if ( client[:last_ping].to_i + idle_time_in_sec ) >= Time.now.utc.to_i
|
|
next if ( client[:last_ping].to_i + idle_time_in_sec ) >= Time.now.utc.to_i
|
|
|
|
|
|
- log 'notice', 'closing idle websocket connection', client_id
|
|
|
|
|
|
+ log 'info', 'closing idle websocket connection', client_id
|
|
|
|
|
|
# remember to not use this connection anymore
|
|
# remember to not use this connection anymore
|
|
client[:disconnect] = true
|
|
client[:disconnect] = true
|
|
@@ -154,7 +154,7 @@ class WebsocketServer
|
|
# close unused ajax long polling sessions
|
|
# close unused ajax long polling sessions
|
|
clients = Sessions.destroy_idle_sessions(idle_time_in_sec)
|
|
clients = Sessions.destroy_idle_sessions(idle_time_in_sec)
|
|
clients.each do |client_id|
|
|
clients.each do |client_id|
|
|
- log 'notice', 'closing idle long polling connection', client_id
|
|
|
|
|
|
+ log 'info', 'closing idle long polling connection', client_id
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
@@ -170,7 +170,7 @@ class WebsocketServer
|
|
queue = Sessions.queue(client_id)
|
|
queue = Sessions.queue(client_id)
|
|
next if queue.blank?
|
|
next if queue.blank?
|
|
|
|
|
|
- log 'notice', 'send data to client', client_id
|
|
|
|
|
|
+ log 'info', 'send data to client', client_id
|
|
websocket_send(client_id, queue)
|
|
websocket_send(client_id, queue)
|
|
rescue => e
|
|
rescue => e
|
|
log 'error', "problem:#{e.inspect}", client_id
|
|
log 'error', "problem:#{e.inspect}", client_id
|
|
@@ -186,9 +186,9 @@ class WebsocketServer
|
|
|
|
|
|
def self.log_status
|
|
def self.log_status
|
|
# websocket
|
|
# websocket
|
|
- log 'notice', "Status: websocket clients: #{@clients.size}"
|
|
|
|
|
|
+ log 'info', "Status: websocket clients: #{@clients.size}"
|
|
@clients.each_key do |client_id|
|
|
@clients.each_key do |client_id|
|
|
- log 'notice', 'working...', client_id
|
|
|
|
|
|
+ log 'info', 'working...', client_id
|
|
end
|
|
end
|
|
|
|
|
|
# ajax
|
|
# ajax
|
|
@@ -199,11 +199,11 @@ class WebsocketServer
|
|
|
|
|
|
clients = clients + 1
|
|
clients = clients + 1
|
|
end
|
|
end
|
|
- log 'notice', "Status: ajax clients: #{clients}"
|
|
|
|
|
|
+ log 'info', "Status: ajax clients: #{clients}"
|
|
client_list.each do |client_id, client|
|
|
client_list.each do |client_id, client|
|
|
next if client[:meta][:type] == 'websocket'
|
|
next if client[:meta][:type] == 'websocket'
|
|
|
|
|
|
- log 'notice', 'working...', client_id
|
|
|
|
|
|
+ log 'info', 'working...', client_id
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|