Exemple #1
0
        /**
         * Creates a new OpenTok session.
         * <p>
         * OpenTok sessions do not expire. However, authentication tokens do expire (see the
         * generateToken() method). Also note that sessions cannot explicitly be destroyed.
         * <p>
         * A session ID string can be up to 255 characters long.
         * <p>
         * Calling this method results in an OpenTokException in the event of an error.
         * Check the error message for details.
         *
         * You can also create a session using the
         * <a href="http://www.tokbox.com/opentok/api/#session_id_production">OpenTok
         * REST API</a> or the <a href="https://dashboard.tokbox.com/projects">OpenTok
         * sdashboard</a>.
         *
         * @param location (String) An IP address that the OpenTok servers will use to
         * situate the session in its global network. If you do not set a location hint,
         * the OpenTok servers will be based on the first client connecting to the session.
         *
         * @param mediaMode determine whether the session will transmit streams using the
         * OpenTok Media Router (MediaMode.ROUTED) or not (MediaMode.RELAYED). By default, sessions
         * use the OpenTok Media Router.
         * <p>
         * The <a href="http://tokbox.com/#multiparty" target="_top"> OpenTok Media Router</a>
         * provides the following benefits:
         *
         * <ul>
         *   <li>The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
         *       (When the <code>mediaMode</code> parameter is set to
         *       <code>MediaMode.ROUTED</code>, each client must send a separate audio-video stream
         *      to each client subscribing to it.)</li>
         *   <li>The OpenTok Media Router can improve the quality of the user experience through
         *     <a href="http://tokbox.com/#iqc" target="_top">Intelligent Quality Control</a>. With
         *     Intelligent Quality Control, if a client's connectivity degrades to a degree that
         *     it does not support video for a stream it's subscribing to, the video is dropped on
         *     that client (without affecting other clients), and the client receives audio only.
         *     If the client's connectivity improves, the video returns.</li>
         *   <li>The OpenTok Media Router supports the
         *     <a href="http://tokbox.com/#archiving" target="_top">archiving and playback</a>
         *     feature, which lets you record, save, and retrieve OpenTok sessions.</li>
         * </ul>
         *
         * <p>
         * With the <code>mediaMode</code> parameter set to <code>MediaMode.RELAYED</code>, the
         * session will attempt to transmit streams directly between clients. If clients cannot
         * connect due to firewall restrictions, the session uses the OpenTok TURN server to relay
         * streams.
         * <p>
         * You will be billed for streamed minutes if you use the OpenTok Media Router or if the
         * session uses the OpenTok TURN server to relay streams. For information on pricing, see
         * the <a href="http://www.tokbox.com/pricing" target="_top">OpenTok pricing page</a>.
         *
         * @return A Session object representing the new session. The <code>Id</code> property of
         * the Session is the session ID, which uniquely identifies the session. You will use
         * this session ID in the client SDKs to identify the session. For example, when using the
         * OpenTok.js library, use the session ID when calling the
         * <a href="http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession">
         * OT.initSession()</a> method (to initialize an OpenTok session).
         */
        public Session CreateSession(string location = "", MediaMode mediaMode = MediaMode.ROUTED)
        {
            if (!OpenTokUtils.TestIpAddress(location))
            {
                throw new OpenTokArgumentException(string.Format("Location {0} is not a valid IP address", location));
            }
            string preference = (mediaMode == MediaMode.RELAY) ? "enabled" : "disabled";

            var headers = new Dictionary <string, string> {
                { "Content-type", "application/x-www-form-urlencoded" }
            };
            var data = new Dictionary <string, object>
            {
                { "location", location },
                { "p2p.preference", preference }
            };

            var response = Client.Post("session/create", headers, data);
            var xmlDoc   = Client.ReadXmlResponse(response);

            if (xmlDoc.GetElementsByTagName("session_id").Count == 0)
            {
                throw new OpenTokWebException("Session could not be provided. Are ApiKey and ApiSecret correctly set?");
            }
            var sessionId = xmlDoc.GetElementsByTagName("session_id")[0].ChildNodes[0].Value;
            var apiKey    = Convert.ToInt32(xmlDoc.GetElementsByTagName("partner_id")[0].ChildNodes[0].Value);

            return(new Session(sessionId, apiKey, ApiSecret, location, mediaMode));
        }
Exemple #2
0
 protected override bool OnButtonReleaseEvent(Gdk.EventButton evnt)
 {
     if (this.Mode == MediaMode.Seek)
     {
         this.Mode = MediaMode.Pause;
     }
     return(base.OnButtonReleaseEvent(evnt));
 }
Exemple #3
0
 internal Session(string sessionId, int apiKey, string apiSecret, string location, MediaMode mediaMode)
 {
     this.Id = sessionId;
     this.ApiKey = apiKey;
     this.ApiSecret = apiSecret;
     this.Location = location;
     this.MediaMode = mediaMode;
 }
Exemple #4
0
 internal Session(string sessionId, int apiKey, string apiSecret, string location, MediaMode mediaMode)
 {
     this.Id        = sessionId;
     this.ApiKey    = apiKey;
     this.ApiSecret = apiSecret;
     this.Location  = location;
     this.MediaMode = mediaMode;
 }
 public SessionProperties(MediaMode mediaMode, RecordingMode recordingMode, OutputMode outputMode,
                          RecordingLayout layout, string defaultCustomLayout, string customSessionId)
 {
     this._mediaMode              = mediaMode;
     this._recordingMode          = recordingMode;
     this._defaultOutputMode      = outputMode;
     this._defaultRecordingLayout = layout;
     this._defaultCustomLayout    = defaultCustomLayout;
     this._customSessionId        = customSessionId;
 }
Exemple #6
0
 private bool updateCurrent()
 {
     if (this.mode != MediaMode.Play)
     {
         return(false);
     }
     else
     {
         this.current += 0.001d * UpdateInterval * this.speed;
         if (this.current >= this.max - Epsilon)
         {
             this.current = this.max - Epsilon;
             this.Mode    = MediaMode.Pause;
         }
         this.QueueDraw();
         this.handleCurrentChanged();
         return(true);
     }
 }
Exemple #7
0
        protected override bool OnButtonPressEvent(Gdk.EventButton ev)
        {
            double x = ev.X;
            int    w, h;

            this.GdkWindow.GetSize(out w, out h);
            double wb  = w - Offset - xb - 4.0d;
            double xbt = xb + wb * (current - min) / (max - min) - 4.0d;

            if (x >= Offset && x <= Offset + 32 && (int)this.Mode <= 0x01)
            {
                this.Mode = (MediaMode)(0x01 - this.Mode);
            }
            else if (x >= xbt && x <= xbt + 8.0d)
            {
                this.Mode = MediaMode.Seek;
            }
            return(base.OnButtonPressEvent(ev));
        }
Exemple #8
0
        /**
         * Creates a new OpenTok session.
         * <p>
         * OpenTok sessions do not expire. However, authentication tokens do expire (see the
         * generateToken() method). Also note that sessions cannot explicitly be destroyed.
         * <p>
         * A session ID string can be up to 255 characters long.
         * <p>
         * Calling this method results in an OpenTokException in the event of an error.
         * Check the error message for details.
         *
         * You can also create a session using the
         * <a href="http://www.tokbox.com/opentok/api/#session_id_production">OpenTok
         * REST API</a> or the <a href="https://dashboard.tokbox.com/projects">OpenTok
         * dashboard</a>.
         *
         * @param location (String) An IP address that the OpenTok servers will use to
         * situate the session in its global network. If you do not set a location hint,
         * the OpenTok servers will be based on the first client connecting to the session.
         *
         * @param mediaMode Whether the session will transmit streams using the
         * OpenTok Media Router (<code>MediaMode.ROUTED</code>) or not
         * (<code>MediaMode.RELAYED</code>). By default, the setting is
         * <code>MediaMode.RELAYED</code>.
         * <p>
         * With the <code>mediaMode</code> parameter set to <code>MediaMode.RELAYED</code>, the
         * session will attempt to transmit streams directly between clients. If clients cannot
         * connect due to firewall restrictions, the session uses the OpenTok TURN server to relay
         * streams.
         * <p>
         * The <a href="https://tokbox.com/opentok/tutorials/create-session/#media-mode"
         * target="_top">OpenTok Media Router</a> provides the following benefits:
         *
         * <ul>
         *   <li>The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
         *       (When the <code>mediaMode</code> parameter is set to
         *       <code>MediaMode.ROUTED</code>, each client must send a separate audio-video stream
         *      to each client subscribing to it.)</li>
         *   <li>The OpenTok Media Router can improve the quality of the user experience through
         *     <a href="https://tokbox.com/platform/fallback" target="_top">audio fallback and video
         *     recovery</a>. With these features, if a client's connectivity degrades to a degree
         *     that it does not support video for a stream it's subscribing to, the video is dropped
         *     on that client (without affecting other clients), and the client receives audio only.
         *     If the client's connectivity improves, the video returns.</li>
         *   <li>The OpenTok Media Router supports the
         *     <a href="http://tokbox.com/opentok/tutorials/archiving" target="_top">archiving</a>
         *     feature, which lets you record, save, and retrieve OpenTok sessions.</li>
         * </ul>
         *
         * @param archiveMode Whether the session is automatically archived
         * (<code>ArchiveMode.ALWAYS</code>) or not (<code>ArchiveMode.MANUAL</code>). By default,
         * the setting is <code>ArchiveMode.MANUAL</code>, and you must call the
         * StartArchive() method of the OpenTok object to start archiving. To archive the session
         * (either automatically or not), you must set the mediaMode parameter to
         * <code>MediaMode.ROUTED</code>.
         *
         * @return A Session object representing the new session. The <code>Id</code> property of
         * the Session is the session ID, which uniquely identifies the session. You will use
         * this session ID in the client SDKs to identify the session. For example, when using the
         * OpenTok.js library, use the session ID when calling the
         * <a href="http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession">
         * OT.initSession()</a> method (to initialize an OpenTok session).
         */
        public async Task <Session> CreateSession(string location = "", MediaMode mediaMode = MediaMode.RELAYED, ArchiveMode archiveMode = ArchiveMode.MANUAL)
        {
            if (!OpenTokUtils.TestIpAddress(location))
            {
                throw new OpenTokArgumentException(string.Format("Location {0} is not a valid IP address", location));
            }

            if (archiveMode == ArchiveMode.ALWAYS && mediaMode != MediaMode.ROUTED)
            {
                throw new OpenTokArgumentException("A session with always archive mode must also have the routed media mode.");
            }

            string preference = (mediaMode == MediaMode.RELAYED) ? "enabled" : "disabled";

            var headers = new Dictionary <string, string> {
                { "Content-type", "application/x-www-form-urlencoded" }
            };
            var data = new Dictionary <string, object>
            {
                { "location", location },
                { "p2p.preference", preference },
                { "archiveMode", archiveMode.ToString().ToLower() }
            };

            var response = await Client.Post("session/create", headers, data);

            var xmlDoc = XDocument.Parse(response);

            if (!xmlDoc.Descendants("session_id").Any())
            {
                throw new OpenTokWebException("Session could not be provided. Are ApiKey and ApiSecret correctly set?");
            }

            var sessionId = xmlDoc.Descendants("session_id").First().Value;
            var apiKey    = Convert.ToInt32(xmlDoc.Descendants("partner_id").First().Value);

            return(new Session(sessionId, apiKey, ApiSecret, location, mediaMode, archiveMode));
        }
        /**
         * Creates a new OpenTok session.
         * <p>
         * OpenTok sessions do not expire. However, authentication tokens do expire (see the
         * generateToken() method). Also note that sessions cannot explicitly be destroyed.
         * <p>
         * A session ID string can be up to 255 characters long.
         * <p>
         * Calling this method results in an OpenTokException in the event of an error.
         * Check the error message for details.
         *
         * You can also create a session using the
         * <a href="http://www.tokbox.com/opentok/api/#session_id_production">OpenTok
         * REST API</a> or the <a href="https://dashboard.tokbox.com/projects">OpenTok
         * dashboard</a>.
         *
         * @param location (String) An IP address that the OpenTok servers will use to
         * situate the session in its global network. If you do not set a location hint,
         * the OpenTok servers will be based on the first client connecting to the session.
         *
         * @param mediaMode Whether the session will transmit streams using the
         * OpenTok Media Router (<code>MediaMode.ROUTED</code>) or not
         * (<code>MediaMode.RELAYED</code>). By default, the setting is
         * <code>MediaMode.RELAYED</code>.
         * <p>
         * With the <code>mediaMode</code> parameter set to <code>MediaMode.RELAYED</code>, the
         * session will attempt to transmit streams directly between clients. If clients cannot
         * connect due to firewall restrictions, the session uses the OpenTok TURN server to relay
         * streams.
         * <p>
         * The <a href="https://tokbox.com/opentok/tutorials/create-session/#media-mode"
         * target="_top">OpenTok Media Router</a> provides the following benefits:
         *
         * <ul>
         *   <li>The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
         *       (When the <code>mediaMode</code> parameter is set to
         *       <code>MediaMode.ROUTED</code>, each client must send a separate audio-video stream
         *      to each client subscribing to it.)</li>
         *   <li>The OpenTok Media Router can improve the quality of the user experience through
         *     <a href="https://tokbox.com/platform/fallback" target="_top">audio fallback and video
         *     recovery</a>. With these features, if a client's connectivity degrades to a degree
         *     that it does not support video for a stream it's subscribing to, the video is dropped
         *     on that client (without affecting other clients), and the client receives audio only.
         *     If the client's connectivity improves, the video returns.</li>
         *   <li>The OpenTok Media Router supports the
         *     <a href="http://tokbox.com/opentok/tutorials/archiving" target="_top">archiving</a>
         *     feature, which lets you record, save, and retrieve OpenTok sessions.</li>
         * </ul>
         *
         * @param archiveMode Whether the session is automatically archived
         * (<code>ArchiveMode.ALWAYS</code>) or not (<code>ArchiveMode.MANUAL</code>). By default,
         * the setting is <code>ArchiveMode.MANUAL</code>, and you must call the
         * StartArchive() method of the OpenTok object to start archiving. To archive the session
         * (either automatically or not), you must set the mediaMode parameter to
         * <code>MediaMode.ROUTED</code>.
         *
         * @return A Session object representing the new session. The <code>Id</code> property of
         * the Session is the session ID, which uniquely identifies the session. You will use
         * this session ID in the client SDKs to identify the session. For example, when using the
         * OpenTok.js library, use the session ID when calling the
         * <a href="http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession">
         * OT.initSession()</a> method (to initialize an OpenTok session).
         */
        public Session CreateSession(string location = "", MediaMode mediaMode = MediaMode.RELAYED, ArchiveMode archiveMode = ArchiveMode.MANUAL)
        {

            if (!OpenTokUtils.TestIpAddress(location))
            {
                throw new OpenTokArgumentException(string.Format("Location {0} is not a valid IP address", location));
            }

            if (archiveMode == ArchiveMode.ALWAYS && mediaMode != MediaMode.ROUTED)
            {
                throw new OpenTokArgumentException("A session with always archive mode must also have the routed media mode.");
            }

            string preference = (mediaMode == MediaMode.RELAYED) ? "enabled" : "disabled";

            var headers = new Dictionary<string, string> { { "Content-type", "application/x-www-form-urlencoded" } };
            var data = new Dictionary<string, object>
            {
                {"location", location},
                {"p2p.preference", preference},
                {"archiveMode", archiveMode.ToString().ToLower()}
            };

            var response = Client.Post("session/create", headers, data);
            var xmlDoc = Client.ReadXmlResponse(response);

            if (xmlDoc.GetElementsByTagName("session_id").Count == 0)
            {
                throw new OpenTokWebException("Session could not be provided. Are ApiKey and ApiSecret correctly set?");
            }
            var sessionId = xmlDoc.GetElementsByTagName("session_id")[0].ChildNodes[0].Value;
            var apiKey = Convert.ToInt32(xmlDoc.GetElementsByTagName("partner_id")[0].ChildNodes[0].Value);
            return new Session(sessionId, apiKey, ApiSecret, location, mediaMode, archiveMode);
        }
Exemple #10
0
        public static async Task <string> CreateSessionAsync(string secret, string apiKey, MediaMode mediaMode = MediaMode.ROUTED)
        {
            var token = GetTokboxToken(secret, apiKey);
            // can't add to default headers since client is static
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://api.opentok.com/session/create");

            httpRequestMessage.Headers.Add("X-OPENTOK-AUTH", token);
            string location       = "";                         // do not use unless first connecting client isn't representative for other participants
            string p2ppreference  = MediaModes[(int)mediaMode]; // default disabled - the session uses the OpenTok Media Router. enabled - relayed
            string archiveMode    = "manual";                   // default manual, if always you must also set the p2p.preference parameter to disabled
            var    requestContent = string.Format("location={0}&p2p.preference={1}&archiveMode={2}",
                                                  Uri.EscapeDataString(location),
                                                  Uri.EscapeDataString(p2ppreference),
                                                  Uri.EscapeDataString(archiveMode));

            httpRequestMessage.Content = new StringContent(requestContent, Encoding.UTF8, "application/x-www-form-urlencoded");
            var response = await client.SendAsync(httpRequestMessage);

            using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync()))
            {
                String result = await reader.ReadToEndAsync();

                dynamic jsonResult = JsonConvert.DeserializeObject(result);
                return(jsonResult[0]?.session_id);
            }
        }
Exemple #11
0
 public bool GetMediaModeState(MediaMode mediaMode)
 {
     return(_mediaPlayer.settings.getMode(mediaMode.ToString()));
 }
Exemple #12
0
 /// <summary>
 /// Enables or disables specific modes pertaining to media (mostly playback). (Enum bit flagging not implemented)
 /// AutoRewind: Mode indicating whether the tracks are rewound to the beginning after playing to the end. Default state is true.
 /// Loop: Mode indicating whether the sequence of tracks repeats itself. Default state is false.
 /// ShowFrame: Mode indicating whether the nearest video key frame is displayed at the current position
 /// when not playing. Default state is false. Has no effect on audio tracks.
 /// Shuffle: Mode indicating whether the tracks are played in random order. Default state is false.
 /// </summary>
 public void SetMediaMode(MediaMode mediaMode, bool setState)
 {
     _mediaPlayer.settings.setMode(mediaMode.ToString(), setState);
 }
 /**
  * Call this method to set how the media streams will be sent and received by
  * your clients: routed through OpenVidu Media Node
  * (<code>MediaMode.ROUTED</code>) or attempting direct p2p connections
  * (<code>MediaMode.RELAYED</code>, <i>not available yet</i>)
  *
  * Default value is <code>MediaMode.ROUTED</code>
  */
 public SessionPropertiesBuilder mediaMode(MediaMode mediaMode)
 {
     this._mediaMode = mediaMode;
     return(this);
 }