Exemple #1
0
        static async Task HandleConnectionAsync(WebSocket ws, CancellationToken cancellation)
        {
            SignallingManager signalling_manager = null;

            try
            {
                signalling_manager = new SignallingManager(ws);
                signalling_manager.ReceivedFeedback = IncomingFeedback;
                signalling_manager.SentFeedback     = OutgoingFeedback;
                Log("Connected " + signalling_manager.ConnectionId.ToString("B"));
                while (ws.IsConnected && !cancellation.IsCancellationRequested)
                {
                    await signalling_manager.HandleConnection(cancellation);
                }
            }
            catch (Exception aex)
            {
                string message = aex.GetBaseException().Message;
                if (message.Equals("The connection is closed"))
                {
                    Log("Connection closed with " + signalling_manager.ConnectionId.ToString("B"));
                }
                else
                {
                    Log("Error Handling connection: " + message);
                }
                try { ws.Close(); }
                catch { }
            }
            finally
            {
                ws.Dispose();
                if (signalling_manager != null)
                {
                    signalling_manager.Close();
                }
            }
        }
Exemple #2
0
 static void OutgoingFeedback(string data, SignallingManager manager)
 {
     Log("Sent to client (" + manager.ConnectionId.ToString("B") + "): " + data);
 }
Exemple #3
0
 static void IncomingFeedback(string data, SignallingManager manager)
 {
     Log("Received from client (" + manager.ConnectionId.ToString("B") + "): " + data);
 }