lib/angelo/base.rb in angelo-0.1.5 vs lib/angelo/base.rb in angelo-0.1.6
- old
+ new
@@ -80,12 +80,12 @@
def on_pong &block
WebsocketResponder.on_pong = block
end
- def async name, &block
- Angelo::Server.define_action name, &block
+ def task name, &block
+ Angelo::Server.define_task name, &block
end
def websockets
@websockets ||= WebsocketsArray.new server
@websockets.reject! &:closed?
@@ -110,30 +110,45 @@
def async meth, *args
self.class.server.async.__send__ meth, *args
end
+ def future meth, *args
+ self.class.server.future.__send__ meth, *args
+ end
+
def params
@params ||= case request.method
when GET; parse_query_string
when POST; parse_post_body
when PUT; parse_post_body
end
end
def websockets; self.class.websockets; end
- async :handle_websocket do |ws|
+ def request_headers
+ @request_headers ||= Hash.new do |hash, key|
+ if Symbol === key
+ k = key.to_s.upcase
+ k.gsub! UNDERSCORE, DASH
+ rhv = request.headers.select {|header_key,v| header_key.upcase == k}
+ hash[key] = rhv.values.first
+ end
+ end
+ end
+
+ task :handle_websocket do |ws|
begin
while !ws.closed? do
ws.read
end
rescue IOError
websockets.remove_socket ws
end
end
- async :ping_websockets do
+ task :ping_websockets do
every(@@ping_time) do
websockets.all.each do |ws|
ws.socket << ::WebSocket::Message.ping.to_data
end
end