Class: ONVIF::MediaAction::GetAudioEncoderConfigurations

Inherits:
Action
  • Object
show all
Defined in:
lib/ruby_onvif_client/media/get_audio_encoder_configurations.rb

Instance Method Summary collapse

Methods inherited from Action

#attribute, #callback, #create_event_onvif_message, #create_media_onvif_message, #create_ptz_onvif_message, #initialize, #send_message, #value

Constructor Details

This class inherits a constructor from ONVIF::Action

Instance Method Details

#run(cb) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_onvif_client/media/get_audio_encoder_configurations.rb', line 6

def run cb
    message = create_media_onvif_message
    message.body =  ->(xml) do
        xml.wsdl(:GetAudioEncoderConfigurations)
    end
    send_message message do |success, result|
        if success
            xml_doc = Nokogiri::XML(result[:content])
            configurations = []
            xml_doc.xpath('//trt:Configurations').each do |node|
                bounds = node.xpath('tt:Bounds')
                multicast = node.xpath('tt:Multicast')
                address = multicast.xpath('tt:Address')
                configuration = {
                    name: value(node, 'tt:Name'),
                    use_count: value(node, 'tt:UseCount'),
                    token: attribute(node, 'token'),
                    encoding: value(node, 'tt:Encoding'),
                    bitrate: value(node, 'tt:Bitrate'),
                    sample_rate: value(node, 'tt:SampleRate'),
                    
                    multicast: {
                        address: {
                            type: value(address, 'tt:Type'),
                            ipv4_address: value(address, 'tt:IPv4Address'),
                            ipv6_address: value(address, 'tt:IPv6Address')
                        },
                        port: value(multicast, "tt:Port"),
                        ttl: value(multicast, "tt:TTL"),
                        auto_start: value(multicast, "tt:AutoStart")
                    },
                    session_timeout: value(node, 'tt:SessionTimeout')
                }
                configurations << configuration
            end
            callback cb, success, configurations
        else
            callback cb, success, result
        end
    end
end