private void Call() { roomName = roomNameText.text; Debug.Log($"Calling room {roomName}"); if (roomName.Length == 0) { infoText.text = "Please enter a room name"; return; } callButton.interactable = false; void onOpen() { Debug.Log("onOpen"); SendWsMessage("create or join", new JsonMessageData { room = roomName }); } void onMessage(string msg) { Debug.Log("onMessage"); HandleMessage(msg); } ws = new WebsocketClient(onOpen, onMessage); ws.Connect(); }
static async Task Main(string[] args) { try { Console.CancelKeyPress += CancelKeyPressed; var token = ApiToken; while (string.IsNullOrWhiteSpace(token)) { Console.Write("Please specify your api token: "); token = Console.ReadLine(); } Console.WriteLine("Connecting to Finnhub..."); cl = new WebsocketClient(token); await cl.Connect(cts.Token); Console.WriteLine("Connected."); foreach (var symbol in symbols) { await cl.Subscribe(symbol, cts.Token); Console.WriteLine($"Subscribed {symbol}"); } while (!cancelPressed) { var msg = await cl.Receive(cts.Token); switch (msg) { case PingMessage ping: Console.WriteLine("Ping"); break; case ErrorMessage err: Console.WriteLine($"ERROR returned by Finnhub: {err.Msg}"); break; case TradeMessage trade: var tradeMsg = string.Join("\n", trade.Data.Select(t => $"{t.S} - #{t.V} x {t.P}")); Console.WriteLine($"Trade: {tradeMsg}"); break; default: Console.WriteLine($"WARNING: Unknown message received."); break; } } } catch (OperationCanceledException) { } catch (WebSocketException wse) { Console.WriteLine($"CONNECTION ERROR: {wse}"); } }