2015-04-06 14:17:02 -04:00
|
|
|
module ActionCable
|
|
|
|
class RemoteConnection
|
|
|
|
class InvalidIdentifiersError < StandardError; end
|
|
|
|
|
2015-06-22 15:34:06 -04:00
|
|
|
include Connection::Identification, Connection::InternalChannel
|
2015-04-06 14:17:02 -04:00
|
|
|
|
|
|
|
def initialize(server, ids)
|
|
|
|
@server = server
|
|
|
|
set_identifier_instance_vars(ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def disconnect
|
2015-06-28 14:38:05 -04:00
|
|
|
server.broadcast_without_logging internal_redis_channel, type: 'disconnect'
|
2015-04-06 14:17:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def identifiers
|
2015-06-28 14:38:05 -04:00
|
|
|
server.connection_identifiers
|
2015-04-06 14:17:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2015-06-28 14:38:05 -04:00
|
|
|
attr_reader :server
|
|
|
|
|
2015-04-06 14:17:02 -04:00
|
|
|
def set_identifier_instance_vars(ids)
|
|
|
|
raise InvalidIdentifiersError unless valid_identifiers?(ids)
|
|
|
|
ids.each { |k,v| instance_variable_set("@#{k}", v) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_identifiers?(ids)
|
|
|
|
keys = ids.keys
|
|
|
|
identifiers.all? { |id| keys.include?(id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|