예제 #1
0
        /// <summary>
        /// Loads the ORTC factory
        /// </summary>
        /// <returns></returns>
        private bool ORTCLoadFactory()
        {
            try
            {
                // Load factory
                var          api     = new Ibt.Ortc.Api.Ortc("Plugins");
                IOrtcFactory factory = api.LoadOrtcFactory("IbtRealTimeSJ");

                if (factory != null)
                {
                    // Construct object
                    ortcClient = factory.CreateClient();

                    if (ortcClient != null)
                    {
                        ortcClient.Id = "RTCH";

                        // Handlers
                        ortcClient.OnConnected    += new OnConnectedDelegate(ortc_OnConnected);
                        ortcClient.OnDisconnected += new OnDisconnectedDelegate(ortc_OnDisconnected);
                        ortcClient.OnException    += (sender, error) => {
                            Log(error.ToString());
                        };
                        return(true);
                    }
                }
                else
                {
                    Log("Factory is null");
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }

            if (ortcClient == null)
            {
                Log("ORTC object is null");
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Saves the authentication token channels permissions in the ORTC server.
        /// </summary>
        /// <param name="url">ORTC server URL.</param>
        /// <param name="isCluster">Indicates whether the ORTC server is in a cluster.</param>
        /// <param name="authenticationToken">Authentication Token which is generated by the application server, for instance a unique session ID.</param>
        /// <param name="authenticationTokenIsPrivate">Indicates whether the authentication token is private (1) or not (0).</param>
        /// <param name="applicationKey">Application Key that was provided to you together with the ORTC service purchasing.</param>
        /// <param name="timeToLive">The authentication token time to live, in other words, the allowed activity time (in seconds).</param>
        /// <param name="privateKey">The private key provided to you together with the ORTC service purchasing.</param>
        /// <param name="permissions">The channels and their permissions (w: write/read or r: read, case sensitive).</param>
        /// <returns>True if the authentication was successful or false if it was not.</returns>
        /// <exception cref="OrtcEmptyFieldException">Server URL can not be null or empty.</exception>
        /// <exception cref="OrtcAuthenticationNotAuthorizedException">Unauthorized by the server.</exception>
        /// <exception cref="OrtcNotConnectedException">Unable to connect to the authentication server.</exception>
        /// <example>
        /// <code>
        ///    // Permissions
        ///    Dictionary&lt;string, ChannelPermissions&gt; permissions = new Dictionary&lt;string, ChannelPermissions&gt;();
        ///
        ///    permissions.Add("channel1", ChannelPermissions.Read);
        ///    permissions.Add("channel2", ChannelPermissions.Write);
        ///
        ///    string url = "http://ortc-developers.realtime.co/server/2.1";
        ///    bool isCluster = true;
        ///    string authenticationToken = "myAuthenticationToken";
        ///    bool authenticationTokenIsPrivate = true;
        ///    string applicationKey = "myApplicationKey";
        ///    int timeToLive = 1800; // 30 minutes
        ///    string privateKey = "myPrivateKey";
        ///
        ///    bool authSaved = Ibt.Ortc.Api.Ortc.SaveAuthentication(url, isCluster, authenticationToken, authenticationTokenIsPrivate, applicationKey, timeToLive, privateKey, permissions))
        /// </code>
        /// </example>
        public static bool SaveAuthentication(string url, bool isCluster, string authenticationToken, bool authenticationTokenIsPrivate,
                                              string applicationKey, int timeToLive, string privateKey, Dictionary <string, ChannelPermissions> permissions)
        {
            var result = false;

            if (permissions != null && permissions.Count > 0)
            {
                var multiPermissions = new Dictionary <string, List <ChannelPermissions> >();

                foreach (var permission in permissions)
                {
                    var permissionList = new List <ChannelPermissions>();
                    permissionList.Add(permission.Value);

                    multiPermissions.Add(permission.Key, permissionList);
                }

                result = Ortc.SaveAuthentication(url, isCluster, authenticationToken, authenticationTokenIsPrivate, applicationKey, timeToLive, privateKey, multiPermissions);
            }

            return(result);
        }