Module: PalavaMachine::Server::CoreSupport
- Defined in:
- lib/palava_machine/server/core_support.rb
Instance Method Summary collapse
- #em_init_pm ⇒ Object
- #send_error(ws, e) ⇒ Object
- #stop!(timeout = options[:shutdown_timeout]) ⇒ Object
- #ws_close_unannounce(ws) ⇒ Object
- #ws_message_action(ws, event) ⇒ Object
- #ws_message_parse(ws, message) ⇒ Object
- #ws_open_announce(ws) ⇒ Object
Instance Method Details
#em_init_pm ⇒ Object
22 23 24 25 |
# File 'lib/palava_machine/server/core_support.rb', line 22 def em_init_pm manager.info "Starting RTC Socket Server on port #{[:port]}" manager.initialize_in_em end |
#send_error(ws, e) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/palava_machine/server/core_support.rb', line 27 def send_error(ws, e) ws.send_text({ event: 'error', message: e. }.to_json) # TODO deactivate message in production? end |
#stop!(timeout = options[:shutdown_timeout]) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/palava_machine/server/core_support.rb', line 34 def stop!(timeout = [:shutdown_timeout]) manager.warn "Stopping Machine" if timeout.to_i == 0 manager.shutdown! EM.stop else manager.announce_shutdown(timeout) EM.next_tick do manager.shutdown!(timeout) EM.stop end end end |
#ws_close_unannounce(ws) ⇒ Object
18 19 20 |
# File 'lib/palava_machine/server/core_support.rb', line 18 def ws_close_unannounce(ws) manager.unannounce_connection(ws) end |
#ws_message_action(ws, event) ⇒ Object
13 14 15 16 |
# File 'lib/palava_machine/server/core_support.rb', line 13 def (ws, event) manager.debug "#{event.connection_id} <#{event.name}>" manager.public_send(event.name, event.connection_id, *event.arguments) end |
#ws_message_parse(ws, message) ⇒ Object
8 9 10 11 |
# File 'lib/palava_machine/server/core_support.rb', line 8 def (ws, ) connection_id = manager.connections.get_connection_id(ws) or raise MessageError.new(ws), 'unknown connection' ClientMessage.new(, connection_id) end |
#ws_open_announce(ws) ⇒ Object
4 5 6 |
# File 'lib/palava_machine/server/core_support.rb', line 4 def ws_open_announce(ws) manager.announce_connection(ws) end |