class Ably::Models::ChannelOptions

Represents options of a channel

Constants

MODES

Describes the possible flags used to configure client capabilities, using {Ably::Models::ChannelOptions::MODES}.

PRESENCE                          The client can enter the presence set.
PUBLISH                     The client can publish messages.
SUBSCRIBE                         The client can subscribe to messages.
PRESENCE_SUBSCRIBE              The client can receive presence messages.

@spec TB2d

Attributes

attributes[R]
to_h[R]

Public Class Methods

new(attrs) click to toggle source

Initialize a new ChannelOptions

@spec TB3

@option params [Hash] (TB2c) params (for realtime client libraries only) a of key/value pairs @option modes [Hash] modes (for realtime client libraries only) an array of ChannelMode @option cipher [Hash,Ably::Models::CipherParams] :cipher A hash of options or a {Ably::Models::CipherParams} to configure the encryption. :key is required, all other options are optional.

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 52
def initialize(attrs)
  @attributes = IdiomaticRubyWrapper(attrs.clone)

  attributes[:modes] = modes.to_a.map { |mode| Ably::Models::ChannelOptions::MODES[mode] } if modes
  attributes[:cipher] = Ably::Models::CipherParams(cipher) if cipher
  attributes.clone
end

Public Instance Methods

cipher() click to toggle source

Requests encryption for this channel when not null, and specifies encryption-related parameters (such as algorithm, chaining mode, key length and key). See an example.

@spec RSL5a, TB2b

@return [CipherParams]

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 67
def cipher
  attributes[:cipher]
end
modes() click to toggle source

An array of {Ably:Models:ChannelOptions::MODES} objects.

@spec TB2d

@return [Array<ChannelOptions::MODES>]

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 87
def modes
  attributes[:modes]
end
modes_to_flags() click to toggle source

Converts modes to a bitfield that coresponds to ProtocolMessage#flags

@return [Integer]

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 95
def modes_to_flags
  modes.map { |mode| Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] }.reduce(:|)
end
params() click to toggle source

Channel Parameters that configure the behavior of the channel.

@spec TB2c

@return [Hash]

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 77
def params
  attributes[:params].to_h
end
set_modes_from_flags(flags) click to toggle source

Sets modes from ProtocolMessage#flags

@return [Array<ChannelOptions::MODES>] @api private

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 109
def set_modes_from_flags(flags)
  return unless flags

  message_modes = MODES.select do |mode|
    flag = Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym]
    flags & flag == flag
  end

  attributes[:modes] = message_modes.map { |mode| Ably::Models::ChannelOptions::MODES[mode] }
end
set_params(hash) click to toggle source

@return [Hash] @api private

# File lib/submodules/ably-ruby/lib/ably/models/channel_options.rb, line 101
def set_params(hash)
  attributes[:params] = hash
end