From 35e12c58a5bd2add903c7eb5d854d1dbab30bb01 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 22 Jun 2013 19:00:58 +0200 Subject: [PATCH] Moved from integers to strings for client_id's for keep code simpler. --- app/controllers/long_polling_controller.rb | 6 +++--- lib/session.rb | 2 +- script/websocket-server.rb | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 89ce5e723..62de0857a 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -67,7 +67,7 @@ class LongPollingController < ApplicationController # list all current clients client_list = Session.list client_list.each {|local_client_id, local_client| - if local_client_id.to_s != client_id.to_s + if local_client_id != client_id # broadcast to recipient list if params['data']['data']['recipient'] && params['data']['data']['recipient']['user_id'] @@ -139,11 +139,11 @@ class LongPollingController < ApplicationController private def client_id_check - return params[:client_id] if params[:client_id] + return params[:client_id].to_s if params[:client_id] return end def client_id_gen - rand(99999999) + rand(9999999999).to_s end def client_id_verify return if !params[:client_id] diff --git a/lib/session.rb b/lib/session.rb index 9f2daab56..2fac3e874 100644 --- a/lib/session.rb +++ b/lib/session.rb @@ -257,7 +257,7 @@ module Session data = [] Dir.foreach( path ) do |entry| next if entry == '.' || entry == '..' || entry == 'spool' - data.push entry + data.push entry.to_s end return data end diff --git a/script/websocket-server.rb b/script/websocket-server.rb index d56f5b807..72f067cf8 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -89,8 +89,9 @@ EventMachine.run { # register client connection ws.onopen { - client_id = ws.object_id + client_id = ws.object_id.to_s log 'notice', 'Client connected.', client_id + Session.create( client_id, {}, { :type => 'websocket' } ) if !@clients.include? client_id @clients[client_id] = { @@ -103,7 +104,7 @@ EventMachine.run { # unregister client connection ws.onclose { - client_id = ws.object_id + client_id = ws.object_id.to_s log 'notice', 'Client disconnected.', client_id # removed from current client list @@ -117,7 +118,7 @@ EventMachine.run { # manage messages ws.onmessage { |msg| - client_id = ws.object_id + client_id = ws.object_id.to_s log 'debug', "received message: #{ msg } ", client_id begin data = JSON.parse(msg) @@ -174,7 +175,7 @@ EventMachine.run { # list all current clients client_list = Session.list client_list.each {|local_client_id, local_client| - if local_client_id.to_s != client_id.to_s + if local_client_id != client_id # broadcast to recipient list if data['data']['recipient'] if data['data']['recipient'].class != Hash @@ -269,7 +270,7 @@ EventMachine.run { # disconnect client client[:error_count] += 1 - if client[:error_count] > 100 + if client[:error_count] > 20 if @clients.include? client_id @clients.delete client_id end