示例#1
0
 /// <summary>
 /// Handler for received message.
 /// Associated with Websocket.
 /// </summary>
 private void ReceivedMessage(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
 {
     try
     {
         // Use a datareader to read the message
         // out of the websocket args.
         using (DataReader dataReader = args.GetDataReader())
         {
             dataReader.UnicodeEncoding = UnicodeEncoding.Utf8;
             string           wrapped   = dataReader.ReadString(dataReader.UnconsumedBufferLength);
             SignallerMessage unwrapped = this.MessageProtocol.UnwrapMessage(wrapped);
             this.MessageHandlers[(string)unwrapped.Type]?.Invoke(this, unwrapped);
         }
     }
     catch (Exception ex)
     {
         Windows.Web.WebErrorStatus webErrorStatus = WebSocketError.GetStatus
                                                     (
             ex.GetBaseException().HResult
                                                     );
         System.Diagnostics.Debug.WriteLine(ex.ToString());
         this.IsConnected = false;
         this.ConnectionFailedUIHandler?.Invoke(this, EventArgs.Empty);
     }
 }
示例#2
0
 /// <summary>
 /// Room Create Message Handler.
 /// </summary>
 private void ReceivedRoomCreateMessage(object sender, SignallerMessage message)
 {
     if (message.Contents == "")
     {
         this.RoomCreateFailedUIHandler?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         this.RequestJoinRoom(message.Contents);
     }
 }
示例#3
0
 /// <summary>
 /// Room Join Message Handler.
 /// </summary>
 private void ReceivedRoomJoinMessage(object sender, SignallerMessage message)
 {
     if (message.Contents == "")
     {
         this.RoomJoinFailedUIHandler?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         this.RoomId = message.Contents;
         this.RoomJoinSuccessUIHandler?.Invoke(this, EventArgs.Empty);
     }
 }