Class: Pili::Stream
- Inherits:
-
Object
- Object
- Pili::Stream
- Defined in:
- lib/pili/stream.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#hub ⇒ Object
readonly
Returns the value of attribute hub.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#profiles ⇒ Object
readonly
Returns the value of attribute profiles.
-
#publish_key ⇒ Object
Returns the value of attribute publish_key.
-
#publish_security ⇒ Object
Returns the value of attribute publish_security.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #delete ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #hls_live_urls ⇒ Object
- #hls_playback_urls(start_second = -1,, end_second = -1)) ⇒ Object
- #http_flv_live_urls ⇒ Object
-
#initialize(credentials, options = {}) ⇒ Stream
constructor
A new instance of Stream.
- #rtmp_live_urls ⇒ Object
- #rtmp_publish_url ⇒ Object
- #save_as(name, format, start_time, end_time, notify_url = nil) ⇒ Object
- #segments(options = {}) ⇒ Object
- #snapshot(name, format, options = {}) ⇒ Object
- #status ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
- #update(options = {}) ⇒ Object
Constructor Details
#initialize(credentials, options = {}) ⇒ Stream
Returns a new instance of Stream.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pili/stream.rb', line 9 def initialize(credentials, = {}) @credentials = credentials @id = ["id"] @title = ["title"] @hub = ["hub"] @profiles = ["profiles"] || [] @publish_key = ["publishKey"] @publish_security = ["publishSecurity"] @disabled = ["disabled"] @hosts = ["hosts"] @created_at = ["createdAt"] @updated_at = ["updatedAt"] end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def created_at @created_at end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def credentials @credentials end |
#disabled ⇒ Object
Returns the value of attribute disabled.
6 7 8 |
# File 'lib/pili/stream.rb', line 6 def disabled @disabled end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def hosts @hosts end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def hub @hub end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def id @id end |
#profiles ⇒ Object (readonly)
Returns the value of attribute profiles.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def profiles @profiles end |
#publish_key ⇒ Object
Returns the value of attribute publish_key.
6 7 8 |
# File 'lib/pili/stream.rb', line 6 def publish_key @publish_key end |
#publish_security ⇒ Object
Returns the value of attribute publish_security.
6 7 8 |
# File 'lib/pili/stream.rb', line 6 def publish_security @publish_security end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def title @title end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
5 6 7 |
# File 'lib/pili/stream.rb', line 5 def updated_at @updated_at end |
Instance Method Details
#delete ⇒ Object
45 46 47 |
# File 'lib/pili/stream.rb', line 45 def delete API.delete_stream(@credentials, @id) end |
#disable ⇒ Object
40 41 42 |
# File 'lib/pili/stream.rb', line 40 def disable API.update_stream(@credentials, @id, disabled: true) end |
#enable ⇒ Object
35 36 37 |
# File 'lib/pili/stream.rb', line 35 def enable API.update_stream(@credentials, @id, disabled: false) end |
#hls_live_urls ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pili/stream.rb', line 94 def hls_live_urls live_hls_host = @hosts["live"]["hls"] urls = { Config.origin => "http://#{live_hls_host}/#{@hub}/#{@title}.m3u8" } @profiles.each do |profile| urls[profile] = "http://#{live_hls_host}/#{@hub}/#{@title}@#{profile}.m3u8" end urls end |
#hls_playback_urls(start_second = -1,, end_second = -1)) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/pili/stream.rb', line 107 def hls_playback_urls(start_second = -1, end_second = -1) name = Time.now.to_i.to_s resp = API.save_stream_as(@credentials, @id, name, nil, start_second, end_second) urls = { Config.origin => resp["url"] } urls end |
#http_flv_live_urls ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pili/stream.rb', line 81 def http_flv_live_urls live_hdl_host = @hosts["live"]["hdl"] urls = { Config.origin => "http://#{live_hdl_host}/#{@hub}/#{@title}.flv" } @profiles.each do |profile| urls[profile] = "http://#{live_hdl_host}/#{@hub}/#{@title}@#{profile}.flv" end urls end |
#rtmp_live_urls ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pili/stream.rb', line 68 def rtmp_live_urls live_rtmp_host = @hosts["live"]["rtmp"] urls = { Config.origin => "rtmp://#{live_rtmp_host}/#{@hub}/#{@title}" } @profiles.each do |profile| urls[profile] = "rtmp://#{live_rtmp_host}/#{@hub}/#{@title}@#{profile}" end urls end |
#rtmp_publish_url ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pili/stream.rb', line 55 def rtmp_publish_url rtmp_publish_host = @hosts["publish"]["rtmp"] if @publish_security == "static" return "rtmp://#{rtmp_publish_host}/#{@hub}/#{@title}?key=#{@publish_key}" else nonce = Time.now.to_i token = Credentials.sign(publish_key, "/#{@hub}/#{@title}?nonce=#{nonce}") return "rtmp://#{rtmp_publish_host}/#{@hub}/#{@title}?nonce=#{nonce}&token=#{token}" end end |
#save_as(name, format, start_time, end_time, notify_url = nil) ⇒ Object
137 138 139 |
# File 'lib/pili/stream.rb', line 137 def save_as(name, format, start_time, end_time, notify_url = nil) API.save_stream_as(@credentials, @id, name, format, start_time, end_time, notify_url) end |
#segments(options = {}) ⇒ Object
50 51 52 |
# File 'lib/pili/stream.rb', line 50 def segments( = {}) API.get_stream_segments(@credentials, @id, ) end |
#snapshot(name, format, options = {}) ⇒ Object
132 133 134 |
# File 'lib/pili/stream.rb', line 132 def snapshot(name, format, = {}) API.snapshot(@credentials, @id, name, format, ) end |
#status ⇒ Object
25 26 27 |
# File 'lib/pili/stream.rb', line 25 def status API.get_stream_status(@credentials, @id) end |
#to_h ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/pili/stream.rb', line 142 def to_h { credentials: @credentials, id: @id, title: @title, hub: @hub, profiles: @profiles, publish_key: @publish_key, publish_security: @publish_security, disabled: @disabled, hosts: @hosts, created_at: @created_at, updated_at: @updated_at } end |
#to_json ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pili/stream.rb', line 116 def to_json { id: @id, title: @title, hub: @hub, profiles: @profiles, publish_key: @publish_key, publish_security: @publish_security, disabled: @disabled, hosts: @hosts, created_at: @created_at, updated_at: @updated_at }.to_json end |
#update(options = {}) ⇒ Object
30 31 32 |
# File 'lib/pili/stream.rb', line 30 def update( = {}) API.update_stream(@credentials, @id, self.to_h.merge!()) end |