Ejemplo n.º 1
0
        /**
         * Sets the layout type for the broadcast. For a description of layout types, see
         * <a href="hhttps://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts">Configuring
         *  the video layout for OpenTok live streaming broadcasts</a>.
         * @param broadcastId The broadcast ID of the broadcasting session
         *
         * @param layout The BroadcastLayout that defines layout options for the broadcast.
         *
         */
        public void SetBroadcastLayout(string broadcastId, BroadcastLayout layout)
        {
            string url     = string.Format("v2/project/{0}/broadcast/{1}/layout", this.ApiKey, broadcastId);
            var    headers = new Dictionary <string, string> {
                { "Content-type", "application/json" }
            };
            var data = new Dictionary <string, object>();

            if (layout != null)
            {
                if ((layout.Type.Equals(BroadcastLayout.LayoutType.Custom) && String.IsNullOrEmpty(layout.Stylesheet)) ||
                    (!layout.Type.Equals(BroadcastLayout.LayoutType.Custom) && !String.IsNullOrEmpty(layout.Stylesheet)))
                {
                    throw new OpenTokArgumentException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
                }
                else
                {
                    data.Add("type", OpenTokUtils.convertToCamelCase(layout.Type.ToString()));
                    if (layout.Type.Equals(BroadcastLayout.LayoutType.Custom))
                    {
                        data.Add("stylesheet", layout.Stylesheet);
                    }
                }
            }

            Client.Put(url, headers, data);
        }
Ejemplo n.º 2
0
        /**
         * Use this method to start a live streaming for an OpenTok session.
         * This broadcasts the session to an HLS (HTTP live streaming) or to RTMP streams.
         * <p>
         * To successfully start broadcasting a session, at least one client must be connected to the session.
         * <p>
         * You can only have one active live streaming broadcast at a time for a session
         * (however, having more than one would not be useful).
         * The live streaming broadcast can target one HLS endpoint and up to five RTMP servers simulteneously for a session.
         * You can only start live streaming for sessions that use the OpenTok Media Router (with the media mode set to routed);
         * you cannot use live streaming with sessions that have the media mode set to relayed OpenTok Media Router. See
         * <a href="https://tokbox.com/developer/guides/create-session/#media-mode">The OpenTok Media Router and media modes.</a>
         * <p>
         * For more information on broadcasting, see the
         * <a href="https://tokbox.com/developer/guides/broadcast/">Broadcast developer guide.</a>
         *
         * @param sessionId The session ID corresponding to the session.
         *
         * @param properties This BroadcastProperties object defines options for the broadcast.
         *
         * @return The Broadcast object. This object includes properties defining the archive, including the archive ID.
         */
        public Broadcast StartBroadcast(string sessionId, Boolean hls = true, List <Rtmp> rtmpList = null, string resolution = null, int maxDuration = 7200, BroadcastLayout layout = null)
        {
            if (String.IsNullOrEmpty(sessionId))
            {
                throw new OpenTokArgumentException("Session not valid");
            }

            if (!String.IsNullOrEmpty(resolution) && resolution != "640x480" && resolution != "1280x720")
            {
                throw new OpenTokArgumentException("Resolution value must be either 640x480 (SD) or 1280x720 (HD).");
            }

            if (maxDuration < 60 || maxDuration > 36000)
            {
                throw new OpenTokArgumentException("MaxDuration value must be between 60 and 36000 (inclusive).");
            }

            if (rtmpList != null && rtmpList.Count() >= 5)
            {
                throw new OpenTokArgumentException("Cannot add more than 5 RTMP properties");
            }

            string url     = string.Format("v2/project/{0}/broadcast", this.ApiKey);
            var    headers = new Dictionary <string, string> {
                { "Content-type", "application/json" }
            };
            var outputs = new Dictionary <string, object>();

            if (hls)
            {
                outputs.Add("hls", new Object());
            }

            if (rtmpList != null)
            {
                outputs.Add("rtmp", rtmpList);
            }

            var data = new Dictionary <string, object>()
            {
                { "sessionId", sessionId },
                { "maxDuration", maxDuration },
                { "outputs", outputs }
            };

            if (!String.IsNullOrEmpty(resolution))
            {
                data.Add("resolution", resolution);
            }

            if (layout != null)
            {
                if ((layout.Type.Equals(BroadcastLayout.LayoutType.Custom) && String.IsNullOrEmpty(layout.Stylesheet)) ||
                    (!layout.Type.Equals(BroadcastLayout.LayoutType.Custom) && !String.IsNullOrEmpty(layout.Stylesheet)))
                {
                    throw new OpenTokArgumentException("Could not set the layout. Either an invalid JSON or an invalid layout options.");
                }
                else
                {
                    if (layout.Type.Equals(BroadcastLayout.LayoutType.Custom))
                    {
                        data.Add("layout", layout);
                    }
                    else
                    {
                        data.Add("layout", new { type = OpenTokUtils.convertToCamelCase(layout.Type.ToString()) });
                    }
                }
            }

            string response = Client.Post(url, headers, data);

            return(OpenTokUtils.GenerateBroadcast(response, ApiKey, ApiSecret, OpenTokServer));
        }