Ejemplo n.º 1
0
 private async Task Disconnected(Network.Enums.CloseReason reason, Connection connection)
 {
     //Stop program
     CancelTokenSource.Cancel();
     ConLog.Log("WebMedia Link", "Disconnected from WebMediaLink server", LogType.Fatal);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when a media server disconnects. Removes the connection from the appropriate dictionaries
        /// </summary>
        /// <param name="connection">The connection that disconnected</param>
        /// <param name="type">The type of connection. Should be TCP</param>
        /// <param name="reason">The reason for disconnecting</param>
        /// <returns>A Task representing the operation</returns>
        private static async Task WebMediaDisconnected(Connection connection, Network.Enums.ConnectionType type, Network.Enums.CloseReason reason)
        {
            //Check that it's TCP
            if (type != Network.Enums.ConnectionType.TCP)
            {
                return;
            }

            //Check that it exists
            if (ConnectionToUuid.ContainsKey((TcpConnection)connection))
            {
                //Get the UUID
                MediaServer deadServer = UuidToMediaServer[ConnectionToUuid[(TcpConnection)connection]];

                ConLog.Log("WebMedia Link", "Media server with name " + deadServer.Name + " and address " + connection.IPRemoteEndPoint.ToString() + " disconnected", LogType.Info);

                //Remove the packet handlers
                connection.UnRegisterRawDataHandler("AvailableFilesUpdated");

                //Close it
                await deadServer.Close(false);

                //Remove from dictionaries
                UuidToMediaServer.Remove(deadServer.UUID);
                ConnectionToUuid.Remove((TcpConnection)connection);

                //Update SignalR
                await UpdateAllSignalRClients();

                ConLog.Log("WebMedia Link", "Removed media server with name " + deadServer.Name, LogType.Ok);
            }
            else
            {
                ConLog.Log("WebMedia Link", "Media server with address " + connection.IPRemoteEndPoint.ToString() + " disconnected", LogType.Info);
            }
        }