Class: OpenTok::Broadcasts
- Inherits:
-
Object
- Object
- OpenTok::Broadcasts
- Defined in:
- lib/opentok/broadcasts.rb
Overview
A class for working with OpenTok live streaming broadcasts. See / Live streaming broadcasts.
Instance Method Summary collapse
-
#add_stream(broadcast_id, stream_id, options) ⇒ Object
Adds a stream to currently running broadcast that was started with the streamMode set to “manual”.
-
#all(options = {}) ⇒ BroadcastList
Returns a BroadcastList, which is an array of broadcasts that are completed and in-progress, for your API key.
-
#create(session_id, options = {}) ⇒ Broadcast
Starts a live streaming broadcast of an OpenTok session.
-
#find(broadcast_id) ⇒ Broadcast
Gets a Broadcast object for the given broadcast ID.
-
#layout(broadcast_id, options = {}) ⇒ Object
Dynamically alters the layout an OpenTok broadcast.
-
#remove_stream(broadcast_id, stream_id) ⇒ Object
Removes a stream from a currently running broadcast that was started with the streamMode set to “manual”.
-
#stop(broadcast_id) ⇒ Broadcast
Stops an OpenTok broadcast.
Instance Method Details
#add_stream(broadcast_id, stream_id, options) ⇒ Object
Adds a stream to currently running broadcast that was started with the streamMode set to “manual”. For a description of the feature, see https://tokbox.com/developer/rest/#selecting-broadcast-streams.
You can call the method repeatedly with add_stream set to the same stream ID, to toggle the stream’s audio or video in the broadcast. If you set both has_audio and has_video to false, you will get error response.
267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/opentok/broadcasts.rb', line 267 def add_stream(broadcast_id, stream_id, ) raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty? raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty? if .has_key?(:has_audio) && .has_key?(:has_video) has_audio = [:has_audio] has_video = [:has_video] raise ArgumentError, "has_audio and has_video can't both be false" if (has_audio, has_video) end ['add_stream'] = stream_id @client.select_streams_for_broadcast(broadcast_id, ) end |
#all(options = {}) ⇒ BroadcastList
Returns a BroadcastList, which is an array of broadcasts that are completed and in-progress, for your API key.
156 157 158 159 160 161 |
# File 'lib/opentok/broadcasts.rb', line 156 def all( = {}) raise ArgumentError, "Limit is invalid" unless [:count].nil? || (0..1000).include?([:count]) broadcast_list_json = @client.list_broadcasts([:offset], [:count], [:sessionId]) BroadcastList.new self, broadcast_list_json end |
#create(session_id, options = {}) ⇒ Broadcast
Starts a live streaming broadcast of an OpenTok session.
Clients must be actively connected to the OpenTok session for you to successfully start a broadcast.
This broadcasts the session to an HLS (HTTP live streaming) or to RTMP streams.
Broadcasts#find method.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/opentok/broadcasts.rb', line 113 def create(session_id, = {}) raise ArgumentError, "session_id not provided" if session_id.to_s.empty? raise ArgumentError, "options cannot be empty" if .empty? raise ArgumentError, "outputs property is required in options" unless .has_key?(:outputs) raise ArgumentError, "outputs must be a Hash" unless [:outputs].is_a? Hash if [:outputs].has_key?(:hls) dvr = [:outputs][:hls][:dvr] low_latency = [:outputs][:hls][:low_latency] raise ArgumentError, "dvr and low_latency can't both be true for HLS" if (dvr, low_latency) end broadcast_json = @client.start_broadcast(session_id, ) Broadcast.new self, broadcast_json end |
#find(broadcast_id) ⇒ Broadcast
Gets a Broadcast object for the given broadcast ID.
137 138 139 140 141 |
# File 'lib/opentok/broadcasts.rb', line 137 def find(broadcast_id) raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty? broadcast_json = @client.get_broadcast(broadcast_id.to_s) Broadcast.new self, broadcast_json end |
#layout(broadcast_id, options = {}) ⇒ Object
Dynamically alters the layout an OpenTok broadcast. For more information, see For more information, see Configuring video layout for OpenTok live streaming broadcasts.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/opentok/broadcasts.rb', line 221 def layout(broadcast_id, = {}) raise ArgumentError, "option parameter is empty" if .empty? raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty? type = [:type] raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!.key? :stylesheet) valid_non_custom_layouts = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""] valid_non_custom_type = valid_non_custom_layouts.include? type raise ArgumentError, "type is not valid" if !valid_non_custom_type && !(type.eql? "custom") raise ArgumentError, "stylesheet not needed" if valid_non_custom_type and .key? :stylesheet raise ArgumentError, "screenshare_type is not valid" if [:screenshare_type] && !valid_non_custom_layouts.include?([:screenshare_type]) raise ArgumentError, "type must be set to 'bestFit' if screenshare_type is defined" if [:screenshare_type] && type != 'bestFit' response = @client.layout_broadcast(broadcast_id, ) (200..300).include? response.code end |
#remove_stream(broadcast_id, stream_id) ⇒ Object
Removes a stream from a currently running broadcast that was started with the streamMode set to “manual”. For a description of the feature, see https://tokbox.com/developer/rest/#selecting-broadcast-streams.
296 297 298 299 300 301 302 303 |
# File 'lib/opentok/broadcasts.rb', line 296 def remove_stream(broadcast_id, stream_id) raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty? raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty? = {} ['remove_stream'] = stream_id @client.select_streams_for_broadcast(broadcast_id, ) end |
#stop(broadcast_id) ⇒ Broadcast
Stops an OpenTok broadcast
Note that broadcasts automatically stop after 120 minute
175 176 177 178 179 |
# File 'lib/opentok/broadcasts.rb', line 175 def stop(broadcast_id) raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty? broadcast_json = @client.stop_broadcast(broadcast_id) Broadcast.new self, broadcast_json end |