Permalink
Browse files

Adding support for passing on request to onopen

  • Loading branch information...
1 parent 534c99f commit 43f6ad5fc8b99080b1ef8275c8b3beb81e0e8a1e @mrevilme committed Nov 5, 2011
Showing with 5 additions and 4 deletions.
  1. +1 −1 examples/echo.rb
  2. +2 −2 lib/em-websocket/connection.rb
  3. +1 −1 lib/em-websocket/handler.rb
  4. +1 −0 lib/em-websocket/handshake04.rb
View
@@ -5,4 +5,4 @@
ws.onmessage { |msg| ws.send "Pong: #{msg}" }
ws.onclose { puts "WebSocket closed" }
ws.onerror { |e| puts "Error: #{e.message}" }
-end
+end
@@ -14,8 +14,8 @@ def onmessage(&blk); @onmessage = blk; end
def trigger_on_message(msg)
@onmessage.call(msg) if @onmessage
end
- def trigger_on_open
- @onopen.call if @onopen
+ def trigger_on_open(request)
+ @onopen.call(request) if @onopen
end
def trigger_on_close
@onclose.call if @onclose
@@ -15,7 +15,7 @@ def initialize(connection, request, debug = false)
def run
@connection.send_data handshake
@state = :connected
- @connection.trigger_on_open
+ @connection.trigger_on_open @request
end
# Handshake response
@@ -6,6 +6,7 @@ module WebSocket
module Handshake04
def handshake
# Required
+ debug [:request, request]
unless key = request['sec-websocket-key']
raise HandshakeError, "Sec-WebSocket-Key header is required"
end

0 comments on commit 43f6ad5

Please sign in to comment.