public static IServiceCollection AddLocalTunnelClient(this IServiceCollection services) { services.AddScoped ( service => { var clientTunnel = new LocaltunnelClient(); return(clientTunnel); } ); return(services); }
public static async Task RunAsync(BaseConfiguration configuration, Func <TunnelConnectionHandle, TunnelConnection> connectionFactory, CancellationToken cancellationToken) { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } if (connectionFactory is null) { throw new ArgumentNullException(nameof(connectionFactory)); } using var loggerFactory = LoggerFactory.Create(x => x .AddConsole() .SetMinimumLevel(configuration.Verbose ? LogLevel.Trace : LogLevel.Information)); var clientLogger = loggerFactory.CreateLogger <LocaltunnelClient>(); using var client = new LocaltunnelClient(new Uri(configuration.Server), clientLogger); var connections = Math.Min(10, configuration.MaxConnections); clientLogger.LogDebug(Resources.CreatingTunnelWithNConnections, connections); using var tunnel = await client.OpenAsync(connectionFactory, configuration.Subdomain, cancellationToken); await tunnel.StartAsync(connections); if (configuration.Browser) { clientLogger.LogDebug(Resources.StartingBrowser, tunnel.Information.Url); StartBrowser(tunnel); } clientLogger.LogInformation(Resources.PressToExit); if (configuration.NoDashboard) { await WaitSilentAsync(cancellationToken); } else { await TunnelDashboard.Show(tunnel, configuration, cancellationToken); } clientLogger.LogInformation(Resources.ShuttingDown); }
public Tunnel CreateTunnel( string subdomain, int port ) { var tunnelClient = new LocaltunnelClient(); Log.Information( "Creating tunnel for subdomain {Subdomain}:{Port}", subdomain, port ); var tunnel = tunnelClient.OpenAsync( handle => { var options = new ProxiedHttpTunnelOptions() { Host = "localhost", Port = port, ReceiveBufferSize = 100 }; return(new ProxiedHttpTunnelConnection(handle, options)); }, subdomain: subdomain, CancellationToken.None ) .WaitAndUnwrapException(); tunnel.StartAsync().WaitAndUnwrapException(); var tunnelUrl = tunnel.Information.Url; var tunnelId = tunnel.Information.Id; Log.Information("Tunnel URL: {TunnelUrl}", tunnelUrl); Log.Information("Tunnel URL: {TunnelId}", tunnelId); return(tunnel); }