Renamed Session module to Sessions to avoid conflicts with active record Session module.
This commit is contained in:
parent
977acf0a52
commit
0eccb81fbc
5 changed files with 37 additions and 35 deletions
|
@ -26,7 +26,7 @@ class LongPollingController < ApplicationController
|
||||||
# spool messages for new connects
|
# spool messages for new connects
|
||||||
if params['data']['spool']
|
if params['data']['spool']
|
||||||
msg = JSON.generate( params['data'] )
|
msg = JSON.generate( params['data'] )
|
||||||
Session.spool_create(msg)
|
Sessions.spool_create(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
# get spool messages and send them to new client connection
|
# get spool messages and send them to new client connection
|
||||||
|
@ -40,14 +40,14 @@ class LongPollingController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_user
|
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|
|
spool.each { |item|
|
||||||
if item[:type] == 'direct'
|
if item[:type] == 'direct'
|
||||||
log 'notice', "send spool to (user_id=#{ current_user.id })", client_id
|
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
|
else
|
||||||
log 'notice', "send spool", client_id
|
log 'notice', "send spool", client_id
|
||||||
Session.send( client_id, item[:message] )
|
Sessions.send( client_id, item[:message] )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -55,7 +55,7 @@ class LongPollingController < ApplicationController
|
||||||
# send spool:sent event to client
|
# send spool:sent event to client
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
log 'notice', "send spool:sent event", client_id
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,13 +67,13 @@ class LongPollingController < ApplicationController
|
||||||
user = User.user_data_full( user_id )
|
user = User.user_data_full( user_id )
|
||||||
end
|
end
|
||||||
log 'notice', "send auth login (user_id #{user_id})", client_id
|
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
|
# broadcast
|
||||||
elsif params['data']['action'] == 'broadcast'
|
elsif params['data']['action'] == 'broadcast'
|
||||||
|
|
||||||
# list all current clients
|
# list all current clients
|
||||||
client_list = Session.list
|
client_list = Sessions.list
|
||||||
client_list.each {|local_client_id, local_client|
|
client_list.each {|local_client_id, local_client|
|
||||||
if local_client_id != client_id
|
if local_client_id != client_id
|
||||||
|
|
||||||
|
@ -82,13 +82,13 @@ class LongPollingController < ApplicationController
|
||||||
params['data']['recipient']['user_id'].each { |user_id|
|
params['data']['recipient']['user_id'].each { |user_id|
|
||||||
if local_client[:user][:id] == 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
|
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
|
end
|
||||||
}
|
}
|
||||||
# broadcast every client
|
# broadcast every client
|
||||||
else
|
else
|
||||||
log 'notice', "send broadcast from (#{client_id.to_s})", local_client_id
|
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
|
end
|
||||||
else
|
else
|
||||||
log 'notice', "do not send broadcast to it self", client_id
|
log 'notice', "do not send broadcast to it self", client_id
|
||||||
|
@ -119,13 +119,13 @@ class LongPollingController < ApplicationController
|
||||||
|
|
||||||
# update last ping
|
# update last ping
|
||||||
sleep 1
|
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
|
# set max loop time to 24 sec. because of 30 sec. timeout of mod_proxy
|
||||||
count = 12
|
count = 12
|
||||||
while true
|
while true
|
||||||
count = count - 1
|
count = count - 1
|
||||||
queue = Session.queue( client_id )
|
queue = Sessions.queue( client_id )
|
||||||
if queue && queue[0]
|
if queue && queue[0]
|
||||||
# puts "send " + queue.inspect + client_id.to_s
|
# puts "send " + queue.inspect + client_id.to_s
|
||||||
render :json => queue
|
render :json => queue
|
||||||
|
@ -155,7 +155,7 @@ class LongPollingController < ApplicationController
|
||||||
end
|
end
|
||||||
def client_id_verify
|
def client_id_verify
|
||||||
return if !params[:client_id]
|
return if !params[:client_id]
|
||||||
sessions = Session.sessions
|
sessions = Sessions.sessions
|
||||||
return if !sessions.include?( params[:client_id].to_s )
|
return if !sessions.include?( params[:client_id].to_s )
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
require 'ticket/overviews'
|
||||||
|
|
||||||
class TicketOverviewsController < ApplicationController
|
class TicketOverviewsController < ApplicationController
|
||||||
before_filter :authentication_check
|
before_filter :authentication_check
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'cache'
|
require 'cache'
|
||||||
require 'user_info'
|
require 'user_info'
|
||||||
require 'session'
|
require 'sessions'
|
||||||
|
|
||||||
class ApplicationModel < ActiveRecord::Base
|
class ApplicationModel < ActiveRecord::Base
|
||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
|
@ -340,7 +340,7 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
class_name = self.class.name
|
class_name = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Session.broadcast(
|
Sessions.broadcast(
|
||||||
:event => class_name + ':created',
|
:event => class_name + ':created',
|
||||||
:data => { :id => self.id, :updated_at => self.updated_at }
|
: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
|
puts "#{self.class.name.downcase} UPDATED " + self.updated_at.to_s
|
||||||
class_name = self.class.name
|
class_name = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Session.broadcast(
|
Sessions.broadcast(
|
||||||
:event => class_name + ':updated',
|
:event => class_name + ':updated',
|
||||||
:data => { :id => self.id, :updated_at => self.updated_at }
|
: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
|
puts "#{self.class.name.downcase} DESTOY " + self.updated_at.to_s
|
||||||
class_name = self.class.name
|
class_name = self.class.name
|
||||||
class_name.gsub!(/::/, '')
|
class_name.gsub!(/::/, '')
|
||||||
Session.broadcast(
|
Sessions.broadcast(
|
||||||
:event => class_name + ':destroy',
|
:event => class_name + ':destroy',
|
||||||
:data => { :id => self.id, :updated_at => self.updated_at }
|
:data => { :id => self.id, :updated_at => self.updated_at }
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'json'
|
||||||
require 'rss'
|
require 'rss'
|
||||||
require 'session_helper'
|
require 'session_helper'
|
||||||
|
|
||||||
module Session
|
module Sessions
|
||||||
|
|
||||||
# get application root directory
|
# get application root directory
|
||||||
@root = Dir.pwd.to_s
|
@root = Dir.pwd.to_s
|
||||||
|
@ -205,7 +205,7 @@ module Session
|
||||||
next if @@client_threads[client_id]
|
next if @@client_threads[client_id]
|
||||||
|
|
||||||
# get current user
|
# get current user
|
||||||
session_data = Session.get( client_id )
|
session_data = Sessions.get( client_id )
|
||||||
next if !session_data
|
next if !session_data
|
||||||
next if !session_data[:user]
|
next if !session_data[:user]
|
||||||
next if !session_data[:user][:id]
|
next if !session_data[:user][:id]
|
||||||
|
@ -272,7 +272,7 @@ module Session
|
||||||
files.sort.each {|entry|
|
files.sort.each {|entry|
|
||||||
filename = path + '/' + entry
|
filename = path + '/' + entry
|
||||||
if /^send/.match( entry )
|
if /^send/.match( entry )
|
||||||
data.push Session.queue_file( path, entry )
|
data.push Sessions.queue_file( path, entry )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
@ -297,7 +297,7 @@ module Session
|
||||||
# list all current clients
|
# list all current clients
|
||||||
client_list = self.list
|
client_list = self.list
|
||||||
client_list.each {|local_client_id, local_client|
|
client_list.each {|local_client_id, local_client|
|
||||||
Session.send( local_client_id, data )
|
Sessions.send( local_client_id, data )
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -552,7 +552,7 @@ class ClientState
|
||||||
while true
|
while true
|
||||||
|
|
||||||
# get connection user
|
# get connection user
|
||||||
session_data = Session.get( @client_id )
|
session_data = Sessions.get( @client_id )
|
||||||
return if !session_data
|
return if !session_data
|
||||||
return if !session_data[:user]
|
return if !session_data[:user]
|
||||||
return if !session_data[:user][:id]
|
return if !session_data[:user][:id]
|
||||||
|
@ -849,7 +849,7 @@ class ClientState
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
def send( data )
|
def send( data )
|
||||||
Session.send( @client_id, data )
|
Sessions.send( @client_id, data )
|
||||||
end
|
end
|
||||||
|
|
||||||
def log( level, data )
|
def log( level, data )
|
|
@ -8,7 +8,7 @@ require 'eventmachine'
|
||||||
require 'em-websocket'
|
require 'em-websocket'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'session'
|
require 'sessions'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'daemons'
|
require 'daemons'
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ EventMachine.run {
|
||||||
ws.onopen {
|
ws.onopen {
|
||||||
client_id = ws.object_id.to_s
|
client_id = ws.object_id.to_s
|
||||||
log 'notice', 'Client connected.', client_id
|
log 'notice', 'Client connected.', client_id
|
||||||
Session.create( client_id, {}, { :type => 'websocket' } )
|
Sessions.create( client_id, {}, { :type => 'websocket' } )
|
||||||
|
|
||||||
if !@clients.include? client_id
|
if !@clients.include? client_id
|
||||||
@clients[client_id] = {
|
@clients[client_id] = {
|
||||||
|
@ -112,7 +112,7 @@ EventMachine.run {
|
||||||
@clients.delete client_id
|
@clients.delete client_id
|
||||||
end
|
end
|
||||||
|
|
||||||
Session.destory( client_id )
|
Sessions.destory( client_id )
|
||||||
}
|
}
|
||||||
|
|
||||||
# manage messages
|
# manage messages
|
||||||
|
@ -132,7 +132,7 @@ EventMachine.run {
|
||||||
|
|
||||||
# spool messages for new connects
|
# spool messages for new connects
|
||||||
if data['spool']
|
if data['spool']
|
||||||
Session.spool_create(msg)
|
Sessions.spool_create(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
# get spool messages and send them to new client connection
|
# get spool messages and send them to new client connection
|
||||||
|
@ -146,7 +146,7 @@ EventMachine.run {
|
||||||
end
|
end
|
||||||
|
|
||||||
if @clients[client_id] && @clients[client_id][:session] && @clients[client_id][:session]['id']
|
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|
|
spool.each { |item|
|
||||||
|
|
||||||
# create new msg to push to client
|
# create new msg to push to client
|
||||||
|
@ -171,7 +171,7 @@ EventMachine.run {
|
||||||
# get session
|
# get session
|
||||||
if data['action'] == 'login'
|
if data['action'] == 'login'
|
||||||
@clients[client_id][:session] = data['session']
|
@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
|
# remember ping, send pong back
|
||||||
elsif data['action'] == 'ping'
|
elsif data['action'] == 'ping'
|
||||||
|
@ -182,7 +182,7 @@ EventMachine.run {
|
||||||
elsif data['action'] == 'broadcast'
|
elsif data['action'] == 'broadcast'
|
||||||
|
|
||||||
# list all current clients
|
# list all current clients
|
||||||
client_list = Session.list
|
client_list = Sessions.list
|
||||||
client_list.each {|local_client_id, local_client|
|
client_list.each {|local_client_id, local_client|
|
||||||
if local_client_id != client_id
|
if local_client_id != client_id
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ EventMachine.run {
|
||||||
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
||||||
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
||||||
else
|
else
|
||||||
Session.send( local_client_id, data )
|
Sessions.send( local_client_id, data )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ EventMachine.run {
|
||||||
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
||||||
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
@clients[ local_client_id ][:websocket].send( "[#{msg}]" )
|
||||||
else
|
else
|
||||||
Session.send( local_client_id, data )
|
Sessions.send( local_client_id, data )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -247,7 +247,7 @@ EventMachine.run {
|
||||||
}
|
}
|
||||||
|
|
||||||
# ajax
|
# ajax
|
||||||
client_list = Session.list
|
client_list = Sessions.list
|
||||||
clients = 0
|
clients = 0
|
||||||
client_list.each {|client_id, client|
|
client_list.each {|client_id, client|
|
||||||
next if client[:meta][:type] == 'websocket'
|
next if client[:meta][:type] == 'websocket'
|
||||||
|
@ -268,7 +268,7 @@ EventMachine.run {
|
||||||
next if client[:disconnect]
|
next if client[:disconnect]
|
||||||
log 'debug', 'checking for data...', client_id
|
log 'debug', 'checking for data...', client_id
|
||||||
begin
|
begin
|
||||||
queue = Session.queue( client_id )
|
queue = Sessions.queue( client_id )
|
||||||
if queue && queue[0]
|
if queue && queue[0]
|
||||||
# log "send " + queue.inspect, client_id
|
# log "send " + queue.inspect, client_id
|
||||||
log 'notice', "send data to client", client_id
|
log 'notice', "send data to client", client_id
|
||||||
|
@ -312,12 +312,12 @@ EventMachine.run {
|
||||||
}
|
}
|
||||||
|
|
||||||
# ajax
|
# ajax
|
||||||
clients = Session.list
|
clients = Sessions.list
|
||||||
clients.each { |client_id, client|
|
clients.each { |client_id, client|
|
||||||
next if client[:meta][:type] == 'websocket'
|
next if client[:meta][:type] == 'websocket'
|
||||||
if ( client[:meta][:last_ping].to_i + ( 60 * idle_time_in_min ) ) < Time.now.to_i
|
if ( client[:meta][:last_ping].to_i + ( 60 * idle_time_in_min ) ) < Time.now.to_i
|
||||||
log 'notice', "closing idle ajax connection", client_id
|
log 'notice', "closing idle ajax connection", client_id
|
||||||
Session.destory( client_id )
|
Sessions.destory( client_id )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue