/// <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); } }); }
/// <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) /// { /// Console.WriteLine(error.Message); /// } /// else /// { /// if (result != null) /// { /// Console.WriteLine(result.Subscriptions); /// /// if (result.Metadata != null) /// { /// foreach (var metadata in result.Metadata) /// { /// Console.WriteLine(metadata.Key + " - " + metadata.Value); /// } /// } /// } /// else /// { /// Console.WriteLine("There is no presence data"); /// } /// } /// }); /// </code> /// </example> public static void GetPresence(String url, bool isCluster, String applicationKey, String authenticationToken, String channel, OnPresenceDelegate 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/{1}/{2}/{3}", presenceUrl, applicationKey, authenticationToken, channel); RestWebservice.GetAsync(presenceUrl, (responseError, result) => { if (responseError != null) { callback(responseError, null); } else { Presence presenceData = new Presence(); if (!String.IsNullOrEmpty(result)) { presenceData = Extensibility.Presence.Deserialize(result); } callback(null, presenceData); } }); } else { callback(new OrtcPresenceException(error.Message), null); } }); }
/// <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); } }); }); }
internal static void PostAsync(String url, String content, OnResponseDelegate callback) { RestWebservice.RequestAsync(url, "POST", content, callback); }
internal static void GetAsync(String url, OnResponseDelegate callback) { RestWebservice.RequestAsync(url, "GET", null, callback); }