Sha256: b298674449b681cba3b2b72534d8790fff45391513a5277e80797b37d3f4b5fd

Contents?: true

Size: 579 Bytes

Versions: 2

Compression:

Stored size: 579 Bytes

Contents

require 'em-websocket'
require 'eventmachine'
require 'hara/base'

module Hara
  class Server
    class << self
      def start host, port
	puts "Server starting on #{host}:#{port}"
	EM.epoll
	EM.run {
	  EM::WebSocket.run(host: host, port: port) do |ws|
	  actor = nil

	  ws.onopen { |handshake|
	    actor = Hara::Application.new handshake, ws
	  }

	  ws.onclose { 
	    begin
	      actor.terminate! if actor.alive?
	    rescue Celluloid::DeadActorError => e
	    end
	  }

	  ws.onmessage { |msg|
	    actor.async.process_msg msg
	  }
	  end
	}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hara-0.2.1 lib/hara/server.rb
hara-0.2.0 lib/hara/server.rb