Exemplo n.º 1
0
        /// <summary>
        /// Disables presence for the specified channel.
        /// </summary>
        /// <param name="url">Server containing the presence service.</param>
        /// <param name="isCluster">Specifies if url is cluster.</param>
        /// <param name="applicationKey">Application key with access to presence service.</param>
        /// <param name="privateKey">The private key provided when the ORTC service is purchased.</param>
        /// <param name="channel">Channel to disable presence.</param>
        /// <param name="callback">Callback with error <see cref="OrtcPresenceException"/> and result.</param>
        public static void DisablePresence(String url, bool isCluster, String applicationKey, String privateKey, String channel, OnDisablePresenceDelegate callback)
        {
            Balancer.GetServerUrl(url, isCluster, applicationKey, (error, server) =>
            {
                if (error == null)
                {
                    var presenceUrl = String.IsNullOrEmpty(server) ? server : server[server.Length - 1] == '/' ? server : server + "/";
                    presenceUrl     = String.Format("{0}presence/disable/{1}/{2}", presenceUrl, applicationKey, channel);

                    var content = String.Format("privatekey={0}", privateKey);

                    RestWebservice.PostAsync(presenceUrl, content, (responseError, result) =>
                    {
                        if (responseError != null)
                        {
                            callback(responseError, null);
                        }
                        else
                        {
                            callback(null, result);
                        }
                    });
                }
                else
                {
                    callback(new OrtcPresenceException(error.Message), null);
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enables presence for the specified channel with first 100 unique metadata if metadata is set to true.
        /// </summary>
        /// <param name="url">Server containing the presence service.</param>
        /// <param name="isCluster">Specifies if url is cluster.</param>
        /// <param name="applicationKey">Application key with access to presence service.</param>
        /// <param name="privateKey">The private key provided when the ORTC service is purchased.</param>
        /// <param name="channel">Channel to activate presence.</param>
        /// <param name="metadata">Defines if to collect first 100 unique metadata.</param>
        /// <param name="callback">Callback with error <see cref="OrtcPresenceException"/> and result.</param>
        /// <example>
        /// <code>
        /// client.EnablePresence("http://ortc-developers.realtime.co/server/2.1", true, "myApplicationKey", "myPrivateKey", "presence-channel", false, (error, result) =>
        /// {
        ///     if (error != null)
        ///     {
        ///         Console.WriteLine(error.Message);
        ///     }
        ///     else
        ///     {
        ///         Console.WriteLine(result);
        ///     }
        /// });
        /// </code>
        /// </example>
        public static void EnablePresence(String url, bool isCluster, String applicationKey, String privateKey, String channel, bool metadata, OnEnablePresenceDelegate callback)
        {
            Balancer.GetServerUrl(url, isCluster, applicationKey, (error, server) =>
            {
                var presenceUrl = String.IsNullOrEmpty(server) ? server : server[server.Length - 1] == '/' ? server : server + "/";
                presenceUrl     = String.Format("{0}presence/enable/{1}/{2}", presenceUrl, applicationKey, channel);

                var content = String.Format("privatekey={0}", privateKey);

                if (metadata)
                {
                    content = String.Format("{0}&metadata=1", content);
                }

                RestWebservice.PostAsync(presenceUrl, content, (responseError, result) =>
                {
                    if (responseError != null)
                    {
                        callback(responseError, null);
                    }
                    else
                    {
                        callback(null, result);
                    }
                });
            });
        }