public class Channel extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Channel.OnClientConnectListener
Interface to listen for client connect events, when clients
join the specified channel.
|
static interface |
Channel.OnClientDisconnectListener
Interface to listen for client disconnect events, when clients
leave the specified channel.
|
static interface |
Channel.OnConnectListener
Interface to listen for connect events.
|
static interface |
Channel.OnDisconnectListener
Interface to listen for disconnect events.
|
static interface |
Channel.OnErrorListener
Interface to listen for error events.
|
static interface |
Channel.OnMessageListener
Interface to listen for user-defined event messages on the specified
channel.
|
static interface |
Channel.OnReadyListener
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnMessageListener(String event,
Channel.OnMessageListener onMessageListener)
Add a listener for messages on the specified channel.
|
void |
connect()
Connect to the specified channel.
|
void |
connect(Map<String,String> attributes,
Result<Client> result)
Connect to the specified channel.
|
void |
connect(Result<Client> result)
Connect to the specified channel.
|
void |
connect(Uri url,
Map<String,String> attributes,
Result<Client> result) |
void |
disconnect()
Disconnect from the specified channel.
|
void |
disconnect(Result<Client> result)
Disconnect from the specified channel.
|
Clients |
getClients()
Retrieve the clients subscribed to this channel.
|
String |
getId()
This channel's id.
|
Uri |
getUri()
This channel's uri.
|
boolean |
isConnected()
This only tracks websocket connection.
|
boolean |
isDebug()
Get whether debug is set.
|
boolean |
isSecurityMode()
Retrieve whether security mode was set or not
|
void |
publish(String event,
Object data)
Send a message to the host on this channel.
|
void |
publish(String event,
Object data,
byte[] payload)
Send a message and (binary) payload to the host on this channel.
|
void |
publish(String event,
Object data,
Client client)
Send a message to the specified client on this channel.
|
void |
publish(String event,
Object data,
Client client,
byte[] payload)
Send a message and (binary) payload to the specified client on this channel.
|
void |
publish(String event,
Object data,
List<Client> clients)
Send a message to the specified clients on this channel.
|
void |
publish(String event,
Object data,
List<Client> clients,
byte[] payload)
Send a message and (binary) payload to the specified client on this channel.
|
void |
publish(String event,
Object data,
String target)
Send a message on this channel.
|
void |
publish(String event,
Object data,
String target,
byte[] payload)
Send a message and (binary) payload on this channel.
|
void |
removeAllListeners()
Remove all listeners from this channel.
|
void |
removeOnMessageListener(String event,
Channel.OnMessageListener onMessageListener)
Remove the specified message listener subscribed to the event on this channel.
|
void |
removeOnMessageListeners()
Remove all message listeners on this channel.
|
void |
removeOnMessageListeners(String event)
Remove all message listeners subscribed to the given event on this channel.
|
void |
setConnectionTimeout(int timeout)
Sets the interval for checking the channel connection.
|
void |
setDebug(boolean debug)
Get whether debug is set.
|
void |
setOnClientConnectListener(Channel.OnClientConnectListener onClientConnectListener)
Set the listener for client connect (subscribe) events.
|
void |
setOnClientDisconnectListener(Channel.OnClientDisconnectListener onClientDisconnectListener)
Set the listener for client disconnect (unsubscribe) events.
|
void |
setOnConnectListener(Channel.OnConnectListener onConnectListener)
Set the listener for connect events.
|
void |
setOnDisconnectListener(Channel.OnDisconnectListener onDisconnectListener)
Set the listener for disconnect events.
|
void |
setOnErrorListener(Channel.OnErrorListener onErrorListener)
Set the listener for error events.
|
void |
setOnReadyListener(Channel.OnReadyListener onReadyListener)
Deprecated.
|
void |
setSecurityMode(boolean securityMode,
Result<Boolean> result)
Set security mode status to for web socket connection or rest API
|
String |
toString() |
public boolean isConnected()
public void connect()
public void connect(Result<Client> result)
result
- the callback to invoke with the result of the connect requestpublic void setSecurityMode(boolean securityMode, Result<Boolean> result)
securityMode
- security mode status to setresult
- result to return whether security mode was set or notpublic void connect(Map<String,String> attributes, Result<Client> result)
attributes
- option attributes to include in the connect requestresult
- the callback to invoke with the result of the connect requestpublic void disconnect()
public void disconnect(Result<Client> result)
result
- the callback to invoke with the result of the disconnect requestpublic void publish(String event, Object data)
event
- an application specified eventdata
- the data to be sentpublic void publish(String event, Object data, byte[] payload)
event
- an application specified eventdata
- the data to be sentpayload
- binary data to be sentpublic void publish(String event, Object data, String target)
event
- an application specified eventdata
- the data to be senttarget
- the target (host, all, broadcast, ...) of this messagepublic void publish(String event, Object data, String target, byte[] payload)
event
- an application specified eventdata
- the data to be senttarget
- the target (host, all, broadcast, ...) of this messagepayload
- binary data to be sentpublic void publish(String event, Object data, Client client)
event
- an application specified eventdata
- the data to be sentclient
- the client for this messagepublic void publish(String event, Object data, Client client, byte[] payload)
event
- an application specified eventdata
- the data to be sentclient
- the client for this messagepayload
- binary data to be sentpublic void publish(String event, Object data, List<Client> clients)
event
- an application specified eventdata
- the data to be sentclients
- the clients for this messagepublic void publish(String event, Object data, List<Client> clients, byte[] payload)
event
- an application specified eventdata
- the data to be sentclients
- the clients for this messagepayload
- binary data to be sentpublic void addOnMessageListener(String event, Channel.OnMessageListener onMessageListener)
event
- the event on this channel to subscribe toonMessageListener
- the message listener to invoke when a message is
received with the specified event on this channelpublic void removeOnMessageListeners(String event)
event
- the event for which all message listeners will be removedpublic void removeOnMessageListener(String event, Channel.OnMessageListener onMessageListener)
event
- the event on this channel to remove the message listener fromonMessageListener
- the message listener to removepublic void removeOnMessageListeners()
public void removeAllListeners()
public void setConnectionTimeout(int timeout)
timeout
- the timeout in millisecondspublic Uri getUri()
public String getId()
public Clients getClients()
public boolean isSecurityMode()
public void setOnConnectListener(Channel.OnConnectListener onConnectListener)
null
will remove the listener.public void setOnDisconnectListener(Channel.OnDisconnectListener onDisconnectListener)
null
will remove the listener.public void setOnClientConnectListener(Channel.OnClientConnectListener onClientConnectListener)
null
will remove the listener.public void setOnClientDisconnectListener(Channel.OnClientDisconnectListener onClientDisconnectListener)
null
will remove the listener.@Deprecated public void setOnReadyListener(Channel.OnReadyListener onReadyListener)
null
will remove the listener.public void setOnErrorListener(Channel.OnErrorListener onErrorListener)
null
will remove the listener.public void setDebug(boolean debug)
public boolean isDebug()