Module: Pili
- Defined in:
- lib/pili.rb,
lib/pili/auth.rb,
lib/pili/http.rb,
lib/pili/utils.rb,
lib/pili/config.rb,
lib/pili/version.rb
Defined Under Namespace
Modules: Auth, Config, Utils
Classes: HTTP
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
-
.create_stream(hub, options = {}) ⇒ Object
-
.delete_stream(stream_id) ⇒ Object
-
.get_stream(stream_id) ⇒ Object
-
.get_stream_hls_live_url(play_host, stream_id, preset = nil) ⇒ Object
-
.get_stream_hls_playback_url(play_host, stream_id, start_second, end_second, preset = nil) ⇒ Object
-
.get_stream_publish_url(publish_host, stream_id, publish_key, publish_security, nonce = nil) ⇒ Object
-
.get_stream_rtmp_live_url(play_host, stream_id, preset = nil) ⇒ Object
-
.get_stream_segments(stream_id, options = {}) ⇒ Object
-
.setup!(options = {}) ⇒ Object
-
.stream_list(hub, options = {}) ⇒ Object
-
.update_stream(stream_id, options = {}) ⇒ Object
Class Method Details
.create_stream(hub, options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/pili.rb', line 30
def create_stream(hub, options = {})
url = Config.api_base_url + "/streams"
body = {
:hub => hub,
:title => options[:title],
:publishKey => options[:publish_key],
:publishSecurity => options[:publish_security] == "static" ? "static" : "dynamic",
:clientIp => options[:client_ip]
}
body.delete_if { |k, v| v.nil? }
response = HTTP.api_post(url, body)
response.parsed_response
end
|
.delete_stream(stream_id) ⇒ Object
70
71
72
73
74
|
# File 'lib/pili.rb', line 70
def delete_stream(stream_id)
url = Config.api_base_url + "/streams/" + stream_id
response = HTTP.api_delete(url)
response.parsed_response
end
|
.get_stream(stream_id) ⇒ Object
48
49
50
51
52
|
# File 'lib/pili.rb', line 48
def get_stream(stream_id)
url = Config.api_base_url + "/streams/" + stream_id
response = HTTP.api_get(url)
response.parsed_response
end
|
.get_stream_hls_live_url(play_host, stream_id, preset = nil) ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'lib/pili.rb', line 114
def get_stream_hls_live_url(play_host, stream_id, preset = nil)
hub, title = Utils.get_stream_hub_and_title(stream_id)
if Utils.blank? preset
return "http://#{play_host}/#{hub}/#{title}.m3u8"
else
return "http://#{play_host}/#{hub}/#{title}@#{preset}.m3u8"
end
end
|
.get_stream_hls_playback_url(play_host, stream_id, start_second, end_second, preset = nil) ⇒ Object
125
126
127
128
129
130
131
132
133
|
# File 'lib/pili.rb', line 125
def get_stream_hls_playback_url(play_host, stream_id, start_second, end_second, preset = nil)
hub, title = Utils.get_stream_hub_and_title(stream_id)
if Utils.blank? preset
return "http://#{play_host}/#{hub}/#{title}.m3u8?start=#{start_second}&end=#{end_second}"
else
return "http://#{play_host}/#{hub}/#{title}@#{preset}.m3u8?start=#{start_second}&end=#{end_second}"
end
end
|
.get_stream_publish_url(publish_host, stream_id, publish_key, publish_security, nonce = nil) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/pili.rb', line 88
def get_stream_publish_url(publish_host, stream_id, publish_key, publish_security, nonce = nil)
nonce = nonce.to_i
nonce = (Time.now.to_f * 1000.0).to_i if nonce == 0
hub, title = Utils.get_stream_hub_and_title(stream_id)
if publish_security == "static"
return "rtmp://#{publish_host}/#{hub}/#{title}?key=#{publish_key}"
else
token = Auth.sign(publish_key, "/#{hub}/#{title}?nonce=#{nonce}")
return "rtmp://#{publish_host}/#{hub}/#{title}?nonce=#{nonce}&token=#{token}"
end
end
|
.get_stream_rtmp_live_url(play_host, stream_id, preset = nil) ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/pili.rb', line 103
def get_stream_rtmp_live_url(play_host, stream_id, preset = nil)
hub, title = Utils.get_stream_hub_and_title(stream_id)
if Utils.blank? preset
return "rtmp://#{play_host}/#{hub}/#{title}"
else
return "rtmp://#{play_host}/#{hub}/#{title}@#{preset}"
end
end
|
.get_stream_segments(stream_id, options = {}) ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/pili.rb', line 77
def get_stream_segments(stream_id, options = {})
url = Config.api_base_url + "/streams/#{stream_id}/segments"
url += "?start=#{options[:start]}" if options[:start].is_a?(Fixnum)
url += "&end=#{options[:end]}" if options[:end].is_a?(Fixnum)
response = HTTP.api_get(url)
response.parsed_response
end
|
.setup!(options = {}) ⇒ Object
14
15
16
|
# File 'lib/pili.rb', line 14
def setup!(options = {})
Config.init(options)
end
|
.stream_list(hub, options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/pili.rb', line 19
def stream_list(hub, options = {})
url = Config.api_base_url + "/streams?hub=#{hub}"
url += "&marker=#{options[:marker]}" unless Utils.blank?(options[:marker])
url += "&limit=#{options[:limit]}" if options[:limit].is_a?(Fixnum)
response = HTTP.api_get(url)
response.parsed_response
end
|
.update_stream(stream_id, options = {}) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/pili.rb', line 55
def update_stream(stream_id, options = {})
url = Config.api_base_url + "/streams/" + stream_id
body = {
:publishKey => options[:publish_key],
:publishSecurity => options[:publish_security] == "static" ? "static" : "dynamic",
}
body.delete_if { |k, v| v.nil? }
response = HTTP.api_post(url, body)
response.parsed_response
end
|