Class: OpenTok::Broadcast
- Inherits:
-
Object
- Object
- OpenTok::Broadcast
- Defined in:
- lib/opentok/broadcast.rb
Overview
Represents a live streaming broadcast of an OpenTok session. See / Live streaming broadcasts.
Instance Attribute Summary collapse
-
#broadcastUrls ⇒ Hash
is defined as follows: This object defines the types of broadcast streams you want to start (both HLS and RTMP).
-
#created_at ⇒ int
The time at which the broadcast was created, in milliseconds since the UNIX epoch.
-
#hasAudio ⇒ boolean
The broadcast has audio enabled.
-
#hasVideo ⇒ boolean
The broadcast has video enabled.
-
#id ⇒ string
The broadcast ID.
-
#maxBitRate ⇒ int
The maximum bitrate for the broadcast stream(s), in bits per second.
-
#multi_broadcast_tag ⇒ Object
readonly
Returns the value of attribute multi_broadcast_tag.
-
#project_id ⇒ string
The API key associated with the broadcast.
-
#resolution ⇒ string
The resolution of the broadcast: either “640x480” (SD landscape, the default), “1280x720” (HD landscape), “1920x1080” (FHD landscape), “480x640” (SD portrait), “720x1280” (HD portrait), or “1080x1920” (FHD portrait).
-
#session_id ⇒ string
The session ID of the OpenTok session associated with this broadcast.
-
#status ⇒ string
The status of the RTMP stream.
-
#streamMode ⇒ string
Whether streams included in the broadcast are selected automatically (“auto”, the default) or manually (“manual”).
-
#updated_at ⇒ int
For this start method, this timestamp matches the createdAt timestamp.
Instance Method Summary collapse
-
#add_stream(stream_id, opts = {}) ⇒ Object
Adds a stream to currently running broadcast that was started with the streamMode set to “manual”.
-
#layout(opts = {}) ⇒ Object
Sets the layout of the OpenTok broadcast.
-
#remove_stream(stream_id) ⇒ Object
Removes a stream to currently running broadcast that was started with the streamMode set to “manual”.
-
#stop ⇒ Object
Stops the OpenTok broadcast.
-
#to_json ⇒ Object
A JSON-encoded string representation of the broadcast.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/opentok/broadcast.rb', line 166 def method_missing(method, *args, &block) camelized_method = method.to_s.camelize(:lower) if @json.has_key? camelized_method and args.empty? # TODO: convert create_time method call to a Time object if camelized_method == 'outputMode' @json[camelized_method].to_sym else @json[camelized_method] end else super method, *args, &block end end |
Instance Attribute Details
#broadcastUrls ⇒ Hash
is defined as follows: This object defines the types of broadcast streams you want to start (both HLS and RTMP). You can include HLS, RTMP, or both as broadcast streams. If you include RTMP streaming, you can specify up to five target RTMP streams (or just one). The (:hls
) property is set to an empty [Hash] object. The HLS URL is returned in the response. The ‘hlsStatus` property is set to one of the following:
- "connecting" — The OpenTok server is in the process of starting transcoders. This is the initial state.
- "ready" — The OpenTok server has succesfully initialized but the CDN is not consuming media.
- "live" — The OpenTok server has succesfully initialized and the CDN is consuming media.
- "ended" — The source stream has ended. If DVR is enabled and pre-recorded media is requested, then the status will transition to "live".
- "error" — There is an error in the OpenTok platform.
The (:rtmp
) property is set to an [Array] of Rtmp [Hash] properties. For each RTMP stream, specify (:serverUrl
) for the RTMP server URL, (:streamName
) such as the YouTube Live stream name or the Facebook stream key), and (optionally) (:id
), a unique ID for the stream.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def broadcastUrls @broadcastUrls end |
#created_at ⇒ int
The time at which the broadcast was created, in milliseconds since the UNIX epoch.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def created_at @created_at end |
#hasAudio ⇒ boolean
The broadcast has audio enabled
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def hasAudio @hasAudio end |
#hasVideo ⇒ boolean
The broadcast has video enabled
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def hasVideo @hasVideo end |
#id ⇒ string
The broadcast ID.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def id @id end |
#maxBitRate ⇒ int
The maximum bitrate for the broadcast stream(s), in bits per second.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def maxBitRate @maxBitRate end |
#multi_broadcast_tag ⇒ Object (readonly)
Returns the value of attribute multi_broadcast_tag.
64 65 66 |
# File 'lib/opentok/broadcast.rb', line 64 def multi_broadcast_tag @multi_broadcast_tag end |
#project_id ⇒ string
The API key associated with the broadcast.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def project_id @project_id end |
#resolution ⇒ string
The resolution of the broadcast: either “640x480” (SD landscape, the default), “1280x720” (HD landscape), “1920x1080” (FHD landscape), “480x640” (SD portrait), “720x1280” (HD portrait), or “1080x1920” (FHD portrait). You may want to use a portrait aspect ratio for broadcasts that include video streams from mobile devices (which often use the portrait aspect ratio). This property is optional.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def resolution @resolution end |
#session_id ⇒ string
The session ID of the OpenTok session associated with this broadcast.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def session_id @session_id end |
#status ⇒ string
The status of the RTMP stream.
-
“connecting” – The OpenTok platform is in the process of connecting to the remote RTMP server.
This is the initial state, and it is the status if you start when there are no streams published in the session. It changes to "live" when there are streams (or it changes to one of the other states).
-
“live – The OpenTok platform has successfully connected to the remote RTMP server, and the media is streaming.
-
“offline” – The OpenTok platform could not connect to the remote RTMP server. This is due to an unreachable server or an error in the RTMP handshake. Causes include rejected RTMP connections, non-existing RTMP applications, rejected stream names, authentication errors, etc. Check that the server is online, and that you have provided the correct server URL and stream name.
-
“error” – There is an error in the OpenTok platform.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def status @status end |
#streamMode ⇒ string
Whether streams included in the broadcast are selected automatically (“auto”, the default) or manually (“manual”).
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def streamMode @streamMode end |
#updated_at ⇒ int
For this start method, this timestamp matches the createdAt timestamp.
63 64 65 |
# File 'lib/opentok/broadcast.rb', line 63 def updated_at @updated_at end |
Instance Method Details
#add_stream(stream_id, opts = {}) ⇒ 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.
146 147 148 149 |
# File 'lib/opentok/broadcast.rb', line 146 def add_stream(stream_id, opts = {}) raise OpenTokBroadcastError, "stream_mode must be manual in order to add a stream" unless @json['streamMode'] == 'manual' @interface.add_stream(@json['id'], stream_id, opts) end |
#layout(opts = {}) ⇒ Object
Sets the layout of the OpenTok broadcast.
You can dynamically change the layout type of a broadcast while it is being broadcast. For more information, see Configuring video layout for OpenTok live streaming broadcasts.
Refer to https://tokbox.com/developer/rest/#change_composed_archive_layout
120 121 122 123 |
# File 'lib/opentok/broadcast.rb', line 120 def layout(opts = {}) # TODO: validate returned json fits schema @json = @interface.layout(@json['id'], opts) end |
#remove_stream(stream_id) ⇒ Object
Removes 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.
160 161 162 163 |
# File 'lib/opentok/broadcast.rb', line 160 def remove_stream(stream_id) raise OpenTokBroadcastError, "stream_mode must be manual in order to add a stream" unless @json['streamMode'] == 'manual' @interface.remove_stream(@json['id'], stream_id) end |
#stop ⇒ Object
Stops the OpenTok broadcast.
79 80 81 82 |
# File 'lib/opentok/broadcast.rb', line 79 def stop # TODO: validate returned json fits schema @json = @interface.stop @json['id'] end |
#to_json ⇒ Object
A JSON-encoded string representation of the broadcast.
74 75 76 |
# File 'lib/opentok/broadcast.rb', line 74 def to_json @json.to_json end |