Class: ONVIF::DeviceDiscovery

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_onvif_client/device_discovery.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(options = {}) ⇒ Object



7
8
9
10
11
# File 'lib/ruby_onvif_client/device_discovery.rb', line 7

def self.start options = {}
    DeviceDiscovery.new.start(options) do |devices|
        yield devices
    end
end

Instance Method Details

#start(options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_onvif_client/device_discovery.rb', line 13

def start options
    @options = {
    }.merge(options)
    searcher = WSDiscovery.search(
        env_namespaces: { 
            "xmlns:dn" => "http://www.onvif.org/ver10/network/wsdl"
        }, 
        types: "dn:NetworkVideoTransmitter"
    )
    searcher.discovery_responses.subscribe do |notification|
        device = {
            ep_address: notification[:probe_matches][:probe_match][:endpoint_reference][:address],
            types: notification[:probe_matches][:probe_match][:types],
            device_ip: URI(notification[:probe_matches][:probe_match][:x_addrs]).host,
            device_service_address: notification[:probe_matches][:probe_match][:x_addrs],
            scopes: notification[:probe_matches][:probe_match][:scopes].split(' '),
            metadata_version: notification[:probe_matches][:probe_match][:metadata_version]
        }
        yield device
    end
end