Skip to content

Commit

Permalink
Adding support for passing on request to onopen
Browse files Browse the repository at this point in the history
  • Loading branch information
emil-palm committed Nov 5, 2011
1 parent 534c99f commit 43f6ad5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/echo.rb
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/em-websocket/connection.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/em-websocket/handler.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/em-websocket/handshake04.rb
Expand Up @@ -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
Expand Down

0 comments on commit 43f6ad5

Please sign in to comment.