lib/turntabler/client.rb
def connect(url = room(digest(rand)).url)
      if !@connection || !@connection.connected? || @connection.url != url
        # Close any existing connection
        close

        # Create a new connection to the given url
        @connection = Connection.new(url, :timeout => timeout, :params => {:clientid => id, :userid => user.id, :userauth => user.auth})
        @connection.handler = lambda {|data| trigger(data.delete('command'), data)}
        @connection.start

        # Wait until the connection is authenticated
        wait do |&resume|
          on(:session_missing, :once => true) { resume.call }
        end
      end

      true
    end
def connect(url = room(digest(rand)).url)
      if !@connection || !@connection.connected? || @connection.url != url
        # Close any existing connection
        close

        # Create a new connection to the given url
        @connection = Connection.new(url, :timeout => timeout, :params => {:clientid => id, :userid => user.id, :userauth => user.auth})
        @connection.handler = lambda {|data| trigger(data.delete('command'), data)}
        @connection.start

        # Wait until the connection is authenticated
        wait do |&resume|
          on(:session_missing, :once => true) { resume.call }
        end
      end

      true
    end
def connect ( url = room ( digest ( rand ) ) . url ) if ! @connection || ! @connection . connected? || @connection . url != url # Close any existing connection close # Create a new connection to the given url @connection = Connection . new ( url , :timeout => timeout , :params => { :clientid => id , :userid => user . id , :userauth => user . auth } ) @connection . handler = lambda { | data | trigger ( data . delete ( 'command' ) , data ) } @connection . start # Wait until the connection is authenticated wait do | & resume | on ( :session_missing , :once => true ) { resume . call } end end true end
Creates a new client for communicating with Turntable.fm with the given
 email / password.

 @param [String] email The e-mail address of the user to authenticate with
 @param [String] password The Turntable password associated with the email address
 @param [Hash] options The configuration options for the client
 @option options [String] :id The unique identifier representing this client
 @option options [String] :room The id of the room to initially enter
 @option options [String] :user_id The Turntable id for the authenticating user (required if the user does not have an associated password)
 @option options [String] :auth The authentication token for the user (required if the user does not have an associated password)
 @option options [Fixnum] :timeout (10) The amount of seconds to allow to elapse for requests before timing out
 @option options [Boolean] :reconnect (false) Whether to allow the client to automatically reconnect when disconnected either by Turntable or by the network
 @option options [Fixnum] :reconnect_wait (5) The amount of seconds to wait before reconnecting
 @raise [Turntabler::Error] if an invalid option is specified
 @yield Runs the given block within the context if the client (for DSL-type usage)
 Initiates a connection with the given url.  Once a connection is started,
 this will also attempt to authenticate the user.

 @api private
 @note This will only open a new connection if the client isn't already connected to the given url
 @param [String] url The url to open a connection to
 @return [true]
 @raise [Turntabler::Error] if the connection cannot be opened
Creates a new client for communicating with Turntable . fm with the given email / password .