Method: Faye::Server#connect

Defined in:
lib/faye/protocol/server.rb

#connect(message, local = false, &callback) ⇒ Object

MUST contain * clientId

* connectionType

MAY contain * ext

* id


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/faye/protocol/server.rb', line 190

def connect(message, local = false, &callback)
  response        = make_response(message)
  client_id       = message['clientId']
  connection_type = message['connectionType']

  @engine.client_exists(client_id) do |exists|
    response['error'] = Error.client_unknown(client_id) unless exists
    response['error'] = Error.parameter_missing('clientId') if client_id.nil?

    unless CONNECTION_TYPES.include?(connection_type)
      response['error'] = Error.conntype_mismatch(connection_type)
    end

    response['error'] = Error.parameter_missing('connectionType') if connection_type.nil?

    response['successful'] = response['error'].nil?

    if !response['successful']
      response.delete('clientId')
      next callback.call(response)
    end

    if message['connectionType'] == 'eventsource'
      message['advice'] ||= {}
      message['advice']['timeout'] = 0
    end

    @engine.connect(response['clientId'], message['advice']) do |events|
      callback.call([response] + events)
    end
  end
end