ssdp 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ssdp.rb +11 -10
- data/lib/ssdp/consumer.rb +22 -7
- data/lib/ssdp/producer.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45a022bdf308b1a26cb8e290067a9882f97e0d15
|
4
|
+
data.tar.gz: c5b651cee29b9a61788da711ec6e9797fef72c2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60672a24ffd30f738f26773195cd2956be4c860a5580f5d79d4bea223e83d45587f4d38e5f114490f01e378da9fa1586eedb5ea575b090c9a69ad56d485d2257
|
7
|
+
data.tar.gz: fd617fa6bc5d97013297fb7542cd58ebd5e6e9d2178d0f3534d3117f7ba5d12b45ab0a302c10207d893bad4f551cd80936b8bca25ade21c35e887069662660a1
|
data/lib/ssdp.rb
CHANGED
@@ -6,18 +6,19 @@ require_relative 'ssdp/consumer'
|
|
6
6
|
module SSDP
|
7
7
|
DEFAULTS = {
|
8
8
|
# Shared
|
9
|
-
:broadcast
|
10
|
-
:bind
|
11
|
-
:port
|
12
|
-
:maxpack
|
9
|
+
:broadcast => '239.255.255.250',
|
10
|
+
:bind => '0.0.0.0',
|
11
|
+
:port => 1900,
|
12
|
+
:maxpack => 65_507,
|
13
13
|
# Producer-Only
|
14
|
-
:interval
|
15
|
-
:notifier
|
14
|
+
:interval => 30,
|
15
|
+
:notifier => true,
|
16
|
+
:respond_to_all => true,
|
16
17
|
# Consumer-Only
|
17
|
-
:timeout
|
18
|
-
:first_only
|
19
|
-
:synchronous
|
20
|
-
:no_warnings
|
18
|
+
:timeout => 30,
|
19
|
+
:first_only => false,
|
20
|
+
:synchronous => true,
|
21
|
+
:no_warnings => false
|
21
22
|
}
|
22
23
|
|
23
24
|
HEADER_MATCH = /^([^:]+):\s*(.+)$/
|
data/lib/ssdp/consumer.rb
CHANGED
@@ -13,7 +13,7 @@ module SSDP
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
-
def search(options, &block)
|
16
|
+
def search(options = {}, &block)
|
17
17
|
options = @options.merge options
|
18
18
|
options[:callback] ||= block unless block.nil?
|
19
19
|
fail "SSDP consumer async search missing callback." if (options[:synchronous] == false) && options[:callback].nil?
|
@@ -74,16 +74,26 @@ module SSDP
|
|
74
74
|
|
75
75
|
def search_single(options)
|
76
76
|
result = nil
|
77
|
+
found = false
|
77
78
|
|
78
79
|
if options[:timeout]
|
79
|
-
|
80
|
-
|
80
|
+
began = Time.now
|
81
|
+
remaining = options[:timeout]
|
82
|
+
while !found && remaining > 0
|
83
|
+
ready = IO::select [@search_socket], nil, nil, remaining
|
84
|
+
if ready
|
85
|
+
message, producer = @search_socket.recvfrom options[:maxpack]
|
86
|
+
result = process_ssdp_packet message, producer
|
87
|
+
found = options[:filter].nil? ? true : options[:filter].call(result)
|
88
|
+
end
|
89
|
+
remaining = options[:timeout] - (Time.now - began).to_i
|
90
|
+
end
|
91
|
+
else
|
92
|
+
while !found
|
81
93
|
message, producer = @search_socket.recvfrom options[:maxpack]
|
82
94
|
result = process_ssdp_packet message, producer
|
95
|
+
found = options[:filter].nil? ? true : options[:filter].call(result)
|
83
96
|
end
|
84
|
-
else
|
85
|
-
message, producer = @search_socket.recvfrom options[:maxpack]
|
86
|
-
result = process_ssdp_packet message, producer
|
87
97
|
end
|
88
98
|
|
89
99
|
if options[:synchronous]
|
@@ -102,7 +112,12 @@ module SSDP
|
|
102
112
|
ready = IO::select [@search_socket], nil, nil, remaining
|
103
113
|
if ready
|
104
114
|
message, producer = @search_socket.recvfrom options[:maxpack]
|
105
|
-
|
115
|
+
if options[:filter].nil?
|
116
|
+
responses << process_ssdp_packet(message, producer)
|
117
|
+
else
|
118
|
+
result = process_ssdp_packet message, producer
|
119
|
+
responses << result if options[:filter].call(result)
|
120
|
+
end
|
106
121
|
end
|
107
122
|
remaining -= (Time.now - start_time).to_i
|
108
123
|
end
|
data/lib/ssdp/producer.rb
CHANGED
@@ -20,12 +20,12 @@ module SSDP
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def start
|
23
|
-
start_notifier if @options[:notifier]
|
24
|
-
start_listener
|
23
|
+
start_notifier if @notifier[:thread].nil? && @options[:notifier]
|
24
|
+
start_listener if @listener[:thread].nil?
|
25
25
|
end
|
26
26
|
|
27
27
|
def stop(bye_bye = true)
|
28
|
-
|
28
|
+
was_running = running?
|
29
29
|
|
30
30
|
if @listener[:thread] != nil
|
31
31
|
@listener[:thread].exit
|
@@ -35,6 +35,8 @@ module SSDP
|
|
35
35
|
@notifier[:thread].exit
|
36
36
|
@notifier[:thread] = nil
|
37
37
|
end
|
38
|
+
|
39
|
+
@services.each { |type, params| send_bye_bye type, params } if bye_bye && @options[:notifier] && was_running
|
38
40
|
end
|
39
41
|
|
40
42
|
def add_service(type, location_or_param_hash)
|
@@ -47,11 +49,11 @@ module SSDP
|
|
47
49
|
end
|
48
50
|
|
49
51
|
@services[type] = params
|
50
|
-
send_notification type, params if @options[:notifier]
|
52
|
+
send_notification type, params if @options[:notifier] && running?
|
51
53
|
end
|
52
54
|
|
53
55
|
def remove_service(type)
|
54
|
-
@services.delete
|
56
|
+
@services.delete type
|
55
57
|
end
|
56
58
|
|
57
59
|
private
|
@@ -61,6 +63,12 @@ module SSDP
|
|
61
63
|
return unless ssdp[:status].start_with? 'M-SEARCH * HTTP'
|
62
64
|
|
63
65
|
return if ssdp[:params]['ST'].nil?
|
66
|
+
|
67
|
+
if @options[:respond_to_all] && ssdp[:params]['ST'].downcase == 'ssdp:all'
|
68
|
+
@services.each { |service, _| send_response service, consumer }
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
64
72
|
return if @services[ssdp[:params]['ST']].nil?
|
65
73
|
send_response ssdp[:params]['ST'], consumer
|
66
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssdp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dillon Aumiller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: SSDP client/server library. Server notify/part/respond; client search/listen.
|
14
14
|
email: dillonaumiller@gmail.com
|