* all messages are finally binary encoded
This commit is contained in:
parent
59664caa39
commit
484b5f7496
|
|
@ -22,4 +22,4 @@ end
|
|||
Logging.logger.root.appenders = Logging.appenders.stdout
|
||||
|
||||
ActiveRecord::Base.establish_connection(db_config)
|
||||
Server.new.run :port => config["port"], :debug => true# config["debug"]
|
||||
Server.new.run :port => config["port"], :emwebsocket_debug => config["emwebsocket_debug"]
|
||||
|
|
|
|||
|
|
@ -129,9 +129,9 @@ module JamWebsockets
|
|||
@log.debug "received user-directed message for session: #{user_id}"
|
||||
|
||||
contexts.each do |context|
|
||||
@log.debug "sending user message to #{context}"
|
||||
EM.schedule do
|
||||
context.client.instance_variable_get(:@handler).send_frame(:binary, msg)
|
||||
@log.debug "sending user message to #{context}"
|
||||
send_to_client(context.client, msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -161,11 +161,9 @@ module JamWebsockets
|
|||
@log.debug "received session-directed message for session: #{session_id}"
|
||||
|
||||
contexts.each do |context|
|
||||
@log.debug "sending session message to #{context}"
|
||||
EM.schedule do
|
||||
@log.debug "ONTUHNOTEHU"
|
||||
context.client.instance_variable_get(:@handler).send_frame(:binary, msg)
|
||||
@log.debug "gross"
|
||||
@log.debug "sending session message to #{context}"
|
||||
send_to_client(context.client, msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -177,6 +175,11 @@ module JamWebsockets
|
|||
end
|
||||
end
|
||||
|
||||
def send_to_client(client, msg)
|
||||
# this is so odd that this is necessary. but searching through the source code... it's all I could find in em-websocket
|
||||
client.instance_variable_get(:@handler).send_frame(:binary, msg)
|
||||
end
|
||||
|
||||
def cleanup()
|
||||
# shutdown topic listeners and mq connection
|
||||
begin
|
||||
|
|
@ -257,7 +260,8 @@ module JamWebsockets
|
|||
@log.info "ending client session deliberately due to malformed client behavior. reason=#{e}"
|
||||
begin
|
||||
# wrap the message up and send it down
|
||||
client.send(@message_factory.server_rejection_error(e.to_s).to_s)
|
||||
error_msg = @message_factory.server_rejection_error(e.to_s).to_s
|
||||
send_to_client(client, error_msg)
|
||||
ensure
|
||||
client.close_websocket
|
||||
cleanup_client(client)
|
||||
|
|
@ -268,7 +272,8 @@ module JamWebsockets
|
|||
|
||||
begin
|
||||
# wrap the message up and send it down
|
||||
client.send(@message_factory.server_generic_error(e.to_s).to_s)
|
||||
error_msg = @message_factory.server_generic_error(e.to_s).to_s
|
||||
send_to_client(client, error_msg)
|
||||
ensure
|
||||
client.close_websocket
|
||||
cleanup_client(client)
|
||||
|
|
@ -374,7 +379,8 @@ module JamWebsockets
|
|||
@log.debug "user #{user.email} logged in"
|
||||
|
||||
# respond with LOGIN_ACK to let client know it was successful
|
||||
client.send(@message_factory.login_ack(client.request["origin"]).to_s)
|
||||
login_ack = @message_factory.login_ack(client.request["origin"]).to_s
|
||||
send_to_client(client, login_ack)
|
||||
|
||||
# remove from pending_queue
|
||||
@semaphore.synchronize do
|
||||
|
|
@ -415,13 +421,15 @@ module JamWebsockets
|
|||
rescue => e
|
||||
# send back a failure ack and bail
|
||||
@log.debug "client requested non-existent session. client:#{client.request['origin']} user:#{context.user.email}"
|
||||
client.send(@message_factory.login_jam_session_ack(true, e.to_s).to_s)
|
||||
login_jam_session = @message_factory.login_jam_session_ack(true, e.to_s).to_s
|
||||
send_to_client(client, login_jam_session)
|
||||
return
|
||||
end
|
||||
|
||||
# respond with LOGIN_JAM_SESSION_ACK to let client know it was successful
|
||||
client.send(@message_factory.login_jam_session_ack(false, nil).to_s)
|
||||
|
||||
login_jam_session = @message_factory.login_jam_session_ack(false, nil).to_s
|
||||
send_to_client(client, login_jam_session)
|
||||
|
||||
# send 'new client' message to other members in the session
|
||||
handle_session_directed(session_id,
|
||||
@message_factory.user_joined_jam_session(context.user.id, context.user.name),
|
||||
|
|
|
|||
Loading…
Reference in New Issue