예제 #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;
        }
        public static string CreateV2Signature(string httpMethod, string path, string query, string publishKey, string cipherKey, string secretKey, string body)
        {
            StringBuilder stringToSign = new StringBuilder();

            stringToSign.Append(httpMethod)
            .Append("\n")
            .Append(publishKey)
            .Append("\n")
            .Append(path)
            .Append("\n")
            .Append(query)
            .Append("\n")
            .Append(body);

            PNLoggingMethod PNLog = new PNLoggingMethod(PNLogVerbosity.BODY);

            PubnubCrypto pubnubCrypto = new PubnubCrypto(cipherKey, PNLog);
            string       signature    = pubnubCrypto.PubnubAccessManagerSign(secretKey, stringToSign.ToString());

            signature = signature.TrimEnd('=');
            signature = string.Format("v2.{0}", signature);
            Debug.Log("signature ===== >" + signature);
            return(signature);
        }
예제 #3
0
 public PubnubCrypto(string cipher_key, PNLoggingMethod pnLog, bool useRandomInitializationVector)
     : base(cipher_key)
 {
     this.pnLog = pnLog;
     UseRandomInitializationVector = useRandomInitializationVector;
 }
예제 #4
0
 public PubnubCrypto(string cipher_key, PNLoggingMethod pnLog)
     : base(cipher_key)
 {
     this.pnLog = pnLog;
 }
예제 #5
0
        public static List <SubscribeMessage> CreateListOfSubscribeMessage(object message, PNLoggingMethod pnLog)
        {
            List <SubscribeMessage> subscribeMessages = new List <SubscribeMessage> ();

            if (message != null)
            {
                //JSONFx
                object[] messages = message as object[];

                if (messages != null)
                {
                    var myObjectArray = (from item in messages
                                         select item as object).ToArray();
                    if ((myObjectArray != null) && (myObjectArray.Length > 0))
                    {
                        foreach (object dictObject in myObjectArray)
                        {
                            TryAddToSubscribeMessageList(dictObject, ref subscribeMessages, pnLog);
                        }
                    }
                }
                else
                {
                    //MiniJSON
                    List <object> messageList = message as List <object>;
                    if ((messageList != null) && messageList.Count > 0)
                    {
                        foreach (object dictObject in messageList)
                        {
                            TryAddToSubscribeMessageList(dictObject, ref subscribeMessages, pnLog);
                        }
                    }
                }
            }
            #if (ENABLE_PUBNUB_LOGGING)
            else
            {
                pnLog.WriteToLog(string.Format("CreateListOfSubscribeMessage: no messages "), PNLoggingMethod.LevelInfo);
            }
            #endif

            return(subscribeMessages);
        }
예제 #6
0
        public static bool TryAddToSubscribeMessageList(object dictObject, ref List <SubscribeMessage> subscribeMessages, PNLoggingMethod pnLog)
        {
            var dict = dictObject as IDictionary;

            if ((dict != null) && (dict.Count > 1))
            {
                string shard             = (dict.Contains("a")) ? dict ["a"].ToString() : "";
                string subscriptionMatch = (dict.Contains("b")) ? dict ["b"].ToString() : "";
                string channel           = (dict.Contains("c")) ? dict ["c"].ToString() : "";
                object payload           = (dict.Contains("d")) ? (object)dict ["d"] : null;
                string flags             = (dict.Contains("f")) ? dict ["f"].ToString() : "";
                string issuingClientId   = (dict.Contains("i")) ? dict ["i"].ToString() : "";
                string subscribeKey      = (dict.Contains("k")) ? dict ["k"].ToString() : "";
                string log;
                long   sequenceNumber;
                Utility.TryCheckKeyAndParseLong(dict, "sequenceNumber", "s", out log, out sequenceNumber);

                TimetokenMetadata originatingTimetoken = (dict.Contains("o")) ? Helpers.CreateTimetokenMetadata(dict ["o"], "Originating TT: ", pnLog) : null;
                TimetokenMetadata publishMetadata      = (dict.Contains("p")) ? Helpers.CreateTimetokenMetadata(dict ["p"], "Publish TT: ", pnLog) : null;
                object            userMetadata         = (dict.Contains("u")) ? (object)dict ["u"] : null;

                int messageType;
                Utility.TryCheckKeyAndParseInt(dict, "messageType", "e", out log, out messageType);

                SubscribeMessage subscribeMessage = new SubscribeMessage(
                    shard,
                    subscriptionMatch,
                    channel,
                    payload,
                    flags,
                    issuingClientId,
                    subscribeKey,
                    sequenceNumber,
                    originatingTimetoken,
                    publishMetadata,
                    userMetadata,
                    messageType
                    );
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("AddToSubscribeMessageList: \n" +
                                               "shard : {0},\n" +
                                               "subscriptionMatch: {1},\n" +
                                               "channel: {2},\n" +
                                               "payload: {3},\n" +
                                               "flags: {4},\n" +
                                               "issuingClientId: {5},\n" +
                                               "subscribeKey: {6},\n" +
                                               "sequenceNumber: {7},\n" +
                                               "originatingTimetoken tt: {8},\n" +
                                               "originatingTimetoken region: {9},\n" +
                                               "publishMetadata tt: {10},\n" +
                                               "publishMetadata region: {11},\n" +
                                               "userMetadata {12} \n" +
                                               "log {13} \n",
                                               "messageType {14}\n",

                                               shard,
                                               subscriptionMatch,
                                               channel,
                                               payload.ToString(),
                                               flags,
                                               issuingClientId,
                                               subscribeKey,
                                               sequenceNumber,
                                               (originatingTimetoken != null) ? originatingTimetoken.Timetoken.ToString() : "",
                                               (originatingTimetoken != null) ? originatingTimetoken.Region : "",
                                               (publishMetadata != null) ? publishMetadata.Timetoken.ToString() : "",
                                               (publishMetadata != null) ? publishMetadata.Region : "",
                                               (userMetadata != null) ? userMetadata.ToString() : "null",
                                               log,
                                               messageType),
                                 PNLoggingMethod.LevelInfo);
                #endif

                subscribeMessages.Add(subscribeMessage);
                return(true);
            }
            #if (ENABLE_PUBNUB_LOGGING)
            else
            {
                pnLog.WriteToLog(string.Format("AddToSubscribeMessageList: CreateListOfSubscribeMessage create SubscribeMessage failed. dictObject type: {0}, dict type : {1}", dictObject.ToString(), dict.ToString()), PNLoggingMethod.LevelInfo);
            }
            #endif
            return(false);
        }
예제 #7
0
        public static List <ChannelEntity> CreateChannelEntity(string[] channelOrChannelGroupNames, bool isAwaitingConnectCallback, bool isChannelGroup, Dictionary <string, object> userState, PNLoggingMethod pnLog)
        {
            List <ChannelEntity> channelEntities = null;

            if (channelOrChannelGroupNames != null)
            {
                channelEntities = new List <ChannelEntity> ();
                foreach (string ch in channelOrChannelGroupNames)
                {
                    ChannelEntity chEntity = CreateChannelEntity(ch, isAwaitingConnectCallback, isChannelGroup, userState, pnLog);
                    if (chEntity != null)
                    {
                        channelEntities.Add(chEntity);
                    }
                }
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("CreateChannelEntity 2: channelEntities={0}", channelEntities.Count), PNLoggingMethod.LevelInfo);
                #endif
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("CreateChannelEntity 2: channelOrChannelGroupNames null, is channel group {0}", isChannelGroup.ToString()), PNLoggingMethod.LevelInfo);
                #endif
            }

            return(channelEntities);
        }
예제 #8
0
        public static ChannelEntity CreateChannelEntity(string channelOrChannelGroupName2, bool isAwaitingConnectCallback, bool isChannelGroup, Dictionary <string, object> userState, PNLoggingMethod pnLog)
        {
            string channelOrChannelGroupName = channelOrChannelGroupName2.Trim();

            #if (ENABLE_PUBNUB_LOGGING)
            pnLog.WriteToLog(string.Format("CreateChannelEntity: channelOrChannelGroupName {0}, {1}", channelOrChannelGroupName.ToString(), channelOrChannelGroupName2.ToString()), PNLoggingMethod.LevelInfo);
            #endif

            if (!string.IsNullOrEmpty(channelOrChannelGroupName))
            {
                ChannelIdentity ci = new ChannelIdentity();
                ci.ChannelOrChannelGroupName = channelOrChannelGroupName;
                ci.IsPresenceChannel         = Utility.IsPresenceChannel(channelOrChannelGroupName);
                ci.IsChannelGroup            = isChannelGroup;

                ChannelParameters cp = new ChannelParameters();
                cp.IsAwaitingConnectCallback = isAwaitingConnectCallback;
                cp.UserState = userState;
                ChannelEntity ce = new ChannelEntity(ci, cp);

                return(ce);
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("CreateChannelEntity: channelOrChannelGroupName empty, is channel group {0}", isChannelGroup.ToString()), PNLoggingMethod.LevelInfo);
                #endif

                return(null);
            }
        }
예제 #9
0
        public static TimetokenMetadata CreateTimetokenMetadata(object timeTokenDataObject, string whichTT, PNLoggingMethod pnLog)
        {
            Dictionary <string, object> timeTokenData = (Dictionary <string, object>)timeTokenDataObject;
            string log;
            long   timetoken;

            Utility.TryCheckKeyAndParseLong(timeTokenData, whichTT, "t", out log, out timetoken);
            TimetokenMetadata timetokenMetadata = new TimetokenMetadata(timetoken, (timeTokenData.ContainsKey("r")) ? timeTokenData["r"].ToString(): "");

            #if (ENABLE_PUBNUB_LOGGING)
            pnLog.WriteToLog(string.Format("TimetokenMetadata: {0} \nTimetoken: {1} \nRegion: {2}\nlog : {3}", whichTT, timetokenMetadata.Timetoken, timetokenMetadata.Region, log), PNLoggingMethod.LevelInfo);
            #endif

            return(timetokenMetadata);
        }
예제 #10
0
        public static string JsonEncodePublishMsg(object originalMessage, string cipherKey, IJsonLibrary jsonPluggableLibrary, PNLoggingMethod pnLog)
        {
            string message = jsonPluggableLibrary.SerializeToJsonString(originalMessage);

            if (!string.IsNullOrEmpty(cipherKey) && (cipherKey.Length > 0))
            {
                PubnubCrypto aes            = new PubnubCrypto(cipherKey, pnLog);
                string       encryptMessage = aes.Encrypt(message);
                message = jsonPluggableLibrary.SerializeToJsonString(encryptMessage);
            }

            return(message);
        }