2015-04-06 14:17:02 -04:00
|
|
|
module ActionCable
|
|
|
|
class RemoteConnection
|
|
|
|
class InvalidIdentifiersError < StandardError; end
|
|
|
|
|
|
|
|
include Connection::Identifier
|
|
|
|
|
|
|
|
def initialize(server, ids)
|
|
|
|
@server = server
|
|
|
|
set_identifier_instance_vars(ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def disconnect
|
|
|
|
message = { type: 'disconnect' }.to_json
|
|
|
|
redis.publish(internal_redis_channel, message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def identifiers
|
|
|
|
@server.connection_identifiers
|
|
|
|
end
|
|
|
|
|
|
|
|
def redis
|
2015-04-15 14:58:22 -04:00
|
|
|
@server.threaded_redis
|
2015-04-06 14:17:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
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
|