lib/faye/websocket/api.rb in faye-websocket-0.9.2 vs lib/faye/websocket/api.rb in faye-websocket-0.10.0

- old
+ new

@@ -67,13 +67,22 @@ def ping(message = '', &callback) return false if @ready_state > OPEN @driver.ping(message, &callback) end - def close + def close(code = nil, reason = nil) + code ||= 1000 + reason ||= '' + + unless code == 1000 or (code >= 3000 and code <= 4999) + raise ArgumentError, "Failed to execute 'close' on WebSocket: " + + "The code must be either 1000, or between 3000 and 4999. " + + "#{code} is neither." + end + @ready_state = CLOSING unless @ready_state == CLOSED - @driver.close + @driver.close(reason, code) end def protocol @driver.protocol || '' end @@ -104,16 +113,16 @@ end def begin_close(reason, code) return if @ready_state == CLOSED @ready_state = CLOSING + @close_params = [reason, code] if @stream @stream.close_connection_after_writing else finalize_close end - @close_params = [reason, code] end def finalize_close return if @ready_state == CLOSED @ready_state = CLOSED