示例#1
0
        SubscribeEnvelope ParseReceiedJSONV2(string jsonString)
        {
            if (!string.IsNullOrEmpty(jsonString))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ParseReceiedJSONV2: jsonString = {0}", jsonString), PNLoggingMethod.LevelInfo);
                #endif

                //this doesnt work on JSONFx for Unity in case a string is passed in an variable of type object
                //SubscribeEnvelope resultSubscribeEnvelope = jsonPluggableLibrary.Deserialize<SubscribeEnvelope>(jsonString);
                object            resultSubscribeEnvelope = PubNubInstance.JsonLibrary.DeserializeToObject(jsonString);
                SubscribeEnvelope subscribeEnvelope       = new SubscribeEnvelope();

                if (resultSubscribeEnvelope is Dictionary <string, object> )
                {
                    Dictionary <string, object> message = (Dictionary <string, object>)resultSubscribeEnvelope;
                    subscribeEnvelope.TimetokenMeta = Helpers.CreateTimetokenMetadata(message ["t"], "Subscribe TT: ", this.PubNubInstance.PNLog);
                    subscribeEnvelope.Messages      = Helpers.CreateListOfSubscribeMessage(message ["m"], this.PubNubInstance.PNLog);

                    return(subscribeEnvelope);
                }
                else
                {
                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("ParseReceiedJSONV2: resultSubscribeEnvelope is not dict"), PNLoggingMethod.LevelError);
                    #endif

                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
示例#2
0
 internal void ProcessResponse(ref SubscribeEnvelope resultSubscribeEnvelope, RequestState pnRequestState)
 {
     if (resultSubscribeEnvelope != null)
     {
         SendResponseToConnectCallback(pnRequestState);
         if (resultSubscribeEnvelope.Messages != null)
         {
             ResponseToUserCallbackForSubscribe(resultSubscribeEnvelope.Messages);
         }
         else
         {
             #if (ENABLE_PUBNUB_LOGGING)
             this.PubNubInstance.PNLog.WriteToLog(string.Format("ProcessResponseCallbacksV2: resultSubscribeEnvelope.Messages null"), PNLoggingMethod.LevelError);
             #endif
         }
     }
 }
示例#3
0
        private void  SubscribePresenceHanlder(CustomEventArgs cea)
        {
            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog("WebRequestCompleteHandler FireEvent", PNLoggingMethod.LevelInfo);
            #endif

            SubscribeEnvelope resultSubscribeEnvelope = null;
            string            jsonString = cea.Message;
            if (!jsonString.Equals("[]"))
            {
                resultSubscribeEnvelope = ParseReceiedJSONV2(jsonString);

                switch (cea.PubNubRequestState.OperationType)
                {
                case PNOperationType.PNSubscribeOperation:
                case PNOperationType.PNPresenceOperation:
                    ProcessResponse(ref resultSubscribeEnvelope, cea.PubNubRequestState);
                    if ((resultSubscribeEnvelope != null) && (resultSubscribeEnvelope.TimetokenMeta != null))
                    {
                        ParseReceiedTimetoken(reconnect, resultSubscribeEnvelope.TimetokenMeta.Timetoken);
                        this.region = resultSubscribeEnvelope.TimetokenMeta.Region;

                        RunSubscribeRequest(resultSubscribeEnvelope.TimetokenMeta.Timetoken, false);
                    }

                    else
                    {
                        #if (ENABLE_PUBNUB_LOGGING)
                        this.PubNubInstance.PNLog.WriteToLog(string.Format("ResponseCallbackNonErrorHandler ERROR: Couldn't extract timetoken, initiating fresh subscribe request. \nJSON response:\n {0}", jsonString), PNLoggingMethod.LevelError);
                        #endif
                        RunSubscribeRequest(0, false);
                    }
                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog("WebRequestCompleteHandler", PNLoggingMethod.LevelInfo);
                    #endif

                    break;

                default:
                    break;
                }
            }
        }