internal void CreatePNPresenceEventResult(SubscribeMessage subscribeMessage, out PNPresenceEventResult messageResult) { long timetoken = (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Timetoken : 0; PNPresenceEvent pnPresenceEvent = CreatePNPresenceEvent(subscribeMessage.Payload); messageResult = new PNPresenceEventResult( subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""), subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""), pnPresenceEvent.Action, timetoken, pnPresenceEvent.Timestamp, subscribeMessage.UserMetadata, pnPresenceEvent.State, pnPresenceEvent.UUID, pnPresenceEvent.Occupancy, subscribeMessage.IssuingClientId, pnPresenceEvent.Join, pnPresenceEvent.Leave, pnPresenceEvent.Timeout ); }
internal PNPresenceEvent CreatePNPresenceEvent(object payload) { Dictionary <string, object> pnPresenceEventDict = (Dictionary <string, object>)payload; string log = ""; int occupancy = 0; if (Utility.TryCheckKeyAndParseInt(pnPresenceEventDict, "occupancy", "occupancy", out log, out occupancy)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("occupancy: {0}", occupancy), PNLoggingMethod.LevelInfo); #endif } long timetoken; Utility.TryCheckKeyAndParseLong(pnPresenceEventDict, "timestamp", "timestamp", out log, out timetoken); bool hereNowRefresh = false; if (pnPresenceEventDict.ContainsKey("here_now_refresh")) { hereNowRefresh = (bool)pnPresenceEventDict["here_now_refresh"]; } PNPresenceEvent pnPresenceEvent = new PNPresenceEvent( (pnPresenceEventDict.ContainsKey("action"))?pnPresenceEventDict["action"].ToString():"", (pnPresenceEventDict.ContainsKey("uuid"))?pnPresenceEventDict["uuid"].ToString():"", occupancy, timetoken, (pnPresenceEventDict.ContainsKey("data"))?pnPresenceEventDict["data"]:null, Utility.CheckKeyAndConvertObjToStringArr((pnPresenceEventDict.ContainsKey("join"))?pnPresenceEventDict["join"]:null), Utility.CheckKeyAndConvertObjToStringArr((pnPresenceEventDict.ContainsKey("leave"))?pnPresenceEventDict["leave"]:null), Utility.CheckKeyAndConvertObjToStringArr((pnPresenceEventDict.ContainsKey("timeout"))?pnPresenceEventDict["timeout"]:null), hereNowRefresh ); //"action": "join", "timestamp": 1473952169, "uuid": "a7acb27c-f1da-4031-a2cc-58656196b06d", "occupancy": 1 //"action": "interval", "timestamp": 1490700797, "occupancy": 3, "join": ["Client-odx4y", "test"] #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("Action: {0} \nTimestamp: {1} \nOccupancy: {2}\nUUID: {3}", pnPresenceEvent.Action, pnPresenceEvent.Timestamp, pnPresenceEvent.Occupancy, pnPresenceEvent.UUID), PNLoggingMethod.LevelInfo); #endif return(pnPresenceEvent); }