Interface SocketIOSocket

  • All Superinterfaces:
    SocketIOEmitter

    @ProviderType
    public interface SocketIOSocket
    extends SocketIOEmitter
    A Socket is the fundamental class for interacting with browser clients. A Socket belongs to a certain Namespace (by default /) and uses an underlying Client to communicate.
    • Method Detail

      • setListener

        @Nonnull
        SocketIOSocket setListener​(@Nonnull
                                   SocketIOSocketListener listener)
        Sets a listener to this socket that will receive the socket events.
        Parameters:
        listener - the listener
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if this socket already has a listener
      • removeListener

        @Nonnull
        SocketIOSocket removeListener​(@Nonnull
                                      SocketIOSocketListener listener)
        Removes a listener from this socket. If this socket has no listener defined, this method has no effect.
        Parameters:
        listener - the listener
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if this socket already has a listener defined that is not the given one.
      • getId

        @Nonnull
        java.lang.String getId()
        A unique identifier for the socket session, that comes from the underlying Client.
        Returns:
        the id
      • getNamespace

        @Nonnull
        SocketIONamespace getNamespace()
        Client namespace
        Returns:
        - namespace
      • getRooms

        @Nonnull
        java.util.Set<java.lang.String> getRooms()
        A list of strings identifying the rooms this socket is in.
        Returns:
        set of rooms
      • disconnect

        @Nonnull
        SocketIOSocket disconnect​(boolean close)
        Disconnects this socket.
        Parameters:
        close - true to also close the underlying connection
        Returns:
        this
      • join

        @Nonnull
        SocketIOSocket join​(@Nonnull
                            java.lang.String name)
        Adds the socket to the room, and fires optionally a callback fn with err signature (if any). The socket is automatically a member of a room identified with its session id (see Socket#id). The mechanics of joining rooms are handled by the Adapter that has been configured (see Server#adapter above), defaulting to socket.io-adapter.
        Parameters:
        name - room name
        Returns:
        this
      • leave

        @Nonnull
        SocketIOSocket leave​(@Nonnull
                             java.lang.String name)
        Removes the socket from room, and fires optionally a callback fn with err signature (if any). Rooms are left automatically upon disconnection. The mechanics of leaving rooms are handled by the Adapter that has been configured (see Server#adapter above), defaulting to socket.io-adapter.
        Parameters:
        name - room name
        Returns:
        this
      • broadcast

        @Nonnull
        SocketIOEmitter broadcast()
        Sets a modifier for a subsequent event emission that the event will sent to all sockets except to itself.
        Returns:
        an emitter
      • emit

        @Nonnull
        SocketIOSocket emit​(@Nonnull
                            java.lang.String eventName,
                            @Nonnull
                            SocketIOAckListener ackListener,
                            @Nonnull
                            java.lang.Object... arguments)
                     throws java.io.IOException
        Emits an event to the socket identified by the string name. Any other parameters can be included. The called needs to specify an SocketIOAckListener that will be called after the client sent the ack response.
        Parameters:
        eventName - name of the event
        ackListener - the acknowledge listener
        arguments - optional arguments
        Returns:
        this
        Throws:
        java.io.IOException - error
      • emit

        @Nonnull
        SocketIOSocket emit​(@Nonnull
                            java.lang.String eventName,
                            @Nonnull
                            SocketIOAckListener ackListener,
                            @Nonnull
                            JSONArray arguments)
                     throws java.io.IOException
        Emits an event to the socket identified by the string name. Any other parameters can be included. The called needs to specify an SocketIOAckListener that will be called after the client sent the ack response.
        Parameters:
        eventName - name of the event
        ackListener - the acknowledge listener
        arguments - optional arguments
        Returns:
        this
        Throws:
        java.io.IOException - error
      • getUserPrincipal

        java.security.Principal getUserPrincipal()
        Returns:
        the Principal of the current authenticated user.