lib/hara/server.rb in hara-0.2.2 vs lib/hara/server.rb in hara-0.3.0

- old
+ new

@@ -1,35 +1,23 @@ 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 + def start host, port, options = {} + puts "Server starting on #{host}:#{port}" + options = options.merge(host: host, port: port) + EM.epoll + EM.run do - ws.onopen { |handshake| - actor = Hara::Application.new handshake, ws - } + EM::WebSocket.run(options) do |ws| + ws.onopen { |handshake| + Hara.filter_pool.async.run_filter handshake, ws + } + end - ws.onclose {|close_info = {}| - begin - actor.async.set_close_info close_info - actor.terminate! if actor.alive? - rescue Celluloid::DeadActorError => e - end - } - - ws.onmessage { |msg| - actor.async.process_msg msg - } - end - } + end end end end end