lib/websocket/eventmachine/base.rb in websocket-eventmachine-base-1.1.1 vs lib/websocket/eventmachine/base.rb in websocket-eventmachine-base-1.2.0
- old
+ new
@@ -130,42 +130,36 @@
### Private methods ###
#######################
private
- ['onopen'].each do |m|
- define_method "trigger_#{m}" do
- callback = instance_variable_get("@#{m}")
- callback.call if callback
- end
+ def trigger_onopen(handshake)
+ @onopen.call(handshake) if @onopen
end
+ def trigger_onmessage(data, type)
+ @onmessage.call(data, type) if @onmessage
+ end
+
+ def trigger_onclose(code, reason)
+ @onclose.call(code, reason) if @onclose
+ end
+
['onerror', 'onping', 'onpong'].each do |m|
define_method "trigger_#{m}" do |data|
callback = instance_variable_get("@#{m}")
callback.call(data) if callback
end
end
- ['onclose'].each do |m|
- define_method "trigger_#{m}" do |code, reason|
- callback = instance_variable_get("@#{m}")
- callback.call(code, reason) if callback
- end
- end
-
- def trigger_onmessage(data, type)
- @onmessage.call(data, type) if @onmessage
- end
-
def handle_connecting(data)
@handshake << data
return unless @handshake.finished?
if @handshake.valid?
send(@handshake.to_s, :type => :plain) if @handshake.should_respond?
@frame = incoming_frame.new(:version => @handshake.version)
@state = :open
- trigger_onopen
+ trigger_onopen(@handshake)
handle_open(@handshake.leftovers) if @handshake.leftovers
else
trigger_onerror(@handshake.error.to_s)
close
end