Search in sources :

Example 1 with Namespace

use of com.corundumstudio.socketio.namespace.Namespace in project netty-socketio by mrniko.

the class InPacketHandler method channelRead0.

@Override
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, PacketsMessage message) throws Exception {
    ByteBuf content = message.getContent();
    ClientHead client = message.getClient();
    if (log.isTraceEnabled()) {
        log.trace("In message: {} sessionId: {}", content.toString(CharsetUtil.UTF_8), client.getSessionId());
    }
    while (content.isReadable()) {
        try {
            Packet packet = decoder.decodePackets(content, client);
            if (packet.hasAttachments() && !packet.isAttachmentsLoaded()) {
                return;
            }
            Namespace ns = namespacesHub.get(packet.getNsp());
            if (ns == null) {
                if (packet.getSubType() == PacketType.CONNECT) {
                    Packet p = new Packet(PacketType.MESSAGE);
                    p.setSubType(PacketType.ERROR);
                    p.setNsp(packet.getNsp());
                    p.setData("Invalid namespace");
                    client.send(p);
                    return;
                }
                log.debug("Can't find namespace for endpoint: {}, sessionId: {} probably it was removed.", packet.getNsp(), client.getSessionId());
                return;
            }
            if (packet.getSubType() == PacketType.CONNECT) {
                client.addNamespaceClient(ns);
            }
            NamespaceClient nClient = client.getChildClient(ns);
            if (nClient == null) {
                log.debug("Can't find namespace client in namespace: {}, sessionId: {} probably it was disconnected.", ns.getName(), client.getSessionId());
                return;
            }
            packetListener.onPacket(packet, nClient, message.getTransport());
        } catch (Exception ex) {
            String c = content.toString(CharsetUtil.UTF_8);
            log.error("Error during data processing. Client sessionId: " + client.getSessionId() + ", data: " + c, ex);
            throw ex;
        }
    }
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) NamespaceClient(com.corundumstudio.socketio.transport.NamespaceClient) ByteBuf(io.netty.buffer.ByteBuf) Namespace(com.corundumstudio.socketio.namespace.Namespace)

Example 2 with Namespace

use of com.corundumstudio.socketio.namespace.Namespace in project netty-socketio by mrniko.

the class BroadcastOperations method dispatch.

private void dispatch(Packet packet) {
    Map<String, Set<String>> namespaceRooms = new HashMap<String, Set<String>>();
    for (SocketIOClient socketIOClient : clients) {
        Namespace namespace = (Namespace) socketIOClient.getNamespace();
        Set<String> rooms = namespace.getRooms(socketIOClient);
        Set<String> roomsList = namespaceRooms.get(namespace.getName());
        if (roomsList == null) {
            roomsList = new HashSet<String>();
            namespaceRooms.put(namespace.getName(), roomsList);
        }
        roomsList.addAll(rooms);
    }
    for (Entry<String, Set<String>> entry : namespaceRooms.entrySet()) {
        for (String room : entry.getValue()) {
            storeFactory.pubSubStore().publish(PubSubType.DISPATCH, new DispatchMessage(room, packet, entry.getKey()));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) DispatchMessage(com.corundumstudio.socketio.store.pubsub.DispatchMessage) Namespace(com.corundumstudio.socketio.namespace.Namespace)

Example 3 with Namespace

use of com.corundumstudio.socketio.namespace.Namespace in project netty-socketio by mrniko.

the class AuthorizeHandler method connect.

public void connect(ClientHead client) {
    Namespace ns = namespacesHub.get(Namespace.DEFAULT_NAME);
    if (!client.getNamespaces().contains(ns)) {
        Packet packet = new Packet(PacketType.MESSAGE);
        packet.setSubType(PacketType.CONNECT);
        client.send(packet);
        configuration.getStoreFactory().pubSubStore().publish(PubSubType.CONNECT, new ConnectMessage(client.getSessionId()));
        SocketIOClient nsClient = client.addNamespaceClient(ns);
        ns.onConnect(nsClient);
    }
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) AuthPacket(com.corundumstudio.socketio.protocol.AuthPacket) SocketIOClient(com.corundumstudio.socketio.SocketIOClient) ConnectMessage(com.corundumstudio.socketio.store.pubsub.ConnectMessage) Namespace(com.corundumstudio.socketio.namespace.Namespace)

Aggregations

Namespace (com.corundumstudio.socketio.namespace.Namespace)3 Packet (com.corundumstudio.socketio.protocol.Packet)2 SocketIOClient (com.corundumstudio.socketio.SocketIOClient)1 AuthPacket (com.corundumstudio.socketio.protocol.AuthPacket)1 ConnectMessage (com.corundumstudio.socketio.store.pubsub.ConnectMessage)1 DispatchMessage (com.corundumstudio.socketio.store.pubsub.DispatchMessage)1 NamespaceClient (com.corundumstudio.socketio.transport.NamespaceClient)1 ByteBuf (io.netty.buffer.ByteBuf)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1