Beispiel #1
0
        /**
         * _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)
        {
            clsPubnubCrypto pc = new clsPubnubCrypto(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);
            }
        }
Beispiel #2
0
        /**
         * _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;
            clsPubnubCrypto pc        = new clsPubnubCrypto(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);
            }
        }
Beispiel #3
0
        /**
         * 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 i.e list of history messages
         */
        public void Publish(Dictionary <string, object> args)
        {
            string           channel      = args["channel"].ToString();
            object           message      = args["message"];
            ResponseCallback respCallback = (ResponseCallback)args["callback"];

            clsPubnubCrypto pc = new clsPubnubCrypto(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);
        }
Beispiel #4
0
        /**
          * _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;
            clsPubnubCrypto pc = new clsPubnubCrypto(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);
            }
        }
Beispiel #5
0
        /**
         * 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 i.e list of history messages
         */
        public void Publish(Dictionary<string, object> args)
        {
            string channel = args["channel"].ToString();
            object message = args["message"];
            ResponseCallback respCallback = (ResponseCallback)args["callback"];

            clsPubnubCrypto pc = new clsPubnubCrypto(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);
        }