public void StartProvidingTelemetry() { SockJS = new SockJS(EndpointConfiguration.Value.Url); SockJS.AddEventListener("open", (sender, e) => { SockJS.Send(EndpointConfiguration.Value.ConnectionString); }); SockJS.AddEventListener("message", (sender, obj) => { if (obj[0] is TransportMessageEvent msg) { var dataString = msg.Data.ToString(); if (dataString.Contains("No subscription found")) { return; } var conn = dataString.StartsWith("CONNECTED"); canSend |= conn; if (conn) { SubscriptionModels.ToList().ForEach(ProcessChanges); } var kk = TransportLocationData.FromJson(dataString); if (kk is null) { return; } OnTelemetryArrived?.Invoke(this, kk); } }); SockJS.AddEventListener("close", (sender, e) => { Task.Run(StartProvidingTelemetry); }); }
public TransportDataProviderService(IOptions <EndpointConfiguration> EndpointConfiguration) { this.EndpointConfiguration = EndpointConfiguration; OnSubscriptionListChanged = (b) => { SubscriptionModels.Add(b); ProcessChanges(b); }; }