Fixed use of last_ping.

This commit is contained in:
Martin Edenhofer 2015-05-10 22:53:15 +02:00
parent 94a3797f53
commit b7ecd9a1eb
2 changed files with 7 additions and 7 deletions

View file

@ -35,7 +35,7 @@ returns
session_file = "#{path_tmp}/session"
# collect session data
meta[:last_ping] = Time.now.utc.to_i.to_s
meta[:last_ping] = Time.now.utc.to_i
data = {
user: session,
meta: meta,
@ -215,7 +215,7 @@ returns
data = get(client_id)
return false if !data
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
File.open( path + '/session', 'wb' ) { |file|
file.write content
@ -264,7 +264,7 @@ returns
file.flock( File::LOCK_UN )
data_json = JSON.parse( all )
if data_json
data = symbolize_keys(data_json)
data = symbolize_keys(data_json)
data[:user] = data_json['user'] # for compat. reasons
end
}

View file

@ -95,8 +95,8 @@ EventMachine.run {
if !@clients.include? client_id
@clients[client_id] = {
websocket: ws,
last_ping: Time.now.utc.iso8601,
websocket: ws,
last_ping: Time.now.utc.to_i,
error_count: 0,
}
end
@ -176,7 +176,7 @@ EventMachine.run {
# remember ping, send pong back
elsif data['action'] == 'ping'
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"}]' )
# broadcast
@ -299,7 +299,7 @@ EventMachine.run {
# close unused web socket sessions
@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