public void Emit(string eventName, JsonData data) { var wsData = new WebSocketEventData("42", eventName, data); string d = wsData.ToSocketData(); Debug.Log(d); m_webSocket.Send(d); }
private void EventHandlerOnMessage(object sender, MessageEventArgs e) { if (e.IsPing) { return; } Debug.Log($"OnMessage\nData: {e.Data}"); var eventData = new WebSocketEventData(e.Data); switch (eventData.code) { //Handshake event. case "0": { var data = eventData.data; if (data != null && data.IsObject) { if (data.ContainsKey("sid") && data["sid"].IsString) { m_sid = (string)data["sid"]; Debug.Log($"SID: {m_sid}"); } if (data.ContainsKey("pingInterval") && data["pingInterval"].IsInt) { var cPingInterval = (int)data["pingInterval"]; m_pingInterval = cPingInterval / 1000.0f; Debug.Log($"PingInterval: {m_pingInterval.ToString("N2")}"); } if (data.ContainsKey("pingTimeout") && data["pingTimeout"].IsInt) { var cPingTimeout = (int)data["pingTimeout"]; m_pingTimeout = cPingTimeout / 1000.0f; Debug.Log($"PingTimeout: {m_pingTimeout.ToString("N2")}"); } } } break; //Ping-pong event. case "3": { } break; case "42": { if (events.ContainsKey(eventData.eventName)) { behaviour.AddAction(() => { events[eventData.eventName]?.Invoke(eventData.data); }); } } break; default: break; } Debug.Log(eventData.ToString()); }