Class: RUPNP::SSDP::Listener

Inherits:
MulticastConnection show all
Includes:
HTTP
Defined in:
lib/rupnp/ssdp/listener.rb

Overview

Listener class for listening for devices’ notifications

Author:

  • Sylvain Daubert

Constant Summary

Constants included from LogMixin

LogMixin::LOG_LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTTP

#get_http_headers, #get_http_verb, #is_http_status_ok?

Methods inherited from MulticastConnection

#peer_info

Methods included from LogMixin

#log

Constructor Details

#initialize(options = {}) ⇒ Listener

Returns a new instance of Listener.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :ttl (Integer)


14
15
16
17
18
# File 'lib/rupnp/ssdp/listener.rb', line 14

def initialize(options={})
  @notifications = EM::Channel.new

  super options[:ttl]
end

Instance Attribute Details

#notificationsEM::Channel (readonly)

Channel to receive notifications

Returns:

  • (EM::Channel)


10
11
12
# File 'lib/rupnp/ssdp/listener.rb', line 10

def notifications
  @notifications
end

Instance Method Details

#receive_data(data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rupnp/ssdp/listener.rb', line 21

def receive_data(data)
  port, ip = peer_info
  log :info, "Receive notification from #{ip}:#{port}"
  log :debug, data

  io = StringIO.new(data)
  h = get_http_verb(io)

  if h.nil?
    log :warn, "No HTTP command"
    return
  elsif h[:verb] == 'M-SEARCH'
    return
  elsif !(h[:verb].upcase == 'NOTIFY' and h[:path] == '*' and
          h[:http_version] == '1.1')
    log :warn, "Unknown HTTP command: #{h[:cmd]}"
    return
  end

  @notifications << get_http_headers(io)
end