Method: Faye::Server#unsubscribe

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

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

MUST contain * clientId

* subscription

MAY contain * ext

* id


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/faye/protocol/server.rb', line 276

def unsubscribe(message, local = false, &callback)
  response     = make_response(message)
  client_id    = message['clientId']
  subscription = [message['subscription']].flatten

  @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?
    response['error'] = Error.parameter_missing('subscription') if message['subscription'].nil?

    response['subscription'] = message['subscription'] || []

    subscription.each do |channel|
      next if response['error']
      response['error'] = Error.channel_forbidden(channel) unless local or Channel.subscribable?(channel)
      response['error'] = Error.channel_invalid(channel) unless Channel.valid?(channel)

      next if response['error']
      @engine.unsubscribe(client_id, channel)
    end

    response['successful'] = response['error'].nil?
    callback.call(response)
  end
end