Fixed use of last_ping.
This commit is contained in:
parent
94a3797f53
commit
b7ecd9a1eb
2 changed files with 7 additions and 7 deletions
|
@ -35,7 +35,7 @@ returns
|
||||||
session_file = "#{path_tmp}/session"
|
session_file = "#{path_tmp}/session"
|
||||||
|
|
||||||
# collect session data
|
# collect session data
|
||||||
meta[:last_ping] = Time.now.utc.to_i.to_s
|
meta[:last_ping] = Time.now.utc.to_i
|
||||||
data = {
|
data = {
|
||||||
user: session,
|
user: session,
|
||||||
meta: meta,
|
meta: meta,
|
||||||
|
@ -215,7 +215,7 @@ returns
|
||||||
data = get(client_id)
|
data = get(client_id)
|
||||||
return false if !data
|
return false if !data
|
||||||
path = "#{@path}/#{client_id}"
|
path = "#{@path}/#{client_id}"
|
||||||
data[:meta][:last_ping] = Time.now.utc.to_i.to_s
|
data[:meta][:last_ping] = Time.now.utc.to_i
|
||||||
content = data.to_json
|
content = data.to_json
|
||||||
File.open( path + '/session', 'wb' ) { |file|
|
File.open( path + '/session', 'wb' ) { |file|
|
||||||
file.write content
|
file.write content
|
||||||
|
|
|
@ -96,7 +96,7 @@ EventMachine.run {
|
||||||
if !@clients.include? client_id
|
if !@clients.include? client_id
|
||||||
@clients[client_id] = {
|
@clients[client_id] = {
|
||||||
websocket: ws,
|
websocket: ws,
|
||||||
last_ping: Time.now.utc.iso8601,
|
last_ping: Time.now.utc.to_i,
|
||||||
error_count: 0,
|
error_count: 0,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -176,7 +176,7 @@ EventMachine.run {
|
||||||
# remember ping, send pong back
|
# remember ping, send pong back
|
||||||
elsif data['action'] == 'ping'
|
elsif data['action'] == 'ping'
|
||||||
Sessions.touch(client_id)
|
Sessions.touch(client_id)
|
||||||
@clients[client_id][:last_ping] = Time.now.utc.iso8601
|
@clients[client_id][:last_ping] = Time.now.utc.to_i
|
||||||
@clients[client_id][:websocket].send( '[{"action":"pong"}]' )
|
@clients[client_id][:websocket].send( '[{"action":"pong"}]' )
|
||||||
|
|
||||||
# broadcast
|
# broadcast
|
||||||
|
@ -299,7 +299,7 @@ EventMachine.run {
|
||||||
# close unused web socket sessions
|
# close unused web socket sessions
|
||||||
@clients.each { |client_id, client|
|
@clients.each { |client_id, client|
|
||||||
|
|
||||||
next if ( client[:last_ping] + idle_time_in_sec ) >= Time.now.utc.iso8601
|
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 'notice', 'closing idle websocket connection', client_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue