Package com.adobe.granite.socketio
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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description SocketIOEmitter
broadcast()
Sets a modifier for a subsequent event emission that the event will sent to all sockets except to itself.SocketIOSocket
disconnect(boolean close)
Disconnects this socket.SocketIOSocket
emit(java.lang.String eventName, SocketIOAckListener ackListener, java.lang.Object... arguments)
Emits an event to the socket identified by the string name.SocketIOSocket
emit(java.lang.String eventName, SocketIOAckListener ackListener, JSONArray arguments)
Emits an event to the socket identified by the string name.java.lang.String
getId()
A unique identifier for the socket session, that comes from the underlying Client.SocketIONamespace
getNamespace()
Client namespacejava.util.Set<java.lang.String>
getRooms()
A list of strings identifying the rooms this socket is in.java.security.Principal
getUserPrincipal()
SocketIOSocket
join(java.lang.String name)
Adds the socket to the room, and fires optionally a callback fn with err signature (if any).SocketIOSocket
leave(java.lang.String name)
Removes the socket from room, and fires optionally a callback fn with err signature (if any).SocketIOSocket
removeListener(SocketIOSocketListener listener)
Removes a listener from this socket.SocketIOSocket
setListener(SocketIOSocketListener listener)
Sets a listener to this socket that will receive the socket events.-
Methods inherited from interface com.adobe.granite.socketio.SocketIOEmitter
emit, emit, to
-
-
-
-
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 anSocketIOAckListener
that will be called after the client sent the ack response.- Parameters:
eventName
- name of the eventackListener
- the acknowledge listenerarguments
- 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 anSocketIOAckListener
that will be called after the client sent the ack response.- Parameters:
eventName
- name of the eventackListener
- the acknowledge listenerarguments
- optional arguments- Returns:
- this
- Throws:
java.io.IOException
- error
-
getUserPrincipal
java.security.Principal getUserPrincipal()
- Returns:
- the
Principal
of the current authenticated user.
-
-