8000 GitHub - Im0/sauce.net
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Im0/sauce.net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Use in ASP.NET Core

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddHttpClient<Sauce.Client>(client =>
    {
        // Instance of Sauce connecting to
        client.BaseAddress = new Uri("http://192.168.1.100:1080");
    })
    .ConfigurePrimaryHttpMessageHandler(() =>
    {
        return new SocketsHttpHandler()
        {
            PooledConnectionLifetime = TimeSpan.FromHours(1)
        };
    })
    .SetHandlerLifetime(Timeout.InfiniteTimeSpan);

builder.Services
    .AddScoped<Sauce.Client>();

Subscripting to Messages

// You can use DI to assign to _sauce via ctor()
private Sauce.Client _sauce;
private Subscription? _subscription;
private WebsocketClient? _websocketClient;

private async Task DoInitializeAsync()
{
  // this is a predefined subscription, you can create your own
  _subscription = Sauce.Client.Watching();
  _websocketClient = await _sauce.SubscribeTo<Watched>(_subscription, async watched =>
  {
    // process the `Watched watched` input
  });
}

public void Dispose()
{
  if (_websocketClient is not null && _subscription is not null)
  {
    Sauce.Client.UnsubscribeFrom(_websocketClient, _subscription);
    _websocketClient.Dispose();
    _websocketClient = null;
    _subscription = null;
  }
}

The class passed to SubscribeTo is a model you define, which will be constructed from the JSON received via the websocket. This way you can define only the fields you are interested in receiving.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%
0