class Vines::Stream::Component

Implements the XMPP protocol for trusted, external component (XEP-0114) streams. This serves connected streams using the jabber:component:accept namespace.

Attributes

remote_domain[R]

Public Class Methods

new(config) click to toggle source
Calls superclass method Vines::Stream::new
# File lib/vines/stream/component.rb, line 12
def initialize(config)
  super
  @remote_domain = nil
  @stream_id = Kit.uuid
  advance(Start.new(self))
end

Public Instance Methods

max_stanza_size() click to toggle source
# File lib/vines/stream/component.rb, line 19
def max_stanza_size
  config[:component].max_stanza_size
end
ready?() click to toggle source
# File lib/vines/stream/component.rb, line 23
def ready?
  state.class == Component::Ready
end
secret() click to toggle source
# File lib/vines/stream/component.rb, line 40
def secret
  password = config.component_password(@remote_domain)
  Digest::SHA1.hexdigest(@stream_id + password)
end
start(node) click to toggle source
# File lib/vines/stream/component.rb, line 31
def start(node)
  @remote_domain = node['to']
  send_stream_header
  raise StreamErrors::ImproperAddressing unless valid_address?(@remote_domain)
  raise StreamErrors::HostUnknown unless config.component?(@remote_domain)
  raise StreamErrors::InvalidNamespace unless node.namespaces['xmlns'] == NAMESPACES[:component]
  raise StreamErrors::InvalidNamespace unless node.namespaces['xmlns:stream'] == NAMESPACES[:stream]
end
stream_type() click to toggle source
# File lib/vines/stream/component.rb, line 27
def stream_type
  :component
end

Private Instance Methods

send_stream_header() click to toggle source
# File lib/vines/stream/component.rb, line 47
def send_stream_header
  attrs = {
    'xmlns'        => NAMESPACES[:component],
    'xmlns:stream' => NAMESPACES[:stream],
    'id'           => @stream_id,
    'from'         => @remote_domain
  }
  write "<stream:stream %s>" % attrs.to_a.map{|k,v| "#{k}='#{v}'"}.join(' ')
end