Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/socket.io-client-simple/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module SocketIO
module Client
module Simple

def self.connect(url, opts={})
client = Client.new(url, opts)
def self.connect(url, opts={}, headers={})
client = Client.new(url, opts, headers)
client.connect
return client
end
Expand All @@ -15,9 +15,10 @@ class Client
attr_accessor :auto_reconnection, :websocket, :url, :reconnecting, :state,
:session_id, :ping_interval, :ping_timeout, :last_pong_at, :last_ping_at

def initialize(url, opts={})
def initialize(url, opts={}, headers={})
@url = url
@opts = opts
@headers = headers
@opts[:transport] = :websocket
@reconnecting = false
@state = :disconnect
Expand Down Expand Up @@ -49,7 +50,7 @@ def initialize(url, opts={})
def connect
query = @opts.map{|k,v| URI.encode "#{k}=#{v}" }.join '&'
begin
@websocket = WebSocket::Client::Simple.connect "#{@url}/socket.io/?#{query}"
@websocket = WebSocket::Client::Simple.connect "#{@url}/socket.io/?#{query}", options = @headers
rescue Errno::ECONNREFUSED => e
@state = :disconnect
@reconnecting = false
Expand Down