Exemplo n.º 1
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)
        ///     {
        ///         System.Diagnostics.Debug.Writeline(error.Message);
        ///     }
        ///     else
        ///     {
        ///         System.Diagnostics.Debug.Writeline(result);
        ///     }
        /// });
        /// </code>
        /// </example>
        internal 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.DoRest(presenceUrl, content, (responseError, result) =>
                {
                    if (responseError != null)
                    {
                        callback(responseError, null);
                    }
                    else
                    {
                        callback(null, result);
                    }
                });
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the subscriptions in the specified channel and if active the first 100 unique metadata.
        /// </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="authenticationToken">Authentication token with access to presence service.</param>
        /// <param name="channel">Channel with presence data active.</param>
        /// <param name="callback"><see cref="OnPresenceDelegate"/>Callback with error <see cref="OrtcPresenceException"/> and result <see cref="Presence"/>.</param>
        /// <example>
        /// <code>
        /// client.Presence("http://ortc-developers.realtime.co/server/2.1", true, "myApplicationKey", "myAuthenticationToken", "presence-channel", (error, result) =>
        /// {
        ///     if (error != null)
        ///     {
        ///         System.Diagnostics.Debug.Writeline(error.Message);
        ///     }
        ///     else
        ///     {
        ///         if (result != null)
        ///         {
        ///             System.Diagnostics.Debug.Writeline(result.Subscriptions);
        ///
        ///             if (result.Metadata != null)
        ///             {
        ///                 foreach (var metadata in result.Metadata)
        ///                 {
        ///                     System.Diagnostics.Debug.Writeline(metadata.Key + " - " + metadata.Value);
        ///                 }
        ///             }
        ///         }
        ///         else
        ///         {
        ///             System.Diagnostics.Debug.Writeline("There is no presence data");
        ///         }
        ///     }
        /// });
        /// </code>
        /// </example>
        internal static void GetPresence(String url, bool isCluster, String applicationKey, String authenticationToken, String channel, OnPresenceDelegate 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/{1}/{2}/{3}", presenceUrl, applicationKey, authenticationToken, channel);

                RestWebservice.DoRestGet(presenceUrl, (responseError, result) =>
                {
                    if (responseError != null)
                    {
                        callback(responseError, null);
                    }
                    else
                    {
                        Presence presenceData = new Presence();
                        if (!String.IsNullOrEmpty(result))
                        {
                            presenceData = Presence.Deserialize(result);
                        }
                        callback(null, presenceData);
                    }
                });
            });
        }