void DisplayHereNowResult(PNHereNowResult result) { if (result.Channels != null) { foreach (KeyValuePair <string, PNHereNowChannelData> kvp in result.Channels) { Debug.Log("in HereNow channel: " + kvp.Key); if (kvp.Value != null) { PNHereNowChannelData hereNowChannelData = kvp.Value as PNHereNowChannelData; if (hereNowChannelData != null) { Debug.Log("in HereNow channelName: " + hereNowChannelData.ChannelName); Display(string.Format("channelName: {0}", hereNowChannelData.ChannelName)); Debug.Log("in HereNow channel occupancy: " + hereNowChannelData.Occupancy.ToString()); Display(string.Format("channelName: {0}", hereNowChannelData.Occupancy)); List <PNHereNowOccupantData> hereNowOccupantData = hereNowChannelData.Occupants as List <PNHereNowOccupantData>; if (hereNowOccupantData != null) { foreach (PNHereNowOccupantData pnHereNowOccupantData in hereNowOccupantData) { if (pnHereNowOccupantData.State != null) { Debug.Log("in HereNow channel State: " + pnHereNowOccupantData.State.ToString()); Display(string.Format("State: {0}", pnHereNowOccupantData.State.ToString())); } if (pnHereNowOccupantData.UUID != null) { Debug.Log("in HereNow channel UUID: " + pnHereNowOccupantData.UUID.ToString()); Display(string.Format("UUID: {0}", pnHereNowOccupantData.UUID.ToString())); } } } else { Debug.Log("in HereNow hereNowOccupantData null"); } } else { Debug.Log("in HereNow hereNowChannelData null"); } } else { Debug.Log("in HereNow kvp null"); } } } else { Debug.Log("in HereNow channels null"); } }
void HereNow() { Pubnub pubnub = new Pubnub(pnConfiguration); pubnub.HereNow() // tailor the next two lines to example .Channels(new string[] { "coolChannel", "coolChannel2" }) .IncludeUUIDs(true) .Async(new PNHereNowResultEx( (result, status) => { if (status.Error) { // handle error return; } if (result.Channels != null && result.Channels.Count > 0) { foreach (KeyValuePair <string, PNHereNowChannelData> kvp in result.Channels) { PNHereNowChannelData channelData = kvp.Value; Console.WriteLine("---"); Console.WriteLine("channel:" + channelData.ChannelName); Console.WriteLine("occupancy:" + channelData.Occupancy); Console.WriteLine("Occupants:"); if (channelData.Occupants != null && channelData.Occupants.Count > 0) { for (int index = 0; index < channelData.Occupants.Count; index++) { PNHereNowOccupantData occupant = channelData.Occupants[index]; Console.WriteLine(string.Format("uuid: {0}", occupant.Uuid)); Console.WriteLine(string.Format("state:{1}", (occupant.State != null) ? pubnub.JsonPluggableLibrary.SerializeToJsonString(occupant.State) : "")); } } } } } )); }
void DisplayHereNowResult(PNHereNowResult result) { if (result.Channels != null) { foreach (KeyValuePair <string, PNHereNowChannelData> kvp in result.Channels) { Debug.Log("in HereNow channel: " + kvp.Key); if (kvp.Value != null) { PNHereNowChannelData hereNowChannelData = kvp.Value as PNHereNowChannelData; if (hereNowChannelData != null) { StringBuilder sb = new StringBuilder(); sb.Append("in HereNow channelName: " + hereNowChannelData.ChannelName); Display(string.Format("channelName: {0}", hereNowChannelData.ChannelName)); sb.Append("in HereNow channel occupancy: " + hereNowChannelData.Occupancy.ToString()); Display(string.Format("channelName: {0}", hereNowChannelData.Occupancy)); List <PNHereNowOccupantData> hereNowOccupantData = hereNowChannelData.Occupants as List <PNHereNowOccupantData>; if (hereNowOccupantData != null) { foreach (PNHereNowOccupantData pnHereNowOccupantData in hereNowOccupantData) { if (pnHereNowOccupantData.State != null) { sb.Append("in HereNow channel State: " + pnHereNowOccupantData.State.ToString()); Dictionary <string, object> state = pnHereNowOccupantData.State as Dictionary <string, object>; foreach (KeyValuePair <string, object> kvpState in state) { sb.Append(kvp.Key); sb.Append("=====>"); sb.Append(kvp.Value.ToString()); } Display(string.Format("State: {0}", pnHereNowOccupantData.State.ToString())); } if (pnHereNowOccupantData.UUID != null) { sb.Append("in HereNow channel UUID: " + pnHereNowOccupantData.UUID.ToString()); Display(string.Format("UUID: {0}", pnHereNowOccupantData.UUID.ToString())); } } } else { sb.Append("in HereNow hereNowOccupantData null"); } Debug.Log(sb.ToString()); } else { Debug.Log("in HereNow hereNowChannelData null"); } } else { Debug.Log("in HereNow kvp null"); } } } else { Debug.Log("in HereNow channels null"); } }