ruby_onvif_client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_onvif_client/action.rb +9 -0
- data/lib/ruby_onvif_client/device_management/set_network_interfaces.rb +68 -37
- data/lib/ruby_onvif_client/device_management/set_system_date_and_time.rb +27 -20
- data/lib/ruby_onvif_client/device_management/set_system_factory_default.rb +0 -1
- data/lib/ruby_onvif_client/event.rb +40 -0
- data/lib/ruby_onvif_client/event_handing/create_pull_point.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/create_pull_point_subscription.rb +37 -0
- data/lib/ruby_onvif_client/event_handing/destroy_pull_point.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/get_current_message.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/get_event_properties.rb +46 -0
- data/lib/ruby_onvif_client/event_handing/get_messages.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/get_service_capabilities.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/notify.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/pause_subscription.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/pull_messages.rb +38 -0
- data/lib/ruby_onvif_client/event_handing/renew.rb +31 -0
- data/lib/ruby_onvif_client/event_handing/resume_subscription.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/seek.rb +0 -0
- data/lib/ruby_onvif_client/event_handing/set_synchronization_point.rb +22 -0
- data/lib/ruby_onvif_client/event_handing/subscribe.rb +46 -0
- data/lib/ruby_onvif_client/event_handing/unsubscribe.rb +22 -0
- data/lib/ruby_onvif_client/ptz/relative_move.rb +2 -2
- data/lib/ruby_onvif_client/server.rb +115 -0
- data/lib/ruby_onvif_client.rb +1 -0
- data/ruby-onvif-client.gemspec +3 -2
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 604d28854be92132f924b164328b6a8377a9da43
|
4
|
+
data.tar.gz: bd1f2fbe5905e6f9fe26c4cedea726729d423185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a5b5ba6c8ba8428aad1cfcf3cf5b3676661af7a368c245e7759521feccd21510ad3b8ec240afccf6ef41ec05aaa996d60176399f2ff2c9efc360e8b5596558e
|
7
|
+
data.tar.gz: 11e4ad45dd2661b8fa93493089fd22b09a4bcf4d1d06678f836f0f75da7750745c9cddf3f8972158482a2bc199e934ef5406d1fc69324223845dd43993b26949
|
@@ -39,6 +39,7 @@ module ONVIF
|
|
39
39
|
options[:namespaces] = namespaces
|
40
40
|
Message.new options
|
41
41
|
end
|
42
|
+
|
42
43
|
def create_ptz_onvif_message options = {}
|
43
44
|
namespaces = {
|
44
45
|
:'xmlns:wsdl' => "http://www.onvif.org/ver20/ptz/wsdl"
|
@@ -46,5 +47,13 @@ module ONVIF
|
|
46
47
|
options[:namespaces] = namespaces
|
47
48
|
Message.new options
|
48
49
|
end
|
50
|
+
|
51
|
+
def create_event_onvif_message options = {}
|
52
|
+
namespaces = {
|
53
|
+
:'xmlns:wsdl' => "http://www.onvif.org/ver10/events/wsdl"
|
54
|
+
}.merge(options[:namespaces] || {})
|
55
|
+
options[:namespaces] = namespaces
|
56
|
+
Message.new options
|
57
|
+
end
|
49
58
|
end
|
50
59
|
end
|
@@ -5,31 +5,31 @@ module ONVIF
|
|
5
5
|
class SetNetworkInterfaces < Action
|
6
6
|
# network_interface 的结构
|
7
7
|
# {
|
8
|
-
# interface_token: 'xxxxxx', // name [string]
|
8
|
+
# interface_token: 'xxxxxx', // optional name [string]
|
9
9
|
# nwif:{ // #NetworkInterface
|
10
|
-
# enabled: true, //true, false [boolean]
|
11
|
-
# link: {
|
10
|
+
# enabled: true, //optional true, false [boolean]
|
11
|
+
# link: {//optional
|
12
12
|
# auto_negotiation: true, //true, false [boolean]
|
13
13
|
# speed: 3, // [int]
|
14
14
|
# duplex: 'Full' //'Full', 'Half'
|
15
15
|
# }
|
16
|
-
# mtu: 2, //
|
17
|
-
# ipv4: {
|
18
|
-
# enabled: true, //true, false [boolean]
|
19
|
-
# manual: [{
|
16
|
+
# mtu: 2, //optional [int]
|
17
|
+
# ipv4: { //optional
|
18
|
+
# enabled: true, //optional true, false [boolean]
|
19
|
+
# manual: [{ //optional
|
20
20
|
# address: "xxx.xxx.xxx.xxx", // [IPv4Address]
|
21
21
|
# prefix_length: 22 // [int]
|
22
22
|
# }],
|
23
|
-
# dhcp: true //true, false [boolean]
|
23
|
+
# dhcp: true //optional true, false [boolean]
|
24
24
|
# },
|
25
|
-
# ipv6: {
|
26
|
-
# enabled: true, //true, false [boolean]
|
27
|
-
# ara: false//true, false #AcceptRouterAdvert [boolean]
|
28
|
-
# manual: [{
|
25
|
+
# ipv6: {//optional
|
26
|
+
# enabled: true, //optional true, false [boolean]
|
27
|
+
# ara: false//optional true, false #AcceptRouterAdvert [boolean]
|
28
|
+
# manual: [{//optional
|
29
29
|
# address: "xxx.xxx.xxx.xxx", // [IPv4Address]
|
30
30
|
# prefix_length: 22 // [int]
|
31
31
|
# }],
|
32
|
-
# dhcp: true //true, false [boolean]
|
32
|
+
# dhcp: true //optional true, false [boolean]
|
33
33
|
# }
|
34
34
|
# }
|
35
35
|
# }
|
@@ -39,43 +39,74 @@ module ONVIF
|
|
39
39
|
xml.wsdl(:SetNetworkInterfaces) do
|
40
40
|
xml.wsdl :InterfaceToken, network_interface[:interface_token]
|
41
41
|
xml.wsdl :NetworkInterface do
|
42
|
-
|
43
|
-
|
44
|
-
xml.sch :AutoNegotiation, network_interface[:nwif][:link][:auto_negotiation]
|
45
|
-
xml.sch :Speed, network_interface[:nwif][:link][:speed]
|
46
|
-
xml.sch :Duplex, network_interface[:nwif][:link][:duplex]
|
42
|
+
unless options[:nwif][:enabled].nil?
|
43
|
+
xml.sch :Enabled, network_interface[:nwif][:enabled]
|
47
44
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
xml.sch :
|
53
|
-
|
54
|
-
|
45
|
+
unless options[:nwif][:link].nil?
|
46
|
+
xml.sch :Link do
|
47
|
+
xml.sch :AutoNegotiation, network_interface[:nwif][:link][:auto_negotiation]
|
48
|
+
xml.sch :Speed, network_interface[:nwif][:link][:speed]
|
49
|
+
xml.sch :Duplex, network_interface[:nwif][:link][:duplex]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
unless options[:nwif][:mtu].nil?
|
53
|
+
xml.sch :MTU, network_interface[:nwif][:mtu]
|
54
|
+
end
|
55
|
+
unless options[:nwif][:ipv4].nil?
|
56
|
+
xml.sch :IPv4 do
|
57
|
+
unless options[:nwif][:ipv4][:enabled].nil?
|
58
|
+
xml.sch :Enabled, network_interface[:nwif][:ipv4][:enabled]
|
59
|
+
end
|
60
|
+
unless options[:nwif][:ipv4][:manual].nil?
|
61
|
+
network_interface[:nwif][:ipv4][:manual].each do |manual|
|
62
|
+
xml.sch :Manual do
|
63
|
+
xml.sch :Address, manual[:address]
|
64
|
+
xml.sch :PrefixLength, manual[:prefix_length]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
unless options[:nwif][:ipv4][:dhcp].nil?
|
69
|
+
xml.sch :DHCP, network_interface[:nwif][:ipv4][:dhcp]
|
55
70
|
end
|
56
71
|
end
|
57
|
-
xml.sch :DHCP, network_interface[:nwif][:ipv4][:dhcp]
|
58
72
|
end
|
59
|
-
|
60
|
-
xml.sch :
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
xml.sch :
|
73
|
+
unless options[:nwif][:ipv6].nil?
|
74
|
+
xml.sch :IPv6 do
|
75
|
+
unless options[:nwif][:ipv6][:enabled].nil?
|
76
|
+
xml.sch :Enabled, network_interface[:nwif][:ipv6][:enabled]
|
77
|
+
end
|
78
|
+
unless options[:nwif][:ipv6][:ara].nil?
|
79
|
+
xml.sch :AcceptRouterAdvert, network_interface[:nwif][:ipv6][:ara]
|
80
|
+
end
|
81
|
+
unless options[:nwif][:ipv6][:manual].nil?
|
82
|
+
network_interface[:nwif][:ipv6][:manual].each do |manual|
|
83
|
+
xml.sch :Manual do
|
84
|
+
xml.sch :Address, manual[:address]
|
85
|
+
xml.sch :PrefixLength, manual[:prefix_length]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
unless options[:nwif][:ipv6][:dhcp].nil?
|
90
|
+
xml.sch :DHCP, network_interface[:nwif][:ipv6][:dhcp]
|
66
91
|
end
|
67
92
|
end
|
68
|
-
xml.sch :DHCP, network_interface[:nwif][:ipv6][:dhcp]
|
69
93
|
end
|
70
|
-
|
71
94
|
end
|
72
95
|
xml.wsdl :Extension do
|
73
96
|
end
|
74
97
|
end
|
75
98
|
end
|
76
99
|
send_message message do |success, result|
|
77
|
-
|
78
|
-
|
100
|
+
if success
|
101
|
+
xml_doc = Nokogiri::XML(result[:content])
|
102
|
+
info = {
|
103
|
+
reboot_needed: value(xml_doc, '//tds:RebootNeeded')
|
104
|
+
}
|
105
|
+
|
106
|
+
callback cb, success, info
|
107
|
+
else
|
108
|
+
callback cb, success, result
|
109
|
+
end
|
79
110
|
end
|
80
111
|
end
|
81
112
|
end
|
@@ -7,13 +7,17 @@ module ONVIF
|
|
7
7
|
# {
|
8
8
|
# type: 'Manual', // 'Manual', 'NTP'
|
9
9
|
# ds: false // DaylightSavings [booblean]
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
10
|
+
# time_zone: {//optional
|
11
|
+
# tz: 'xxxxx'// string TimeZone -> TZ [token]
|
12
|
+
# }
|
13
|
+
# date_time: {//optional
|
14
|
+
# year: 2013 // int
|
15
|
+
# month: 6 // int 1 to 12
|
16
|
+
# day: 26 // int 1 to 31
|
17
|
+
# hour: 5 // int 0 to 23
|
18
|
+
# minute: 31 //int 0 to 59
|
19
|
+
# second: 44 //int 0 to 61 (typically 59)
|
20
|
+
# }
|
17
21
|
# }
|
18
22
|
def run system_date_time, cb
|
19
23
|
message = Message.new namespaces: {:'xmlns:sch' => 'http://www.onvif.org/ver10/schema'}
|
@@ -21,25 +25,28 @@ module ONVIF
|
|
21
25
|
xml.wsdl(:SetSystemDateAndTime) do
|
22
26
|
xml.wsdl :DateTimeType, system_date_time[:type]
|
23
27
|
xml.wsdl :DaylightSavings, system_date_time[:ds]
|
24
|
-
|
25
|
-
xml.
|
26
|
-
|
27
|
-
xml.wsdl(:TimeZone) do
|
28
|
-
xml.sch :Time do
|
29
|
-
xml.sch :Hour, system_date_time[:hour]
|
30
|
-
xml.sch :Minute, system_date_time[:minute]
|
31
|
-
xml.sch :Second, system_date_time[:second]
|
28
|
+
unless options[:time_zone].nil?
|
29
|
+
xml.wsdl(:TimeZone) do
|
30
|
+
xml.sch :TZ, system_date_time[:time_zone][:tz]
|
32
31
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
xml.sch :
|
32
|
+
end
|
33
|
+
unless options[:date_time].nil?
|
34
|
+
xml.wsdl(:UTCDateTime) do
|
35
|
+
xml.sch :Time do
|
36
|
+
xml.sch :Hour, system_date_time[:date_time][:hour]
|
37
|
+
xml.sch :Minute, system_date_time[:date_time][:minute]
|
38
|
+
xml.sch :Second, system_date_time[:date_time][:second]
|
39
|
+
end
|
40
|
+
xml.sch :Date do
|
41
|
+
xml.sch :Year, system_date_time[:date_time][:year]
|
42
|
+
xml.sch :Month, system_date_time[:date_time][:month]
|
43
|
+
xml.sch :Day, system_date_time[:date_time][:day]
|
44
|
+
end
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
send_message message do |success, result|
|
42
|
-
#????
|
43
50
|
callback cb, success, result
|
44
51
|
end
|
45
52
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'service'
|
2
|
+
Dir.chdir __dir__ do
|
3
|
+
require_relative_dir 'event_handing'
|
4
|
+
end
|
5
|
+
|
6
|
+
module ONVIF
|
7
|
+
class Event < Service
|
8
|
+
# def initialize(args)
|
9
|
+
|
10
|
+
# end
|
11
|
+
|
12
|
+
def get_event_service_address cb
|
13
|
+
@res = {}
|
14
|
+
device_management = ONVIF::DeviceManagement.new("http://192.168.16.106/onvif/device_service")
|
15
|
+
content = [{:Category => 'Events'}]
|
16
|
+
device_management.get_capabilities content, ->(success, result) {
|
17
|
+
if success
|
18
|
+
puts "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%success%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
|
19
|
+
#puts result
|
20
|
+
@res[:address] = result[:events][:x_addr]
|
21
|
+
@res[:subscription_policy_support] = result[:events][:wssubscription_policy_support]
|
22
|
+
@res[:pull_point_support] = result[:events][:wspull_point_support]
|
23
|
+
@res[:pausable_subscription_manager_interface_support] = result[:events][:wspsmis]
|
24
|
+
#puts @res
|
25
|
+
cb.call @res[:address]
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsdl="http://www.onvif.org/ver10/device/wsdl">
|
33
|
+
# <soap:Header/>
|
34
|
+
# <soap:Body>
|
35
|
+
# <wsdl:GetCapabilities>
|
36
|
+
# <!--Zero or more repetitions:-->
|
37
|
+
# <wsdl:Category>Events</wsdl:Category>
|
38
|
+
# </wsdl:GetCapabilities>
|
39
|
+
# </soap:Body>
|
40
|
+
# </soap:Envelope>
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class CreatePullPointSubscription < Action
|
6
|
+
def run time, cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl'}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.wsdl(:CreatePullPointSubscription) do
|
10
|
+
xml.wsdl :InitialTerminationTime, time
|
11
|
+
end
|
12
|
+
end
|
13
|
+
send_message message do |success, result|
|
14
|
+
if success
|
15
|
+
xml_doc = Nokogiri::XML(result[:content])
|
16
|
+
addresses = []
|
17
|
+
xml_doc.xpath('//tev:SubscriptionReference').each do |node|
|
18
|
+
addresses << value(node, 'wsa5:Address')
|
19
|
+
end
|
20
|
+
res = {}
|
21
|
+
puts addresses
|
22
|
+
res[:addresses] = addresses
|
23
|
+
current_time = xml_doc.xpath('//wsnt:CurrentTime').first.content
|
24
|
+
termination_time = xml_doc.xpath('//wsnt:TerminationTime').first.content
|
25
|
+
puts current_time, termination_time
|
26
|
+
res[:current_time] = current_time
|
27
|
+
res[:termination_time] = termination_time
|
28
|
+
callback cb, success, res
|
29
|
+
else
|
30
|
+
callback cb, success, result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
File without changes
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class GetEventProperties < Action
|
6
|
+
def run cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl'}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.wsdl(:GetEventProperties)
|
10
|
+
end
|
11
|
+
send_message message do |success, result|
|
12
|
+
if success
|
13
|
+
xml_doc = Nokogiri::XML(result[:content])
|
14
|
+
# users = []
|
15
|
+
step1 = false
|
16
|
+
step2 = false
|
17
|
+
step3 = false
|
18
|
+
step4 = false
|
19
|
+
step5 = false
|
20
|
+
xml_doc.xpath('//wsnt:TopicExpressionDialect').each do |node|
|
21
|
+
if node.content == 'http://docs.oasis-open.org/wsn/t-1/TopicExpression/Concrete'
|
22
|
+
step1 = true
|
23
|
+
elsif node.content == 'http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet'
|
24
|
+
step2 = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
step3 = true if xml_doc.xpath('//tev:MessageContentFilterDialect').first.content == 'http://www.onvif.org/ver10/tev/messageContentFilter/ItemFilter'
|
28
|
+
topic_namespace = xml_doc.xpath('//tev:TopicNamespaceLocation').first.content
|
29
|
+
step4 = true if topic_namespace.include? "http://"
|
30
|
+
#puts xml_doc.xpath('//wstop:TopicSet').size
|
31
|
+
#step5 = true unless xml_doc.xpath('//wstop:TopicSet').size.empty?
|
32
|
+
puts step1, step2, step3, step4, step5
|
33
|
+
if step1 and step2 and step3 and step4# and step5
|
34
|
+
callback cb, success, result
|
35
|
+
else
|
36
|
+
callback cb, false, result
|
37
|
+
end
|
38
|
+
else
|
39
|
+
callback cb, success, result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class PullMessages < Action
|
6
|
+
def run options, cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl'}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.wsdl(:PullMessages) do
|
10
|
+
xml.wsdl :Timeout, options[:time_out]
|
11
|
+
xml.wsdl :MessageLimit , options[:message_limit]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
send_message message do |success, result|
|
15
|
+
if success
|
16
|
+
# xml_doc = Nokogiri::XML(result[:content])
|
17
|
+
# addresses = []
|
18
|
+
# xml_doc.xpath('//tev:SubscriptionReference').each do |node|
|
19
|
+
# addresses << value(node, 'wsa5:Address')
|
20
|
+
# end
|
21
|
+
# res = {}
|
22
|
+
# puts addresses
|
23
|
+
# res[:addresses] = addresses
|
24
|
+
# current_time = xml_doc.xpath('//wsnt:CurrentTime').first.content
|
25
|
+
# termination_time = xml_doc.xpath('//wsnt:TerminationTime').first.content
|
26
|
+
# puts current_time, termination_time
|
27
|
+
# res[:current_time] = current_time
|
28
|
+
# res[:termination_time] = termination_time
|
29
|
+
callback cb, success, result
|
30
|
+
else
|
31
|
+
callback cb, success, result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class Renew < Action
|
6
|
+
def run time, cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl', 'xmlns' => "http://docs.oasis-open.org/wsn/b-2"}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.Renew do
|
10
|
+
xml.TerminationTime time
|
11
|
+
end
|
12
|
+
end
|
13
|
+
send_message message do |success, result|
|
14
|
+
if success
|
15
|
+
xml_doc = Nokogiri::XML(result[:content])
|
16
|
+
res = {}
|
17
|
+
current_time = xml_doc.xpath('//wsnt:CurrentTime').first.content
|
18
|
+
termination_time = xml_doc.xpath('//wsnt:TerminationTime').first.content
|
19
|
+
puts current_time, termination_time
|
20
|
+
res[:current_time] = current_time
|
21
|
+
res[:termination_time] = termination_time
|
22
|
+
callback cb, success, res
|
23
|
+
else
|
24
|
+
callback cb, success, result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
File without changes
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class SetSynchronizationPoint < Action
|
6
|
+
def run cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl'}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.wsdl(:SetSynchronizationPoint)
|
10
|
+
end
|
11
|
+
send_message message do |success, result|
|
12
|
+
if success
|
13
|
+
callback cb, success, result
|
14
|
+
else
|
15
|
+
callback cb, success, result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class Subscribe < Action
|
6
|
+
def run options, cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl', :'xmlns:a' => "http://www.w3.org/2005/08/addressing", 'xmlns:b' => "http://docs.oasis-open.org/wsn/b-2"}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.b(:Subscribe) do
|
10
|
+
xml.b(:ConsumerReference) do
|
11
|
+
xml.a :Address, options[:address]
|
12
|
+
end
|
13
|
+
xml.b :InitialTerminationTime , options[:initial_termination_time]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
send_message message do |success, result|
|
17
|
+
if success
|
18
|
+
xml_doc = Nokogiri::XML(result[:content])
|
19
|
+
addresses = []
|
20
|
+
xml_doc.xpath('//tev:SubscriptionReference').each do |node|
|
21
|
+
addresses << value(node, 'wsa5:Address')
|
22
|
+
end
|
23
|
+
res = {}
|
24
|
+
puts addresses
|
25
|
+
res[:addresses] = addresses
|
26
|
+
current_time = xml_doc.xpath('//wsnt:CurrentTime').first.content
|
27
|
+
termination_time = xml_doc.xpath('//wsnt:TerminationTime').first.content
|
28
|
+
puts current_time, termination_time
|
29
|
+
res[:current_time] = current_time
|
30
|
+
res[:termination_time] = termination_time
|
31
|
+
callback cb, success, res
|
32
|
+
else
|
33
|
+
callback cb, success, result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# <Subscribe xmlns="http://docs.oasis-open.org/wsn/b-2">
|
42
|
+
# <ConsumerReference>
|
43
|
+
# <a:Address>http://192.168.16.197/onvif_notify_server</a:Address>
|
44
|
+
# </ConsumerReference>
|
45
|
+
# <InitialTerminationTime>PT10S</InitialTerminationTime>
|
46
|
+
# </Subscribe>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../action'
|
2
|
+
|
3
|
+
module ONVIF
|
4
|
+
module EventAction
|
5
|
+
class Unsubscribe < Action
|
6
|
+
def run cb
|
7
|
+
message = Message.new namespaces: {:'xmlns:wsdl' => 'http://www.onvif.org/ver10/events/wsdl'}
|
8
|
+
message.body = ->(xml) do
|
9
|
+
xml.Unsubscribe
|
10
|
+
end
|
11
|
+
send_message message do |success, result|
|
12
|
+
if success
|
13
|
+
callback cb, success, result
|
14
|
+
else
|
15
|
+
callback cb, success, result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -2,7 +2,7 @@ require_relative '../action'
|
|
2
2
|
|
3
3
|
module ONVIF
|
4
4
|
module PtzAction
|
5
|
-
class
|
5
|
+
class RelativeMove < Action
|
6
6
|
# options 的结构
|
7
7
|
# {
|
8
8
|
# profile_token: "xxxxxxx",//[ReferenceToken] A reference to the MediaProfile where the operation should take place.
|
@@ -40,7 +40,7 @@ module ONVIF
|
|
40
40
|
def run options, cb
|
41
41
|
message = create_ptz_onvif_message
|
42
42
|
message.body = ->(xml) do
|
43
|
-
xml.wsdl(:
|
43
|
+
xml.wsdl(:RelativeMove) do
|
44
44
|
xml.wsdl :ProfileToken, options[:profile_token]
|
45
45
|
xml.wsdl(:Translation) do
|
46
46
|
unless options[:translation][:pan_tilt].nil?
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'em-http-server'
|
3
|
+
|
4
|
+
module ONVIF
|
5
|
+
class Server < EM::HttpServer::Server
|
6
|
+
# def post_init
|
7
|
+
# super
|
8
|
+
# end
|
9
|
+
def initialize call_back
|
10
|
+
@call_back = call_back
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_http_request
|
15
|
+
puts "############################ #{__LINE__}"
|
16
|
+
puts @http_request_method
|
17
|
+
puts "############################ #{__LINE__}"
|
18
|
+
puts @http_request_uri
|
19
|
+
puts "############################ #{__LINE__}"
|
20
|
+
puts @http_query_string
|
21
|
+
puts "############################ #{__LINE__}"
|
22
|
+
puts @http_protocol
|
23
|
+
puts "############################ #{__LINE__}"
|
24
|
+
puts @http_content
|
25
|
+
puts "############################ #{__LINE__}"
|
26
|
+
puts @http[:cookie]
|
27
|
+
puts "############################ #{__LINE__}"
|
28
|
+
puts @http[:content_type]
|
29
|
+
puts "############################ #{__LINE__}"
|
30
|
+
# you have all the http headers in this hash
|
31
|
+
puts @http.inspect
|
32
|
+
puts "############################ #{__LINE__}"
|
33
|
+
puts @http_if_none_match
|
34
|
+
puts "############################ #{__LINE__}"
|
35
|
+
puts @http_path_info
|
36
|
+
puts "############################ #{__LINE__}"
|
37
|
+
puts @http_if_none_match
|
38
|
+
puts "############################ #{__LINE__}"
|
39
|
+
puts @http_post_content
|
40
|
+
puts "############################ #{__LINE__}"
|
41
|
+
puts @http_headers
|
42
|
+
puts "############################ #{__LINE__}"
|
43
|
+
puts @http_bodys
|
44
|
+
|
45
|
+
result = parse_data @http_content
|
46
|
+
# response = EM::DelegatedHttpResponse.new(self)
|
47
|
+
# response.status = 200
|
48
|
+
# response.content_type 'text/html'
|
49
|
+
# response.content = 'It works'
|
50
|
+
# response.send_response
|
51
|
+
@call_back.call result
|
52
|
+
end
|
53
|
+
|
54
|
+
def http_request_errback e
|
55
|
+
# printing the whole exception
|
56
|
+
puts e.inspect
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_data data
|
60
|
+
xml_doc = Nokogiri::XML(data)
|
61
|
+
res = {}
|
62
|
+
res[:topic] = xml_doc.xpath('//wsnt:Topic').first.content
|
63
|
+
res[:time] = xml_doc.xpath('//tt:Message').first.attribute('UtcTime').value
|
64
|
+
event_type = {}
|
65
|
+
xml_doc.xpath('//tt:Source').each do |node|
|
66
|
+
event_type[:name] = node.xpath('tt:SimpleItem').attribute('Name').value
|
67
|
+
event_type[:value] = node.xpath('tt:SimpleItem').attribute('Value').value
|
68
|
+
end
|
69
|
+
res[:source] = event_type
|
70
|
+
event_data = {}
|
71
|
+
xml_doc.xpath('//tt:Data').each do |node|
|
72
|
+
event_data[:name] = node.xpath('tt:SimpleItem').attribute('Name').value
|
73
|
+
event_data[:value] = node.xpath('tt:SimpleItem').attribute('Value').value
|
74
|
+
end
|
75
|
+
res[:data] = event_data
|
76
|
+
res[:host] = @http[:host] + @http_request_uri
|
77
|
+
puts res
|
78
|
+
# {:topic=>"tns1:VideoAnalytics/tnsn:MotionDetection",
|
79
|
+
# :time=>"2013-08-01T17:01:33",
|
80
|
+
# :source=>{:name=>"VideoSourceConfigurationToken", :value=>"profile_VideoSource_1"},
|
81
|
+
# :data=>{:name=>"MotionActive", :value=>"true"}, :host=>"192.168.16.251:8080/onvif_notify_server"}
|
82
|
+
res
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# EM::run do
|
88
|
+
# EM::start_server("0.0.0.0", 8080, Server)
|
89
|
+
# end
|
90
|
+
# the http request details are available via the following instance variables:
|
91
|
+
|
92
|
+
|
93
|
+
# @http_if_none_match
|
94
|
+
# @http_path_info
|
95
|
+
# @http_post_content
|
96
|
+
# @http_headers
|
97
|
+
|
98
|
+
|
99
|
+
# <SOAP-ENV:Body>
|
100
|
+
# <wsnt:Notify>
|
101
|
+
# <wsnt:NotificationMessage>
|
102
|
+
# <wsnt:Topic Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">tns1:VideoAnalytics/tnsn:MotionDetection</wsnt:Topic>
|
103
|
+
# <wsnt:Message>
|
104
|
+
# <tt:Message UtcTime="2013-07-25T16:44:01">
|
105
|
+
# <tt:Source>
|
106
|
+
# <tt:SimpleItem Name="VideoSourceConfigurationToken" Value="profile_VideoSource_1"/>
|
107
|
+
# </tt:Source>
|
108
|
+
# <tt:Data>
|
109
|
+
# <tt:SimpleItem Name="MotionActive" Value="true"/>
|
110
|
+
# </tt:Data>
|
111
|
+
# </tt:Message>
|
112
|
+
# </wsnt:Message>
|
113
|
+
# </wsnt:NotificationMessage>
|
114
|
+
# </wsnt:Notify>
|
115
|
+
# </SOAP-ENV:Body>
|
data/lib/ruby_onvif_client.rb
CHANGED
data/ruby-onvif-client.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ruby_onvif_client'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2013-
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.date = '2013-08-02'
|
5
5
|
s.summary = "Ruby实现的onvif客户端"
|
6
6
|
s.description = "使用ruby实现的简单的onvif客户端"
|
7
7
|
s.authors = ["jimxl"]
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
|
14
14
|
s.add_dependency 'em_ws_discovery'
|
15
15
|
s.add_dependency 'em-http-request'
|
16
|
+
s.add_dependency 'em-http-server'
|
16
17
|
s.add_dependency 'activesupport'
|
17
18
|
s.add_dependency 'akami'
|
18
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_onvif_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jimxl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em_ws_discovery
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: em-http-server
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: activesupport
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +97,7 @@ files:
|
|
83
97
|
- lib/ruby_onvif_client/device_management/get_capabilities.rb
|
84
98
|
- lib/ruby_onvif_client/device_management/system_reboot.rb
|
85
99
|
- lib/ruby_onvif_client/service.rb
|
100
|
+
- lib/ruby_onvif_client/server.rb
|
86
101
|
- lib/ruby_onvif_client/client.rb
|
87
102
|
- lib/ruby_onvif_client/message.rb
|
88
103
|
- lib/ruby_onvif_client/path.rb
|
@@ -101,6 +116,22 @@ files:
|
|
101
116
|
- lib/ruby_onvif_client/ptz/get_node.rb
|
102
117
|
- lib/ruby_onvif_client/ptz/absolute_move.rb
|
103
118
|
- lib/ruby_onvif_client/device_management.rb
|
119
|
+
- lib/ruby_onvif_client/event_handing/create_pull_point.rb
|
120
|
+
- lib/ruby_onvif_client/event_handing/pause_subscription.rb
|
121
|
+
- lib/ruby_onvif_client/event_handing/get_current_message.rb
|
122
|
+
- lib/ruby_onvif_client/event_handing/set_synchronization_point.rb
|
123
|
+
- lib/ruby_onvif_client/event_handing/pull_messages.rb
|
124
|
+
- lib/ruby_onvif_client/event_handing/get_messages.rb
|
125
|
+
- lib/ruby_onvif_client/event_handing/subscribe.rb
|
126
|
+
- lib/ruby_onvif_client/event_handing/renew.rb
|
127
|
+
- lib/ruby_onvif_client/event_handing/unsubscribe.rb
|
128
|
+
- lib/ruby_onvif_client/event_handing/notify.rb
|
129
|
+
- lib/ruby_onvif_client/event_handing/get_service_capabilities.rb
|
130
|
+
- lib/ruby_onvif_client/event_handing/resume_subscription.rb
|
131
|
+
- lib/ruby_onvif_client/event_handing/seek.rb
|
132
|
+
- lib/ruby_onvif_client/event_handing/get_event_properties.rb
|
133
|
+
- lib/ruby_onvif_client/event_handing/destroy_pull_point.rb
|
134
|
+
- lib/ruby_onvif_client/event_handing/create_pull_point_subscription.rb
|
104
135
|
- lib/ruby_onvif_client/media.rb
|
105
136
|
- lib/ruby_onvif_client/media/get_video_encoder_configuration.rb
|
106
137
|
- lib/ruby_onvif_client/media/get_video_encoder_configuration_options.rb
|
@@ -118,6 +149,7 @@ files:
|
|
118
149
|
- lib/ruby_onvif_client/helper/ptz_common.rb
|
119
150
|
- lib/ruby_onvif_client/action.rb
|
120
151
|
- lib/ruby_onvif_client/ptz.rb
|
152
|
+
- lib/ruby_onvif_client/event.rb
|
121
153
|
- lib/ruby_onvif_client/device_discovery.rb
|
122
154
|
- lib/ruby_onvif_client.rb
|
123
155
|
- Gemfile
|