diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 5903af634..ae4590672 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -26,7 +26,7 @@ class LongPollingController < ApplicationController # spool messages for new connects if params['data']['spool'] msg = JSON.generate( params['data'] ) - Session.spool_create(msg) + Sessions.spool_create(msg) end # get spool messages and send them to new client connection @@ -40,14 +40,14 @@ class LongPollingController < ApplicationController end if current_user - spool = Session.spool_list( params['data']['timestamp'], current_user.id ) + spool = Sessions.spool_list( params['data']['timestamp'], current_user.id ) spool.each { |item| if item[:type] == 'direct' log 'notice', "send spool to (user_id=#{ current_user.id })", client_id - Session.send( client_id, item[:message] ) + Sessions.send( client_id, item[:message] ) else log 'notice', "send spool", client_id - Session.send( client_id, item[:message] ) + Sessions.send( client_id, item[:message] ) end } end @@ -55,7 +55,7 @@ class LongPollingController < ApplicationController # send spool:sent event to client sleep 0.2 log 'notice', "send spool:sent event", client_id - Session.send( client_id, { :event => 'spool:sent', :data => { :timestamp => Time.now.utc.to_i } } ) + Sessions.send( client_id, { :event => 'spool:sent', :data => { :timestamp => Time.now.utc.to_i } } ) end @@ -67,13 +67,13 @@ class LongPollingController < ApplicationController user = User.user_data_full( user_id ) end log 'notice', "send auth login (user_id #{user_id})", client_id - Session.create( client_id, user, { :type => 'ajax' } ) + Sessions.create( client_id, user, { :type => 'ajax' } ) # broadcast elsif params['data']['action'] == 'broadcast' # list all current clients - client_list = Session.list + client_list = Sessions.list client_list.each {|local_client_id, local_client| if local_client_id != client_id @@ -82,13 +82,13 @@ class LongPollingController < ApplicationController params['data']['recipient']['user_id'].each { |user_id| if local_client[:user][:id] == user_id log 'notice', "send broadcast from (#{client_id.to_s}) to (user_id #{user_id})", local_client_id - Session.send( local_client_id, params['data'] ) + Sessions.send( local_client_id, params['data'] ) end } # broadcast every client else log 'notice', "send broadcast from (#{client_id.to_s})", local_client_id - Session.send( local_client_id, params['data'] ) + Sessions.send( local_client_id, params['data'] ) end else log 'notice', "do not send broadcast to it self", client_id @@ -119,13 +119,13 @@ class LongPollingController < ApplicationController # update last ping sleep 1 - Session.touch( client_id ) + Sessions.touch( client_id ) # set max loop time to 24 sec. because of 30 sec. timeout of mod_proxy count = 12 while true count = count - 1 - queue = Session.queue( client_id ) + queue = Sessions.queue( client_id ) if queue && queue[0] # puts "send " + queue.inspect + client_id.to_s render :json => queue @@ -155,7 +155,7 @@ class LongPollingController < ApplicationController end def client_id_verify return if !params[:client_id] - sessions = Session.sessions + sessions = Sessions.sessions return if !sessions.include?( params[:client_id].to_s ) return true end diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index c0f38de75..9433334c4 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -1,5 +1,7 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ +require 'ticket/overviews' + class TicketOverviewsController < ApplicationController before_filter :authentication_check diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 5ddeb65e5..b591d47f8 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -2,7 +2,7 @@ require 'cache' require 'user_info' -require 'session' +require 'sessions' class ApplicationModel < ActiveRecord::Base self.abstract_class = true @@ -340,7 +340,7 @@ class OwnModel < ApplicationModel class_name = self.class.name class_name.gsub!(/::/, '') - Session.broadcast( + Sessions.broadcast( :event => class_name + ':created', :data => { :id => self.id, :updated_at => self.updated_at } ) @@ -368,7 +368,7 @@ class OwnModel < ApplicationModel puts "#{self.class.name.downcase} UPDATED " + self.updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') - Session.broadcast( + Sessions.broadcast( :event => class_name + ':updated', :data => { :id => self.id, :updated_at => self.updated_at } ) @@ -395,7 +395,7 @@ class OwnModel < ApplicationModel puts "#{self.class.name.downcase} DESTOY " + self.updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') - Session.broadcast( + Sessions.broadcast( :event => class_name + ':destroy', :data => { :id => self.id, :updated_at => self.updated_at } ) diff --git a/lib/session.rb b/lib/sessions.rb similarity index 99% rename from lib/session.rb rename to lib/sessions.rb index 2b2f8b2f2..4c6f98903 100644 --- a/lib/session.rb +++ b/lib/sessions.rb @@ -2,7 +2,7 @@ require 'json' require 'rss' require 'session_helper' -module Session +module Sessions # get application root directory @root = Dir.pwd.to_s @@ -205,7 +205,7 @@ module Session next if @@client_threads[client_id] # get current user - session_data = Session.get( client_id ) + session_data = Sessions.get( client_id ) next if !session_data next if !session_data[:user] next if !session_data[:user][:id] @@ -272,7 +272,7 @@ module Session files.sort.each {|entry| filename = path + '/' + entry if /^send/.match( entry ) - data.push Session.queue_file( path, entry ) + data.push Sessions.queue_file( path, entry ) end } return data @@ -297,7 +297,7 @@ module Session # list all current clients client_list = self.list client_list.each {|local_client_id, local_client| - Session.send( local_client_id, data ) + Sessions.send( local_client_id, data ) } return true end @@ -552,7 +552,7 @@ class ClientState while true # get connection user - session_data = Session.get( @client_id ) + session_data = Sessions.get( @client_id ) return if !session_data return if !session_data[:user] return if !session_data[:user][:id] @@ -849,7 +849,7 @@ class ClientState # send update to browser def send( data ) - Session.send( @client_id, data ) + Sessions.send( @client_id, data ) end def log( level, data ) diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 449c5a1e5..2b487b54c 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -8,7 +8,7 @@ require 'eventmachine' require 'em-websocket' require 'json' require 'fileutils' -require 'session' +require 'sessions' require 'optparse' require 'daemons' @@ -91,7 +91,7 @@ EventMachine.run { ws.onopen { client_id = ws.object_id.to_s log 'notice', 'Client connected.', client_id - Session.create( client_id, {}, { :type => 'websocket' } ) + Sessions.create( client_id, {}, { :type => 'websocket' } ) if !@clients.include? client_id @clients[client_id] = { @@ -112,7 +112,7 @@ EventMachine.run { @clients.delete client_id end - Session.destory( client_id ) + Sessions.destory( client_id ) } # manage messages @@ -132,7 +132,7 @@ EventMachine.run { # spool messages for new connects if data['spool'] - Session.spool_create(msg) + Sessions.spool_create(msg) end # get spool messages and send them to new client connection @@ -146,7 +146,7 @@ EventMachine.run { end if @clients[client_id] && @clients[client_id][:session] && @clients[client_id][:session]['id'] - spool = Session.spool_list( data['timestamp'], @clients[client_id][:session]['id'] ) + spool = Sessions.spool_list( data['timestamp'], @clients[client_id][:session]['id'] ) spool.each { |item| # create new msg to push to client @@ -171,7 +171,7 @@ EventMachine.run { # get session if data['action'] == 'login' @clients[client_id][:session] = data['session'] - Session.create( client_id, data['session'], { :type => 'websocket' } ) + Sessions.create( client_id, data['session'], { :type => 'websocket' } ) # remember ping, send pong back elsif data['action'] == 'ping' @@ -182,7 +182,7 @@ EventMachine.run { elsif data['action'] == 'broadcast' # list all current clients - client_list = Session.list + client_list = Sessions.list client_list.each {|local_client_id, local_client| if local_client_id != client_id @@ -203,7 +203,7 @@ EventMachine.run { if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ] @clients[ local_client_id ][:websocket].send( "[#{msg}]" ) else - Session.send( local_client_id, data ) + Sessions.send( local_client_id, data ) end end } @@ -217,7 +217,7 @@ EventMachine.run { if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ] @clients[ local_client_id ][:websocket].send( "[#{msg}]" ) else - Session.send( local_client_id, data ) + Sessions.send( local_client_id, data ) end end else @@ -247,7 +247,7 @@ EventMachine.run { } # ajax - client_list = Session.list + client_list = Sessions.list clients = 0 client_list.each {|client_id, client| next if client[:meta][:type] == 'websocket' @@ -268,7 +268,7 @@ EventMachine.run { next if client[:disconnect] log 'debug', 'checking for data...', client_id begin - queue = Session.queue( client_id ) + queue = Sessions.queue( client_id ) if queue && queue[0] # log "send " + queue.inspect, client_id log 'notice', "send data to client", client_id @@ -312,12 +312,12 @@ EventMachine.run { } # ajax - clients = Session.list + clients = Sessions.list clients.each { |client_id, client| next if client[:meta][:type] == 'websocket' if ( client[:meta][:last_ping].to_i + ( 60 * idle_time_in_min ) ) < Time.now.to_i log 'notice', "closing idle ajax connection", client_id - Session.destory( client_id ) + Sessions.destory( client_id ) end } end