Exemplo n.º 1
0
 public static ChatWindowViewModel GetInstance()
 {
     if (instance == null)
     {
         instance = new ChatWindowViewModel();
     }
     return(instance);
 }
Exemplo n.º 2
0
        public static void WebSocket_ReceivedMessage(MessageWebSocket ws, MessageWebSocketMessageReceivedEventArgs args)
        {
            DataReader reader = args.GetDataReader();

            reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
            string result   = reader.ReadString(reader.UnconsumedBufferLength);
            string username = result.Substring(0, result.IndexOf(' '));
            string content  = result.Substring(result.IndexOf(' ') + 1, result.Length - 1 - result.IndexOf(' '));

            //Here, you need to put receive message to the chat room view model.
            Debug.WriteLine(result);
            ChatWindowViewModel myChatViewModel = ChatWindowViewModel.GetInstance();

            if (username == NetworkControl.username)
            {
                myChatViewModel.AddMessageSelf(username, content);
            }
            else
            {
                myChatViewModel.AddMessage(username, content);
            }
        }