/** * _subscribe - Private Interface * * @param Dictionary<string, object> args * args contains channel name and Procedure function callback and timetoken */ private void _subscribe(Dictionary<string, object> args) { is_disconnect = false; PubnubCrypto pc = new PubnubCrypto(this.CIPHER_KEY); string channel = args["channel"].ToString(); object timetoken = args["timestamp"]; // Begin Subscribe try { // Build URL List<string> url = new List<string>(); url.Add("subscribe"); url.Add(this.SUBSCRIBE_KEY); url.Add(channel); url.Add("0"); url.Add(timetoken.ToString()); _request(url, null, ResponseType.Subscribe); } catch { System.Threading.Thread.Sleep(1000); } }
/** * _subscribe - Private Interface * * @param Dictionary<string, object> args * args contains channel name and Procedure function callback and timetoken */ private void _subscribe(Dictionary<string, object> args) { PubnubCrypto pc = new PubnubCrypto(this.CIPHER_KEY); string channel = args["channel"].ToString(); ResponseCallback respCallback = (ResponseCallback)args["callback"]; object timetoken = args["timestamp"]; // Begin Recusive Subscribe try { // Build URL List<string> url = new List<string>(); url.Add("subscribe"); url.Add(this.SUBSCRIBE_KEY); url.Add(channel); url.Add("0"); url.Add(timetoken.ToString()); _request(url, respCallback, ResponseType.Subscribe); } catch { System.Threading.Thread.Sleep(1000); this._subscribe(args); } }
/** * Publish * * Send a message to a channel. * * @param Dictionary<string, object> args * args is string channel name and object message * and callback to the response back */ public void Publish(Dictionary<string, object> args) { string channel = args["channel"].ToString(); object message = args["message"]; ResponseCallback respCallback = (ResponseCallback)args["callback"]; PubnubCrypto pc = new PubnubCrypto(this.CIPHER_KEY); if (this.CIPHER_KEY.Length > 0) { if (message.GetType() == typeof(string)) { message = pc.encrypt(message.ToString()); message = "\"" + message.ToString() + "\""; } else if (message.GetType() == typeof(JArray)) { message = pc.encrypt((JArray)message); } else if (message.GetType() == typeof(JObject)) { message = pc.encrypt((JObject)message); } } else { message = JsonConvert.SerializeObject(message); } // Generate String to Sign string signature = "0"; if (this.SECRET_KEY.Length > 0) { StringBuilder string_to_sign = new StringBuilder(); string_to_sign .Append(this.PUBLISH_KEY) .Append('/') .Append(this.SUBSCRIBE_KEY) .Append('/') .Append(this.SECRET_KEY) .Append('/') .Append(channel) .Append('/') .Append(message); // Sign Message signature = getHMACSHA256(string_to_sign.ToString()); } // Build URL List<string> url = new List<string>(); url.Add("publish"); url.Add(this.PUBLISH_KEY); url.Add(this.SUBSCRIBE_KEY); url.Add(signature); url.Add(channel); url.Add("0"); url.Add(message.ToString()); _request(url, respCallback, ResponseType.Publish); }
/** * Publish * * Send a message to a channel. * * @param Dictionary<string, object> args * args is string channel name and object message * and callback to the response back */ public void Publish(Dictionary <string, object> args) { string channel = args["channel"].ToString(); object message = args["message"]; ResponseCallback respCallback = (ResponseCallback)args["callback"]; PubnubCrypto pc = new PubnubCrypto(this.CIPHER_KEY); if (this.CIPHER_KEY.Length > 0) { if (message.GetType() == typeof(string)) { message = pc.encrypt(message.ToString()); message = "\"" + message.ToString() + "\""; } else if (message.GetType() == typeof(JArray)) { message = pc.encrypt((JArray)message); } else if (message.GetType() == typeof(JObject)) { message = pc.encrypt((JObject)message); } } else { message = JsonConvert.SerializeObject(message); } // Generate String to Sign string signature = "0"; if (this.SECRET_KEY.Length > 0) { StringBuilder string_to_sign = new StringBuilder(); string_to_sign .Append(this.PUBLISH_KEY) .Append('/') .Append(this.SUBSCRIBE_KEY) .Append('/') .Append(this.SECRET_KEY) .Append('/') .Append(channel) .Append('/') .Append(message); // Sign Message signature = getHMACSHA256(string_to_sign.ToString()); } // Build URL List <string> url = new List <string>(); url.Add("publish"); url.Add(this.PUBLISH_KEY); url.Add(this.SUBSCRIBE_KEY); url.Add(signature); url.Add(channel); url.Add("0"); url.Add(message.ToString()); _request(url, respCallback, ResponseType.Publish); }