Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

Class: OpenTok::Broadcasts

Inherits:
Object
Defined in:
lib/opentok/broadcasts.rb

Overview

A class for working with OpenTok live streaming broadcasts. See / Live streaming broadcasts.

Instance Method Summary

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.

Parameters:

  • broadcast_id (String)

    The broadcast ID.

  • stream_id (String)

    The ID for the stream to be added to the broadcast

  • opts (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)

    The broadcast_id parameter is empty.

  • (ArgumentError)

    The stream_id parameter is empty.

  • (ArgumentError)

    The has_audio and has_video properties of the options parameter are both set to “false”

#all(options = {}) ⇒ BroadcastList

Returns a BroadcastList, which is an array of broadcasts that are completed and in-progress, for your API key.

tokbox.com/developer/rest/#list_broadcasts

Parameters:

  • options (Hash) (defaults to: {})

    A hash with keys defining which range of broadcasts to retrieve.

Options Hash (options):

  • :offset (integer)

    Optional. The index offset of the first broadcast. 0 is offset of the most recently started broadcast. 1 is the offset of the broadcast that started prior to the most recent broadcast. If you do not specify an offset, 0 is used.

  • :count (integer)

    Optional. The number of broadcasts to be returned. The maximum number of broadcasts returned is 1000.

  • :session_id (String)

    Optional. The session ID that broadcasts belong to.

Returns:

  • (BroadcastList)

    An BroadcastList object, which is an array of Broadcast objects.

Raises:

  • (ArgumentError)

#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.

Parameters:

  • session_id (String)

    The session ID of the OpenTok session to broadcast.

  • options (Hash) (defaults to: {})

    A hash defining options for the broadcast.

Options Hash (options):

  • :layout (Hash)

    Specify this to assign the initial layout type for the broadcast. This is a hash containing three keys: :type, :stylesheet<code> and <code>:screenshare_type. Valid values for :type are “bestFit” (best fit), “custom” (custom),

    "horizontalPresentation" (horizontal presentation),
    

    “pip” (picture-in-picture), and “verticalPresentation” (vertical presentation)). If you specify a “custom” layout type, set the :stylesheet key to the stylesheet (CSS). (For other layout types, do not set the :stylesheet key.) Valid values for :screenshare_type are “bestFit”, “pip”, “verticalPresentation”, “horizontalPresentation”. This property is optional. If it is specified, then the :type property *must* be set to “bestFit”. If you do not specify an initial layout type, the broadcast uses the best fit layout type.

  • :multiBroadcastTag (String) — default: Optional

    Set this to support multiple broadcasts for the same session simultaneously. Set this to a unique string for each simultaneous broadcast of an ongoing session. Note that the `multiBroadcastTag` value is not included in the response for the methods to list live streaming broadcasts and get information about a live streaming broadcast. See Simultaneous broadcasts.

  • maxDuration (int)

    The maximum duration for the broadcast, in seconds. The broadcast will automatically stop when the maximum duration is reached. You can set the maximum duration to a value from 60 (60 seconds) to 36000 (10 hours). The default maximum duration is 4 hours (14,400 seconds).

  • outputs (Hash) — default: Required

    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).

    For multiple RTMP streams, the (:rtmp) property is set to an [Array] of Rtmp [Hash] objects. For each RTMP hash, 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. If you specify an ID, it will be included in the (broadcast_json) response from the Client#start_broadcast method call, and is also available in the (broadcast_json) response from the Broadcasts#find method. Vonage streams the session to each RTMP URL you specify. Note that OpenTok live streaming supports RTMP and RTMPS. If you need to support only one RTMP URL, you can set a Rtmp [Hash] object (instead of an array of objects) for the (:rtmp) property value in the (:outputs) [Hash].

    For HLS, the (:hls) property in the (:outputs) [Hash] is set to a HLS [Hash] object. This object includes the following optional properties:

    • (:dvr) (Boolean). Whether to enable DVR functionality (rewinding, pausing, and resuming) in players that support it (true), or not (false, the default). With DVR enabled, the HLS URL will include a ?DVR query string appended to the end.

    • (:low_latency) (Boolean). Whether to enable low-latency mode for the HLSstream. Some HLS players do not support low-latency mode. This feature is incompatible with DVR mode HLS broadcasts (both can't be set to true). This is a beta feature.

    The HLS URL is included in the (broadcast_json) response from the Client#start_broadcast method call, and is also available in the (broadcast_json) response from the

  • 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).

  • :streamMode (String) — default: Optional

    Whether streams included in the broadcast are selected automatically (“auto”, the default) or manually (“manual”). When streams are selected automatically (“auto”), all streams in the session can be included in the broadcast. When streams are selected manually (“manual”), you specify streams to be included based on calls to the #add_stream method. You can specify whether a stream's audio, video, or both are included in the broadcast. For both automatic and manual modes, the broadcast composer includes streams based on stream prioritization rules. Important: this feature is currently available in the Standard environment only.

Returns:

  • (Broadcast)

    The broadcast object, which includes properties defining the broadcast, including the broadcast ID.

Raises:

#find(broadcast_id) ⇒ Broadcast

Gets a Broadcast object for the given broadcast ID.

Parameters:

  • broadcast_id (String)

    The broadcast ID.

Returns:

  • (Broadcast)

    The broadcast object, which includes properties defining the broadcast.

Raises:

#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.

Parameters:

  • broadcast_id (String)

    The broadcast ID.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :type (String)

    The layout type. Set this to “bestFit”, “pip”, “verticalPresentation”, “horizontalPresentation”, “focus”, or “custom”.

  • :stylesheet (String)

    The stylesheet for a custom layout. Set this parameter if you set type to "custom". Otherwise, leave it undefined.

  • :screenshare_type (String)

    The screenshare layout type. Set this to “bestFit”, “pip”, “verticalPresentation” or “horizonalPresentation”. If this is defined, then the type parameter must be set to "bestFit".

Raises:

  • (OpenTokBroadcastError)

    The broadcast layout could not be updated.

  • (OpenTokAuthenticationError)

    Authentication failed. Invalid API key or secret.

  • (OpenTokError)

    OpenTok server error.

  • (ArgumentError)

    The broadcast_id or options parameter is empty.

  • (ArgumentError)

    The “custom” type was specified without a stylesheet option.

  • (ArgumentError)

    A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.

  • (ArgumentError)

    An invalid layout type was passed in.

#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.

Parameters:

  • broadcast_id (String)

    The broadcast ID.

  • stream_id (String)

    The ID for the stream to be removed from the broadcast

Raises:

  • (ArgumentError)

    The broadcast_id parameter id is empty.

  • (ArgumentError)

    The stream_id parameter is empty.

#stop(broadcast_id) ⇒ Broadcast

Stops an OpenTok broadcast

Note that broadcasts automatically stop after 120 minute

Parameters:

  • broadcast_id (String)

    The broadcast ID.

Returns:

  • (Broadcast)

    The broadcast object, which includes properties defining the broadcast.

Raises: