/// <summary> /// This event registers with the chat server /// </summary> public void RegisterWithServer() { SubscriberCallback callback = new SubscriberCallback(SubscriberName); callback.Callback = Listen; callback.Name = SubscriberName; // Get a message back SubscriberMessage message = SubscriberService.Subscribe(callback); // if message.Text exists and equals Subscribed if ((NullHelper.Exists(message)) && (message.HasText) && (TextHelper.IsEqual(message.Text, "Subscribed"))) { // Set to true Connected = true; // Set the Id the Server assigned this.Id = message.ToId; } // Convert the Subscribers to Names this.Names = SubscriberService.GetSubscriberNames(); // get the count int count = NumericHelper.ParseInteger(message.Data.ToString(), 0, -1); // if there are two people online or more if (count > 1) { // send a message to everyone else this user has joined SubscriberMessage newMessage = new SubscriberMessage(); // set the text newMessage.FromId = Id; newMessage.FromName = SubscriberName; newMessage.Text = SubscriberName + " has joined the conversation."; newMessage.ToId = Guid.Empty; newMessage.ToName = "Room"; newMessage.IsSystemMessage = true; // Send the message SubscriberService.BroadcastMessage(newMessage); // 6.5.2020: Get the Messages as you connect now this.Messages = SubscriberService.GetBroadcastMessages(this.Id, DisplayMessagesCount); } // Update Refresh(); }
/// <summary> /// This method Listen /// </summary> public void Listen(SubscriberMessage message) { // if the message exists if (NullHelper.Exists(message)) { // if the message is a SystemMessage if (message.IsSystemMessage) { // Get the Names again this.Names = SubscriberService.GetSubscriberNames(); // Update the UI Refresh(); } else { // Get the Messages this.Messages = SubscriberService.GetBroadcastMessages(this.Id, DisplayMessagesCount); // Update the UI Refresh(); } } }