Class: MadChatter::Servers::EventMachineWebSocket
- Inherits:
-
Object
- Object
- MadChatter::Servers::EventMachineWebSocket
- Defined in:
- lib/mad_chatter/servers/em_websocket.rb
Instance Method Summary collapse
-
#initialize(port, main_server) ⇒ EventMachineWebSocket
constructor
A new instance of EventMachineWebSocket.
- #start ⇒ Object
Constructor Details
#initialize(port, main_server) ⇒ EventMachineWebSocket
Returns a new instance of EventMachineWebSocket.
7 8 9 10 11 12 13 |
# File 'lib/mad_chatter/servers/em_websocket.rb', line 7 def initialize(port, main_server) @main_server = main_server @config = { :host => '0.0.0.0', :port => port } end |
Instance Method Details
#start ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mad_chatter/servers/em_websocket.rb', line 15 def start EventMachine::WebSocket.start(@config) do |ws| ws.onopen do user = MadChatter::User.new user.on_send { |msg| ws.send(msg) } ws.onclose { user.disconnected } ws. { |msg| MadChatter.(msg) } user.connected end end end |