Sha256: b171f61bfd34ecbddc875249b5db0720314f50a38b3c2783e7a69b97a5b2054b

Contents?: true

Size: 656 Bytes

Versions: 5

Compression:

Stored size: 656 Bytes

Contents

require 'em-websocket'

module MadChatter
  module Servers
    class EventMachineWebSocket
      
      def initialize(port, main_server)
        @main_server = main_server
        @config = {
          :host => '0.0.0.0',
          :port => port
        }
      end
      
      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.onmessage { |msg| MadChatter.message_received(msg) }
            user.connected
          end
        end
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mad_chatter-0.3.4 lib/mad_chatter/servers/em_websocket.rb
mad_chatter-0.3.3 lib/mad_chatter/servers/em_websocket.rb
mad_chatter-0.3.2 lib/mad_chatter/servers/em_websocket.rb
mad_chatter-0.3.1 lib/mad_chatter/servers/em_websocket.rb
mad_chatter-0.3.0 lib/mad_chatter/servers/em_websocket.rb