public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
            {
                if (message != null)
                {
                    Console.WriteLine("SubscribeCallback: PNMessageResult: {0}", pubnub.JsonPluggableLibrary.SerializeToJsonString(message.Message));
                    switch (currentTestCase)
                    {
                    case "ThenSubscribeShouldReturnReceivedMessage":
                        if (publishedMessage.ToString() == message.Message.ToString())
                        {
                            receivedMessage = true;
                        }
                        subscribeManualEvent.Set();
                        break;

                    //case "ThenSubscriberShouldBeAbleToReceiveManyMessages":
                    //    numberOfReceivedMessages++;
                    //    if (numberOfReceivedMessages >= 10)
                    //    {
                    //        receivedMessage = true;
                    //        subscribeManualEvent.Set();
                    //    }
                    //    break;
                    default:
                        break;
                    }
                }
            }
예제 #2
0
 public override void Message <T> (Pubnub pubnub, PNMessageResult <T> messageResult)
 {
     if (messageResult != null)
     {
         this.callback(pubnub.JsonPluggableLibrary.SerializeToJsonString(messageResult));
     }
 }
예제 #3
0
 public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
 {
     if (message != null)
     {
         Debug.WriteLine("SubscribeCallback: PNMessageResult: {0}", pubnub.JsonPluggableLibrary.SerializeToJsonString(message.Message));
     }
 }
예제 #4
0
        private void HandleMessageCallback(Pubnub pubnubObj, PNMessageResult <object> message)
        {
            // Handle new message stored in message.Message
            if (message != null)
            {
                if (message.Channel != null)
                {
                    // Message has been received on channel group stored in message.Channel
                    //Console.WriteLine("[{0}] message.Channel: {1} {2} {3}", message.Channel, message.Message, message.Subscription, message.Timetoken);
                    var args = new PubnubMessageReceivedEventArgs(message.Channel, message.Message, message.Subscription, message.Timetoken);
                    PubnubMessageReceived?.Invoke(args);
                }
                else
                {
                    // Message has been received on channel stored in message.Subscription
                    //Console.WriteLine("[{0}] message.Subscription: {1} {2} {3}", message.Subscription, message.Message, message.Subscription, message.Timetoken);
                    var args = new PubnubMessageReceivedEventArgs(message.Subscription, message.Message, message.Subscription, message.Timetoken);
                    PubnubMessageReceived?.Invoke(args);
                }

                /*
                 *      log the following items with your favorite logger
                 *          - message.Message()
                 *          - message.Subscription()
                 *          - message.Timetoken()
                 */
            }
        }
        public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
        {
            if (message.Channel == sourceChannel)
            {
                string jsonString = message.Message.ToString();

                // This is super safe. If we got an object which doesn't match,
                // we'll spit out a neutral object, rather than doing anything
                // exceptional.
                MsgType payload = pubnub.JsonPluggableLibrary.DeserializeToObject <MsgType>(jsonString);

                callback.Invoke(payload);
            }
        }
예제 #6
0
            public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
            {
                if (message != null)
                {
                    Console.WriteLine("SubscribeCallback: PNMessageResult: {0}", pubnub.JsonPluggableLibrary.SerializeToJsonString(message.Message));
                    switch (currentTestCase)
                    {
                    case "ThenSubscribeShouldReturnUnicodeMessage":
                    case "ThenSubscribeShouldReturnUnicodeMessageSSL":
                    case "ThenSubscribeShouldReturnForwardSlashMessage":
                    case "ThenSubscribeShouldReturnForwardSlashMessageSSL":
                    case "ThenSubscribeShouldReturnForwardSlashMessageCipher":
                    case "ThenSubscribeShouldReturnForwardSlashMessageCipherSSL":
                    case "ThenSubscribeShouldReturnForwardSlashMessageSecret":
                    case "ThenSubscribeShouldReturnForwardSlashMessageSecretSSL":
                    case "ThenSubscribeShouldReturnForwardSlashMessageCipherSecret":
                    case "ThenSubscribeShouldReturnForwardSlashMessageCipherSecretSSL":
                        if (publishedMessage.ToString() == message.Message.ToString())
                        {
                            receivedMessage = true;
                        }
                        subscribeManualEvent.Set();
                        break;

                    case "ThenSubscribeShouldReturnSpecialCharMessage":
                    case "ThenSubscribeShouldReturnSpecialCharMessageSSL":
                    case "ThenSubscribeShouldReturnSpecialCharMessageCipher":
                    case "ThenSubscribeShouldReturnSpecialCharMessageCipherSSL":
                    case "ThenSubscribeShouldReturnSpecialCharMessageSecret":
                    case "ThenSubscribeShouldReturnSpecialCharMessageSecretSSL":
                    case "ThenSubscribeShouldReturnSpecialCharMessageCipherSecret":
                    case "ThenSubscribeShouldReturnSpecialCharMessageCipherSecretSSL":
                    //    if (publishedMessage.ToString() == message.Message.ToString())
                    //    {
                    //        receivedMessage = true;
                    //    }
                    //    subscribeManualEvent.Set();
                    //    break;
                    default:
                        break;
                    }
                }
            }
예제 #7
0
            public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
            {
                if (message != null)
                {
                    Debug.WriteLine("SubscribeCallback: PNMessageResult: {0}", pubnub.JsonPluggableLibrary.SerializeToJsonString(message.Message));
                    switch (currentTestCase)
                    {
                    case "ThenSubscribeShouldReturnReceivedMessage":
                    case "ThenSubscribeShouldReturnReceivedMessageSSL":
                    case "ThenSubscribeShouldReturnReceivedMessageCipherSSL":
                    case "ThenSubscribeShouldReturnReceivedMessageSecret":
                    case "ThenSubscribeShouldReturnReceivedMessageSecretSSL":
                    case "ThenSubscribeShouldReturnReceivedMessageSecretCipher":
                    case "ThenSubscribeShouldReturnReceivedMessageSecretCipherSSL":
                    case "ThenSubscribeShouldReturnReceivedMessageCipher":
                        if (publishedMessage.ToString() == message.Message.ToString())
                        {
                            receivedMessage = true;
                        }
                        break;

                    case "ThenSubscribeShouldReturnEmojiMessage":
                    case "ThenSubscribeShouldReturnEmojiMessageSSL":
                    case "ThenSubscribeShouldReturnEmojiMessageSecret":
                    case "ThenSubscribeShouldReturnEmojiMessageCipherSecret":
                    case "ThenSubscribeShouldReturnEmojiMessageCipherSecretSSL":
                    case "ThenSubscribeShouldReturnEmojiMessageSecretSSL":
                        if (publishedMessage.ToString() == message.Message.ToString())
                        {
                            receivedMessage = true;
                        }
                        break;

                    default:
                        break;
                    }
                }
                subscribeManualEvent.Set();
            }
        public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
        {
            string jsonString = message.Message.ToString();

            if (message.Channel == Messenger.MessageType.NewOrders.ToString())
            {
                Cart c = pubnub.JsonPluggableLibrary.DeserializeToObject <Cart>(jsonString);

                Console.Out.WriteLine("Received cart: " + c);
                SQL_Interface.Instance.AddNewOrder(c.Email, c.ShoppingCart);
            }
            else if (message.Channel == Messenger.MessageType.ProductChanges.ToString())
            {
                Product p = pubnub.JsonPluggableLibrary.DeserializeToObject <Product>(jsonString);

                Console.Out.WriteLine("Received product: " + p);
                SQL_Interface.Instance.SetProductInfo(p);
            }
            else
            {
                Console.Out.WriteLine("Dropping odd Pubnub message: " + jsonString);
            }
        }
예제 #9
0
 }
            Initialized = true;
            InitializedChanged?.Invoke(Initialized);
        }

        public void Uninitialize()
        {
            //  this can be called before Initialize
            if (_Pubnub == null) return;
            try
            {
                System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.Uninitialize - Uninitializing Chat for user {_UserId}");
                _Pubnub.RemoveListener(_ListenerSubscribeCallack);
                _Pubnub.Unsubscribe<string>().Channels(new string[] { _UserId }).Execute();
                //  TODO: consider removing push channel association here
                Initialized = false;
                InitializedChanged?.Invoke(Initialized);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"{ GetType().Name}.Uninitialize - Exception: { ex}");
            }
        }

        #endregion Init

        #region Callbacks

        private void OnMessageReceived(Pubnub pubnub, PNMessageResult<object> result)
        {
            try
            {
                MessageReceived?.Invoke(this, new MessageEventArgs(result.Message.ToString()));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.MessageReceived - Unable to deserialize message: { result.Message}\r\n\tException: { ex}");
            }
        }

        private void OnPresenceReceived(Pubnub pubnub, PNPresenceEventResult result)
        {
            System.Diagnostics.Debug.WriteLine($"*** { GetType().Name}.OnPresenceReceived\r\n -> Event: { result.Event}");
            {
                // handle incoming presence data 
                if (result.Event.Equals("join"))
                {
                    RaiseChannelJoined(result.Channel, result.Uuid);
                }
                else if (result.Event.Equals("leave"))
                {
                    RaiseChannelLeft(result.Channel, result.Uuid);
                }
                else if (result.Event.Equals("state-change"))
                {
                    //  listen for status events - eg: typing, etc
                    if ((result.State == null) || (result.State.Count == 0)) return;
                    foreach (var key in result.State.Keys)
                    {
                        var state = (ChatState)Enum.Parse(typeof(ChatState), result.State[key].ToString());
                        RaiseChannelState(result.Channel, result.Uuid, state);
                    }
                }
                else if (result.Event.Equals("timeout"))
                {
                }
                else if (result.Event.Equals("interval"))
                {
                    //  find the ids that have joined
                    if ((result.Join != null) && (result.Join.Length > 0))
                    {
                        foreach (var uuid in result.Join) RaiseChannelJoined(result.Channel, uuid);
                    }
                    if ((result.Leave != null) && (result.Leave.Length > 0))
                    {
                        foreach (var uuid in result.Leave) RaiseChannelJoined(result.Channel, uuid);
                    }
                }
                else if (result.HereNowRefresh)
                {
                    //  TODO: request state for channels
                    //GetState();
                }
            }
        }

        private void OnStatusReceived(Pubnub pubnub, PNStatus status)
        {
            {
                System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.OnStatusReceived\r\n -> Operation: { status.Operation}\r\n -> Category: { status.Category}\r\n -> Error: { status.Error}\r\n -> Data: { status.ErrorData}\r\n -> Status Code: { status.StatusCode}");

                if (status.Operation == PNOperationType.PNHeartbeatOperation)
                {
                    Connected = !status.Error;
                    ConnectedChanged?.Invoke(this, new EventArgs());
                }

                if ((status.Operation == PNOperationType.PNSubscribeOperation) && (status.Category == PNStatusCategory.PNUnknownCategory) && (status.StatusCode == 404))
                {
                    try
                    {
                        _FailCount++;
                        if (_FailCount > 3)
        public IEnumerator DoTestSubscribePSV2(string testName)
        {
            pubnub = new Pubnub(CommonIntergrationTests.PublishKey,
                                CommonIntergrationTests.SubscribeKey);

            System.Random r  = new System.Random();
            string        ch = "UnityIntegrationTest_CH." + r.Next(100);

            UnityEngine.Debug.Log(string.Format("{0} {1}: Start coroutine ", DateTime.Now.ToString(), testName));
            string uuid = "UnityIntegrationTest_UUID";

            pubnub.ChangeUUID(uuid);

            /*Subscribe CG
             * ⁃   Publish to CH
             * ⁃   Read Message on CG*/

            bool   bSubMessage2 = false;
            bool   bSubConnect  = false;
            string pubMessage   = "TestMessagePSV2";

            if (AsObject)
            {
                pubnub.Subscribe <object>(ch, "", (object returnMessage) => {
                    UnityEngine.Debug.Log(string.Format("{0}: {1} Subscribe {2}", DateTime.Now.ToString(), testName, returnMessage));
                    PNMessageResult pnMessageResult = returnMessage as PNMessageResult;

                    UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeObject: {0}", pnMessageResult.Payload));
                    UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeObject: {0}", pnMessageResult.Channel));
                    UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeObject: {0}", pnMessageResult.Subscription));
                    UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeObject: {0}", pnMessageResult.OriginatingTimetoken));
                    UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeObject: {0}", pnMessageResult.Timetoken));
                    //UnityEngine.Debug.Log (string.Format ("DisplayReturnMessageSubscribeObject: {0}", pnMessageResult.UserMetadata.ToString()));

                    if (pnMessageResult.Payload.ToString().Contains(pubMessage) && pnMessageResult.Channel.Contains(ch))
                    {
                        bSubMessage2 = true;
                    }
                }, (object retConnect) => {
                    UnityEngine.Debug.Log(string.Format("{0}: {1} Subscribe Connected {2}", DateTime.Now.ToString(), testName, retConnect));
                    bSubConnect = true;
                }, (object retM) => {
                    UnityEngine.Debug.Log(string.Format("{0}: {1} Subscribe  {2}", DateTime.Now.ToString(), testName, retM));
                }, this.DisplayErrorMessage);
            }
            else
            {
                pubnub.Subscribe <string>(ch, "", (string returnMessage) => {
                    UnityEngine.Debug.Log(string.Format("{0}: {1} Subscribe {2}", DateTime.Now.ToString(), testName, returnMessage));
                    object obj = pubnub.JsonPluggableLibrary.DeserializeToObject(returnMessage);
                    Dictionary <string, object> dict = obj as Dictionary <string, object>;
                    UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeString Object: result:{0}\nobj:{1}\nCount:{2}\n", returnMessage,
                                                        obj.ToString(), dict.Count));

                    bool pairmatch1 = false;
                    bool pairmatch2 = false;
                    foreach (var pair in dict)
                    {
                        UnityEngine.Debug.Log(string.Format("DisplayReturnMessageSubscribeString pair.Key: {0}, pair.Value:{1}",
                                                            pair.Key, pair.Value));
                        if (pair.Key.Equals("Payload") && (pair.Value.Equals(pubMessage)))
                        {
                            pairmatch1 = true;
                        }
                        if (pair.Key.Equals("Channel") && (pair.Value.Equals(ch)))
                        {
                            pairmatch2 = true;
                        }
                    }
                    if (pairmatch1 && pairmatch2)
                    {
                        bSubMessage2 = true;
                    }
                }, (string retConnect) => {
                    UnityEngine.Debug.Log(string.Format("{0}: {1} Subscribe Connected {2}", DateTime.Now.ToString(), testName, retConnect));
                    bSubConnect = true;
                }, (string retM) => {
                    UnityEngine.Debug.Log(string.Format("{0}: {1} Subscribe  {2}", DateTime.Now.ToString(), testName, retM));
                }, this.DisplayErrorMessage);
            }
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCallsLow));

            pubnub.Publish(ch, pubMessage, (string pub) => {
                UnityEngine.Debug.Log(string.Format("{0}: {1} Published CH {2}", DateTime.Now.ToString(), testName, pub));
            }, this.DisplayErrorMessage);

            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCallsLow));

            /*⁃   Unsub from CG*/

            bool bUnsub = true;

            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCallsLow));

            string strLog2 = string.Format("{0}: {1} After wait2   {2}",
                                           DateTime.Now.ToString(),
                                           testName,
                                           bSubMessage2
                                           );

            UnityEngine.Debug.Log(strLog2);

            if (
                bSubMessage2

                )
            {
                IntegrationTest.Pass();
            }
            pubnub.EndPendingRequests();
            pubnub.CleanUp();
        }
예제 #11
0
 public override void Message <T>(Pubnub pubnub, PNMessageResult <T> message)
 {
     Log.ReceiveLog($"{message.Publisher} on {message.Channel} : {message.Message}");
 }