rbsrt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +752 -0
- data/Rakefile +29 -0
- data/bin/rbsrt-client +113 -0
- data/bin/rbsrt-server +68 -0
- data/bin/rbsrt-sockets +82 -0
- data/ext/rbsrt/extconf.rb +37 -0
- data/ext/rbsrt/rbsrt.c +2270 -0
- data/ext/rbsrt/rbsrt.h +265 -0
- data/ext/rbsrt/rbstats.c +960 -0
- data/ext/rbsrt/rbstats.h +24 -0
- data/lib/rbsrt/rbsrt.bundle +0 -0
- data/lib/rbsrt/streamid_components.rb +113 -0
- data/lib/rbsrt/version.rb +3 -0
- data/lib/rbsrt.rb +5 -0
- data/rbsrt.gemspec +22 -0
- data/test/rbsrt/poll_test.rb +153 -0
- data/test/rbsrt/stats_test.rb +546 -0
- data/test/rbsrt/streamid_components_test.rb +281 -0
- metadata +83 -0
@@ -0,0 +1,281 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
require "rbsrt"
|
4
|
+
|
5
|
+
describe SRT::StreamIDComponents do
|
6
|
+
it "can be created with no arguments" do
|
7
|
+
parser = SRT::StreamIDComponents.new
|
8
|
+
refute(parser == nil)
|
9
|
+
parser.mode.must_equal :request
|
10
|
+
parser.type.must_equal :stream
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "parsing" do
|
14
|
+
describe "non access control style streamid" do
|
15
|
+
|
16
|
+
let(:parser) {
|
17
|
+
SRT::StreamIDComponents.new("mystream00")
|
18
|
+
}
|
19
|
+
|
20
|
+
it "uses the streamid as resource name" do
|
21
|
+
parser.resource_name.must_equal "mystream00"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has no user name" do
|
25
|
+
parser.user_name.must_be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has :stream mode" do
|
29
|
+
parser.mode.must_equal :request
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has no host name" do
|
33
|
+
parser.host_name.must_be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has :request type" do
|
37
|
+
parser.type.must_equal :stream
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has no session id" do
|
41
|
+
parser.sessionid.must_be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has no additional info" do
|
45
|
+
parser.extra.must_be_empty
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "access control style streamid string" do
|
50
|
+
let(:streamid) { "#!::r=foobar,u=admin,h=stream.recce.nl,s=12345,t=stream,m=publish" }
|
51
|
+
|
52
|
+
let(:parser) {
|
53
|
+
SRT::StreamIDComponents.new(streamid)
|
54
|
+
}
|
55
|
+
|
56
|
+
it "uses the 'r' var as the resource name" do
|
57
|
+
parser.resource_name.must_equal "foobar"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "uses the 'u' var as user name" do
|
61
|
+
parser.user_name.must_equal "admin"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "uses the 'm' var as mode" do
|
65
|
+
parser.mode.must_equal :publish
|
66
|
+
end
|
67
|
+
|
68
|
+
it "uses the 'h' var as host name" do
|
69
|
+
parser.host_name.must_equal "stream.recce.nl"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "uses the 't' var as type" do
|
73
|
+
parser.type.must_equal :stream
|
74
|
+
end
|
75
|
+
|
76
|
+
it "uses the 's' var as session id" do
|
77
|
+
parser.sessionid.must_equal "12345"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "type parsing" do
|
82
|
+
it "parses 'stream' as :stream" do
|
83
|
+
SRT::StreamIDComponents.new("#!::t=stream").type.must_equal :stream
|
84
|
+
end
|
85
|
+
|
86
|
+
it "parses 'file' as :file" do
|
87
|
+
SRT::StreamIDComponents.new("#!::t=file").type.must_equal :file
|
88
|
+
end
|
89
|
+
|
90
|
+
it "parses 'auth' as :auth" do
|
91
|
+
SRT::StreamIDComponents.new("#!::t=auth").type.must_equal :auth
|
92
|
+
end
|
93
|
+
|
94
|
+
it "parses unknown types to :stream" do
|
95
|
+
SRT::StreamIDComponents.new("#!::t=foo").type.must_equal :stream
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "mode parsing" do
|
100
|
+
it "parses 'request' as :request" do
|
101
|
+
SRT::StreamIDComponents.new("#!::m=request").mode.must_equal :request
|
102
|
+
end
|
103
|
+
|
104
|
+
it "parses 'publish' as :publish" do
|
105
|
+
SRT::StreamIDComponents.new("#!::m=publish").mode.must_equal :publish
|
106
|
+
end
|
107
|
+
|
108
|
+
it "parses 'bidirectional' as :bidirectional" do
|
109
|
+
SRT::StreamIDComponents.new("#!::m=bidirectional").mode.must_equal :bidirectional
|
110
|
+
end
|
111
|
+
|
112
|
+
it "parses unknown modes to :request" do
|
113
|
+
SRT::StreamIDComponents.new("#!::t=foo").mode.must_equal :request
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "host parsing" do
|
118
|
+
it "removes any pathname from the host" do
|
119
|
+
SRT::StreamIDComponents.new("#!::h=stream.recce.nl/my/movie.ts").host_name.must_equal "stream.recce.nl"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "uses the host pathname as resource name when no 'r' var is provided" do
|
123
|
+
SRT::StreamIDComponents.new("#!::h=stream.recce.nl/my/movie.ts").resource_name.must_equal "my/movie.ts"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not use the host pathname as resource name when 'r' var is provided" do
|
127
|
+
SRT::StreamIDComponents.new("#!::r=foo,h=stream.recce.nl/my/movie.ts").resource_name.must_equal "foo"
|
128
|
+
SRT::StreamIDComponents.new("#!::h=stream.recce.nl/my/movie.ts,r=foo").resource_name.must_equal "foo"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "parsing unknown values" do
|
133
|
+
it "adds unknown values as properties" do
|
134
|
+
parser = SRT::StreamIDComponents.new("#!::foo=bar")
|
135
|
+
parser.extra.wont_be_empty
|
136
|
+
parser.foo.must_equal "bar"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "can add properties" do
|
140
|
+
parser = SRT::StreamIDComponents.new
|
141
|
+
|
142
|
+
parser.foo.must_be_nil nil
|
143
|
+
|
144
|
+
parser.foo = "bar"
|
145
|
+
parser.foo.must_equal "bar"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "initialize with a hash" do
|
150
|
+
|
151
|
+
let(:parser) do
|
152
|
+
SRT::StreamIDComponents.new :mode => :publish,
|
153
|
+
:type => :stream,
|
154
|
+
:resource_name => "my_movie.ts"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "sets the properties" do
|
158
|
+
parser.mode.must_equal :publish
|
159
|
+
parser.type.must_equal :stream
|
160
|
+
parser.resource_name.must_equal "my_movie.ts"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "initialize with a URL" do
|
165
|
+
describe "shorthand variables" do
|
166
|
+
let(:url) { "srt://stream.recce.nl:5555?r=foo&t=stream&m=publish&u=admin&s=45678&custom=baz" }
|
167
|
+
|
168
|
+
let(:parser) { SRT::StreamIDComponents.new(url) }
|
169
|
+
|
170
|
+
it "uses the 'r' query var as the resource name" do
|
171
|
+
parser.resource_name.must_equal "foo"
|
172
|
+
end
|
173
|
+
|
174
|
+
it "uses the 'u' query var as user name" do
|
175
|
+
parser.user_name.must_equal "admin"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "uses the 'm' query var as mode" do
|
179
|
+
parser.mode.must_equal :publish
|
180
|
+
end
|
181
|
+
|
182
|
+
it "uses the host as host name" do
|
183
|
+
parser.host_name.must_equal "stream.recce.nl"
|
184
|
+
end
|
185
|
+
|
186
|
+
it "uses the 't' query var as type" do
|
187
|
+
parser.type.must_equal :stream
|
188
|
+
end
|
189
|
+
|
190
|
+
it "uses the 's' query var as session id" do
|
191
|
+
parser.sessionid.must_equal "45678"
|
192
|
+
end
|
193
|
+
|
194
|
+
it "stores custom variables" do
|
195
|
+
parser.custom.must_equal "baz"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "pathname" do
|
200
|
+
let(:url) { "srt://stream.recce.nl:5555/my/movie.ts" }
|
201
|
+
|
202
|
+
let(:parser) { SRT::StreamIDComponents.new(url) }
|
203
|
+
|
204
|
+
it "uses the path as the resource name" do
|
205
|
+
parser.resource_name.must_equal "my/movie.ts"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "compiling" do
|
212
|
+
|
213
|
+
let(:parser) { SRT::StreamIDComponents.new }
|
214
|
+
|
215
|
+
before do
|
216
|
+
parser.resource_name = "myresource"
|
217
|
+
parser.user_name = "emma"
|
218
|
+
parser.mode = :publish
|
219
|
+
parser.host_name = "stream2.recce.nl"
|
220
|
+
parser.type = :file
|
221
|
+
parser.sessionid = "bcde"
|
222
|
+
|
223
|
+
# extra properties
|
224
|
+
parser.baz = "bar"
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "to_s" do
|
228
|
+
let(:streamid) { parser.to_s }
|
229
|
+
|
230
|
+
it "can compile to a streamid string" do
|
231
|
+
streamid.wont_be_nil
|
232
|
+
streamid.must_be_instance_of String
|
233
|
+
streamid.wont_be_empty
|
234
|
+
streamid.must_match /^#!::/
|
235
|
+
end
|
236
|
+
|
237
|
+
it "sets the 'r' var to the resource name" do
|
238
|
+
streamid.must_match /(::|,)r=myresource(,|$)/
|
239
|
+
end
|
240
|
+
|
241
|
+
it "sets the 'u' var to the user name" do
|
242
|
+
streamid.must_match /(::|,)u=emma(,|$)/
|
243
|
+
end
|
244
|
+
|
245
|
+
it "sets the 'm' var to the mode" do
|
246
|
+
streamid.must_match /(::|,)m=publish(,|$)/
|
247
|
+
end
|
248
|
+
|
249
|
+
it "sets the 'h' var to the host name" do
|
250
|
+
streamid.must_match /(::|,)h=stream2.recce.nl(,|$)/
|
251
|
+
end
|
252
|
+
|
253
|
+
it "sets the 't' var to the type" do
|
254
|
+
streamid.must_match /(::|,)t=file(,|$)/
|
255
|
+
end
|
256
|
+
|
257
|
+
it "sets the 's' var to the sessionid" do
|
258
|
+
streamid.must_match /(::|,)s=bcde(,|$)/
|
259
|
+
end
|
260
|
+
|
261
|
+
it "adds extra attributes when available" do
|
262
|
+
streamid.must_match /(::|,)baz=bar(,|$)/
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it "can parse it's own output" do
|
267
|
+
s = SRT::StreamIDComponents.new(parser.to_s)
|
268
|
+
|
269
|
+
s.resource_name.must_equal "myresource"
|
270
|
+
s.user_name.must_equal "emma"
|
271
|
+
s.mode.must_equal :publish
|
272
|
+
s.host_name.must_equal "stream2.recce.nl"
|
273
|
+
s.type.must_equal :file
|
274
|
+
s.sessionid.must_equal "bcde"
|
275
|
+
|
276
|
+
# extra properties
|
277
|
+
s.baz.must_equal "bar"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbsrt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Klaas Speller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Build SRT (Secure Reliable Transport) servers and clients with Ruby
|
28
|
+
email:
|
29
|
+
- klaas@recce.nl
|
30
|
+
executables:
|
31
|
+
- rbsrt-server
|
32
|
+
- rbsrt-client
|
33
|
+
extensions:
|
34
|
+
- ext/rbsrt/extconf.rb
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/rbsrt-client
|
40
|
+
- bin/rbsrt-server
|
41
|
+
- bin/rbsrt-sockets
|
42
|
+
- ext/rbsrt/extconf.rb
|
43
|
+
- ext/rbsrt/rbsrt.c
|
44
|
+
- ext/rbsrt/rbsrt.h
|
45
|
+
- ext/rbsrt/rbstats.c
|
46
|
+
- ext/rbsrt/rbstats.h
|
47
|
+
- lib/rbsrt.rb
|
48
|
+
- lib/rbsrt/rbsrt.bundle
|
49
|
+
- lib/rbsrt/streamid_components.rb
|
50
|
+
- lib/rbsrt/version.rb
|
51
|
+
- rbsrt.gemspec
|
52
|
+
- test/rbsrt/poll_test.rb
|
53
|
+
- test/rbsrt/stats_test.rb
|
54
|
+
- test/rbsrt/streamid_components_test.rb
|
55
|
+
homepage: https://github.com/spllr/rbsrt
|
56
|
+
licenses:
|
57
|
+
- MPLv2.0
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
source_code_uri: https://github.com/spllr/rbsrt
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.2.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.0.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Ruby API for SRT (Secure Reliable Transport)
|
80
|
+
test_files:
|
81
|
+
- test/rbsrt/stats_test.rb
|
82
|
+
- test/rbsrt/streamid_components_test.rb
|
83
|
+
- test/rbsrt/poll_test.rb
|