|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
class LongPollingController < ApplicationController
|
|
|
skip_before_action :session_update # prevent race conditions
|
|
|
+ prepend_before_action :authentication_check_only
|
|
|
|
|
|
# GET /api/v1/message_send
|
|
|
def message_send
|
|
@@ -14,24 +15,22 @@ class LongPollingController < ApplicationController
|
|
|
client_id = client_id_gen
|
|
|
log 'new client connection', client_id
|
|
|
end
|
|
|
- if !params['data']
|
|
|
- params['data'] = {}
|
|
|
- end
|
|
|
+ data = params['data'].permit!.to_h
|
|
|
session_data = {}
|
|
|
if current_user&.id
|
|
|
session_data = { 'id' => current_user.id }
|
|
|
end
|
|
|
|
|
|
# spool messages for new connects
|
|
|
- if params['data']['spool']
|
|
|
- Sessions.spool_create(params['data'])
|
|
|
+ if data['spool']
|
|
|
+ Sessions.spool_create(data)
|
|
|
end
|
|
|
- if params['data']['event'] == 'login'
|
|
|
+ if data['event'] == 'login'
|
|
|
Sessions.create(client_id, session_data, { type: 'ajax' })
|
|
|
- elsif params['data']['event']
|
|
|
+ elsif data['event']
|
|
|
message = Sessions::Event.run(
|
|
|
- event: params['data']['event'],
|
|
|
- payload: params['data'],
|
|
|
+ event: data['event'],
|
|
|
+ payload: data,
|
|
|
session: session_data,
|
|
|
client_id: client_id,
|
|
|
clients: {},
|
|
@@ -41,15 +40,15 @@ class LongPollingController < ApplicationController
|
|
|
Sessions.send(client_id, message)
|
|
|
end
|
|
|
else
|
|
|
- log "unknown message '#{params['data'].inspect}'", client_id
|
|
|
+ log "unknown message '#{data.inspect}'", client_id
|
|
|
end
|
|
|
|
|
|
if new_connection
|
|
|
result = { client_id: client_id }
|
|
|
render json: result
|
|
|
- else
|
|
|
- render json: {}
|
|
|
+ return
|
|
|
end
|
|
|
+ render json: {}
|
|
|
end
|
|
|
|
|
|
# GET /api/v1/message_receive
|
|
@@ -110,7 +109,7 @@ class LongPollingController < ApplicationController
|
|
|
params[:client_id].to_s
|
|
|
end
|
|
|
|
|
|
- def log( data, client_id = '-' )
|
|
|
+ def log(data, client_id = '-')
|
|
|
logger.info "client(#{client_id}) #{data}"
|
|
|
end
|
|
|
end
|