this.ackManager = ackManager;
this.namespacesHub = namespacesHub;
}
public void onPacket(Packet packet, NamespaceClient client) {
final AckRequest ackRequest = new AckRequest(packet, client);
if (packet.isAckRequested()) {
ackManager.initAckIndex(client.getSessionId(), packet.getId());
}
switch (packet.getType()) {
case CONNECT: {
Namespace namespace = namespacesHub.get(packet.getEndpoint());
namespace.onConnect(client);
// send connect handshake packet back to client
client.send(packet);
break;
}
case ACK:
ackManager.onAck(client, packet);
break;
case EVENT: {
Object data = null;
if (packet.getArgs() != null
&& !packet.getArgs().isEmpty()) {
data = packet.getArgs().get(0);
}
Namespace namespace = namespacesHub.get(packet.getEndpoint());
namespace.onEvent(client, packet.getName(), data, ackRequest);
break;
}
case HEARTBEAT:
heartbeatHandler.onHeartbeat(client.getBaseClient());
break;
case MESSAGE: {
Namespace namespace = namespacesHub.get(packet.getEndpoint());
namespace.onMessage(client, packet.getData().toString(), ackRequest);
break;
}
case JSON: {
Namespace namespace = namespacesHub.get(packet.getEndpoint());
namespace.onJsonObject(client, packet.getData(), ackRequest);
break;
}
case DISCONNECT:
client.onDisconnect();
break;
default:
break;
}
// send ack response if it not executed
// during {@link DataListener#onData} invocation
ackRequest.sendAckData(Collections.emptyList());
}