void StartPresenceHeartbeat(bool pause, int pauseTime)
        {
            try {
                if (PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups.Count > 0)
                {
                    isPresenceHearbeatRunning = true;
                    string channelsJsonState = PubNubInstance.SubscriptionInstance.CompiledUserState;

                    Uri request = BuildRequests.BuildPresenceHeartbeatRequest(
                        Helpers.GetNamesFromChannelEntities(PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups, false),
                        Helpers.GetNamesFromChannelEntities(PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups, true),
                        channelsJsonState,
                        this.PubNubInstance
                        );

                    RequestState requestState = new RequestState();
                    requestState.OperationType = PNOperationType.PNPresenceHeartbeatOperation;
                    requestState.URL           = request.OriginalString;
                    requestState.Timeout       = PubNubInstance.PNConfig.NonSubscribeTimeout;
                    requestState.Pause         = pauseTime;
                    requestState.Reconnect     = pause;

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("presenceheartbeat: request.OriginalString {0} ", request.OriginalString), PNLoggingMethod.LevelError);
                    #endif

                    webRequestId = webRequest.Run(requestState);

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: PresenceHeartbeat running "), PNLoggingMethod.LevelInfo);
                    #endif
                }
            }
            catch (Exception ex) {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: PresenceHeartbeat exception {0}", ex.ToString()), PNLoggingMethod.LevelError);
                #endif
            }
        }
示例#2
0
        void StartPresenceHeartbeat(bool pause, int pauseTime)
        {
            try {
                string channelsJsonState;
                int    allNonPresenceChannelsOrChannelGroupsCount;
                string channels;
                string channelGroups;

                if (RunIndependentOfSubscribe)
                {
                    channelsJsonState = State;
                    allNonPresenceChannelsOrChannelGroupsCount = ((ChannelGroups.Length > 0)?ChannelGroups.Split(',').Count():0) + ((Channels.Length > 0)?Channels.Split(',').Count():0);
                    Debug.Log("allNonPresenceChannelsOrChannelGroupsCount:" + allNonPresenceChannelsOrChannelGroupsCount);
                    channels      = Channels;
                    channelGroups = ChannelGroups;
                }
                else
                {
                    channelsJsonState = PubNubInstance.SubscriptionInstance.CompiledUserState;
                    allNonPresenceChannelsOrChannelGroupsCount = PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups.Count;
                    channels      = Helpers.GetNamesFromChannelEntities(PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups, false);
                    channelGroups = Helpers.GetNamesFromChannelEntities(PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups, true);
                }

                if (allNonPresenceChannelsOrChannelGroupsCount > 0)
                {
                    isPresenceHearbeatRunning = true;
                    Uri request = BuildRequests.BuildPresenceHeartbeatRequest(
                        channels,
                        channelGroups,
                        channelsJsonState,
                        this.PubNubInstance,
                        null
                        );

                    RequestState requestState = new RequestState();
                    requestState.OperationType = PNOperationType.PNPresenceHeartbeatOperation;
                    requestState.URL           = request.OriginalString;
                    requestState.Timeout       = PubNubInstance.PNConfig.NonSubscribeTimeout;
                    requestState.Pause         = pauseTime;
                    requestState.Reconnect     = pause;

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("presenceheartbeat: /presence/ request.OriginalString {0} ", request.OriginalString), PNLoggingMethod.LevelError);
                    #endif

                    webRequestId = webRequest.Run(requestState);

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: PresenceHeartbeat running, {0} ", pauseTime), PNLoggingMethod.LevelInfo);
                    #endif
                }
                #if (ENABLE_PUBNUB_LOGGING)
                else
                {
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: AllNonPresenceChannelsOrChannelGroups < 0 "), PNLoggingMethod.LevelInfo);
                }
                #endif
            }
            catch (Exception ex) {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: PresenceHeartbeat exception {0}", ex.ToString()), PNLoggingMethod.LevelError);
                #endif
            }
        }