internal void OnHandshake(HandshakeData handshakeData) { Logger.Log(nameof(OnHandshake)); Emit(EVENT_HANDSHAKE, handshakeData); Id = handshakeData.Sid; Transport.Query.Add("sid", handshakeData.Sid); Upgrades = FilterUpgrades(handshakeData.Upgrades); PingInterval = handshakeData.PingInterval; PingTimeout = handshakeData.PingTimeout; OnOpen(); // In case open handler closes socket if (ReadyStateEnum.CLOSED == ReadyState) { return; } SetPing(); Off(EVENT_HEARTBEAT, new OnHeartbeatAsListener(this)); On(EVENT_HEARTBEAT, new OnHeartbeatAsListener(this)); }
public void OnPacket(Packet packet) { if (ReadyState == ReadyStateEnum.OPENING || ReadyState == ReadyStateEnum.OPEN) { Logger.Log($"socket received: type '{packet.Type}', data '{packet.Data}'"); Emit(EVENT_PACKET, packet); Emit(EVENT_HEARTBEAT); if (packet.Type == Packet.OPEN) { OnHandshake(HandshakeData.FromString((string)packet.Data)); } else if (packet.Type == Packet.PONG) { SetPing(); } else if (packet.Type == Packet.ERROR) { var err = new PureEngineIOException("server error") { Code = packet.Data }; Emit(EVENT_ERROR, err); } else if (packet.Type == Packet.MESSAGE) { Emit(EVENT_DATA, packet.Data); Emit(EVENT_MESSAGE, packet.Data); } } else { Logger.Log($"OnPacket packet received with socket readyState '{ReadyState}'"); } }