26 lines
812 B
C#
26 lines
812 B
C#
namespace Bts.DataStream.Websocket;
|
|
|
|
using bts;
|
|
|
|
using Google.Protobuf;
|
|
|
|
using System.Text.Json;
|
|
|
|
public static class Session {
|
|
static int sessionIdCounter;
|
|
|
|
public static async Task Start(
|
|
WebsocketServerConfig config, JsonSerializerOptions? opts) {
|
|
opts ??= JsonSerializerOptions.Default;
|
|
var sessionId = Interlocked.Increment(ref sessionIdCounter);
|
|
var gateway = new WebsocketClient(config);
|
|
var sync = new DataSync(opts);
|
|
using (gateway.Subscribe(sync))
|
|
using (sync.Subscribe(gateway)) {
|
|
Log.Api.info($"Starting DataStream Websocket Session {sessionId}");
|
|
Log.Api.info($"DataStream Websocket Session {sessionId} config:\n{JsonFormatter.Default.Format(config)}");
|
|
await gateway.ConnectAsync();
|
|
}
|
|
}
|
|
}
|