public void Connect(SessionToken sessionTokenClass = null) { var sclient = new StreamrClient(); sessionToken = sessionTokenClass; websocketClient = new WebsocketClient(new Uri(WebSocketURL)); websocketClient.ReconnectTimeout = TimeSpan.FromSeconds(30); websocketClient.ReconnectionHappened.Subscribe(type => Console.WriteLine($"Reconnection happened, type: {type}")); websocketClient.MessageReceived.Subscribe(msg => { int ptS = 0; int ptE; while (ptS < msg.Text.Length) { ptE = msg.Text.IndexOf("][", ptS); if (ptE == -1) { if (msg.Text.Last() == ']') { ptE = msg.Text.Length - 1; } else { sb.Append(msg.Text.Substring(ptS, msg.Text.Length - ptS)); break; } } if (sb.Length > 0) //Previous data in buffer { sb.Append(msg.Text.Substring(ptS, ptE - ptS + 1)); //Add next message to buffer string message = sb.ToString(1, sb.Length - 2); ProcessMessage(ref message); //Process sb.Clear(); } else { string message = msg.Text.Substring(ptS + 1, ptE - ptS - 1); ProcessMessage(ref message); } ptS = ptE + 1; } }); websocketClient.Start(); }
public Stream(StreamrClient client, string streamID, string requestID = "myapp") { Client = client; StreamID = streamID; RequestID = requestID; }