lib/faye/websocket/client.rb in faye-websocket-0.7.3 vs lib/faye/websocket/client.rb in faye-websocket-0.7.4
- old
+ new
@@ -5,12 +5,10 @@
include API
attr_reader :headers, :status
def initialize(url, protocols = nil, options = {})
- @url = url
- @uri = URI.parse(url)
@driver = ::WebSocket::Driver.client(self, :max_length => options[:max_length], :protocols => protocols)
[:open, :error].each do |event|
@driver.on(event) do
@headers = @driver.headers
@@ -18,16 +16,19 @@
end
end
super(options)
+ @url = url
+ @uri = URI.parse(url)
+
port = @uri.port || (@uri.scheme == 'wss' ? 443 : 80)
EventMachine.connect(@uri.host, port, Connection) do |conn|
@stream = conn
conn.parent = self
end
rescue => error
- event = Event.new('error', :message => "Network error: #{url}: #{error.message}")
+ event = Event.create('error', :message => "Network error: #{url}: #{error.message}")
event.init_event('error', false, false)
dispatch_event(event)
finalize(error.message, 1006)
end