Example #1
0
        public PubNubUnityBase(PNConfiguration pnConfiguration, GameObject gameObjectRef, IJsonLibrary jsonLibrary)
        {
            PNConfig = pnConfiguration;
            PNLog    = new PNLoggingMethod(PNConfig.LogVerbosity);
            #if (UNITY_IOS)
            Version = string.Format("PubNub-CSharp-UnityIOS/{0}", build);
            #elif (UNITY_STANDALONE_WIN)
            Version = string.Format("PubNub-CSharp-UnityWin/{0}", build);
            #elif (UNITY_STANDALONE_OSX)
            Version = string.Format("PubNub-CSharp-UnityOSX/{0}", build);
            #elif (UNITY_ANDROID)
            Version = string.Format("PubNub-CSharp-UnityAndroid/{0}", build);
            #elif (UNITY_STANDALONE_LINUX)
            Version = string.Format("PubNub-CSharp-UnityLinux/{0}", build);
            #elif (UNITY_WEBPLAYER)
            Version = string.Format("PubNub-CSharp-UnityWeb/{0}", build);
            #elif (UNITY_WEBGL)
            Version = string.Format("PubNub-CSharp-UnityWebGL/{0}", build);
            #else
            Version = string.Format("PubNub-CSharp-Unity/{0}", build);
            #endif
            #if (ENABLE_PUBNUB_LOGGING)
            this.PNLog.WriteToLog(Version, PNLoggingMethod.LevelInfo);
            #endif

            if (gameObjectRef == null)
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PNLog.WriteToLog("Initilizing new GameObject", PNLoggingMethod.LevelInfo);
                #endif
                GameObjectRef = new GameObject("PubnubGameObject");
                localGobj     = true;
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PNLog.WriteToLog("Reusing already initialized GameObject", PNLoggingMethod.LevelInfo);
                #endif
                GameObjectRef = gameObjectRef;
                localGobj     = false;
            }
            publishMessageCounter = new Counter();

            QManager = GameObjectRef.AddComponent <QueueManager> ();
            latency  = GameObjectRef.AddComponent <PNLatencyManager> ();
            QManager.NoOfConcurrentRequests = PNConfig.ConcurrentNonSubscribeWorkers;
        }
Example #2
0
        private static StringBuilder AppendLatencyToURL(StringBuilder url, PNOperationType operationType, PNLatencyManager latency)
        {
            //TODO Add delete history
            switch (operationType)
            {
            case PNOperationType.PNTimeOperation:
                if (latency.Time > 0)
                {
                    url.AppendFormat("&l_time={0}", latency.Time);
                }
                break;

            case PNOperationType.PNPublishOperation:
                if (latency.Publish > 0)
                {
                    url.AppendFormat("&l_pub={0}", latency.Publish);
                }
                break;

            case PNOperationType.PNWhereNowOperation:
            case PNOperationType.PNHereNowOperation:
            case PNOperationType.PNLeaveOperation:
            case PNOperationType.PNSetStateOperation:
            case PNOperationType.PNGetStateOperation:
                if (latency.Presence > 0)
                {
                    url.AppendFormat("&l_pres={0}", latency.Presence);
                }
                break;

            case PNOperationType.PNRemoveAllPushNotificationsOperation:
            case PNOperationType.PNAddPushNotificationsOnChannelsOperation:
            case PNOperationType.PNPushNotificationEnabledChannelsOperation:
            case PNOperationType.PNRemovePushNotificationsFromChannelsOperation:
                if (latency.MobilePush > 0)
                {
                    url.AppendFormat("&l_push={0}", latency.MobilePush);
                }
                break;

            case PNOperationType.PNFetchMessagesOperation:
            case PNOperationType.PNHistoryOperation:
                if (latency.History > 0)
                {
                    url.AppendFormat("&l_hist={0}", latency.History);
                }
                break;

            case PNOperationType.PNAddChannelsToGroupOperation:
            case PNOperationType.PNChannelGroupsOperation:
            case PNOperationType.PNChannelsForGroupOperation:
            case PNOperationType.PNRemoveChannelsFromGroupOperation:
            case PNOperationType.PNRemoveGroupOperation:
                if (latency.ChannelGroups > 0)
                {
                    url.AppendFormat("&l_cg={0}", latency.ChannelGroups);
                }
                break;

            default:
                break;
            }
            return(url);
        }