Ejemplo n.º 1
0
        static internal void Uninitialize()
        {
            if (instance != null)
            {
                lock (lockObject)
                {
                    if (instance != null)
                    {
                        instance.pubnubClient.RemoveListener(instance.subscribeCallback);

                        instance.pubnubClient.Unsubscribe <string>().ChannelGroups(new string[] { instance.ChannelGroup }).Execute();

                        instance.pubnubClient.Destroy();
                        instance.pubnubClient = null;

                        instance.ChannelGroup = null;

                        instance.mapChannelToCallback.Clear();
                        instance.mapChannelToCallback = null;

                        instance.KinveyClient = null;

                        instance = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static internal void Initialize(string channelGroup, string publishKey, string subscribeKey, string authKey, AbstractClient client, RealtimeReconnectionPolicy realtimeReconnectionPolicy)
        {
            if (instance == null)
            {
                lock (lockObject)
                {
                    if (instance == null)
                    {
                        instance = new RealtimeRouter();
                        if (instance.pubnubClient == null)
                        {
                            PubnubApi.PNConfiguration PNconfig = new PubnubApi.PNConfiguration();
                            PNconfig.SubscribeKey       = subscribeKey;
                            PNconfig.PublishKey         = publishKey;
                            PNconfig.AuthKey            = authKey;
                            PNconfig.Secure             = true;
                            PNconfig.ReconnectionPolicy = realtimeReconnectionPolicy.ConvertToPNReconnectionPolicy();
                            instance.pubnubClient       = new PubnubApi.Pubnub(PNconfig);

                            instance.subscribeCallback = new PubnubApi.SubscribeCallbackExt(
                                (pubnubObj, message) => { instance.SubscribeCallback(message.Channel, message.Message as string); },
                                (pubnubObj, presence) => { /* presence not currently supported */ }, // TODO Support PubNub presence
                                (pubnubObj, status) =>
                            {
                                instance.HandleStatusMessage(status);
                            }
                                );

                            instance.pubnubClient.AddListener(instance.subscribeCallback);

                            instance.ChannelGroup = channelGroup;
                            instance.pubnubClient.Subscribe <string>().ChannelGroups(new string[] { instance.ChannelGroup }).Execute();

                            //FOR UNIQUE DEVICE GUID GENERATION --> Guid deviceGUID = pubnubClient.GenerateGuid(); string deviceID = deviceGUID.ToString();
                            instance.KinveyClient         = client;
                            instance.mapChannelToCallback = new Dictionary <string, KinveyRealtimeDelegate>();
                        }
                    }
                }
            }
        }