com.samsung.multiscreen

## Class Channel

- java.lang.Object
- - com.samsung.multiscreen.Channel

- Direct Known Subclasses:
    Application

      public class Channel
      extends Object

  Base communication channel for MultiScreen-enabled devices. Allows clients to connect, communicate, and publish (text and binary) messages over user-defined event channels.

- - ### Nested Class Summary

    Nested Classes
    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.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    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()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### isConnected

          public boolean isConnected()

      This only tracks websocket connection. It does NOT track the channel connection. If the channel (really the application host) is not connected, then there is effectively no receiver to process any messages sent over the websocket, unless the target is the service.
      Returns:
        true, if connected. false, otherwise.

    - #### connect

          public void connect()

      Connect to the specified channel.

    - #### connect

          public void connect(Result<Client> result)

      Connect to the specified channel.
      Parameters:
        `result` - the callback to invoke with the result of the connect request

    - #### setSecurityMode

          public void setSecurityMode(boolean securityMode,
                                      Result<Boolean> result)

      Set security mode status to for web socket connection or rest API
      Parameters:
        `securityMode` - security mode status to set
        `result` - result to return whether security mode was set or not

    - #### connect

          public void connect(Map<String,String> attributes,
                              Result<Client> result)

      Connect to the specified channel.
      Parameters:
        `attributes` - option attributes to include in the connect request
        `result` - the callback to invoke with the result of the connect request

    - #### connect

          public void connect(Uri url,
                              Map<String,String> attributes,
                              Result<Client> result)

    - #### disconnect

          public void disconnect()

      Disconnect from the specified channel.

    - #### disconnect

          public void disconnect(Result<Client> result)

      Disconnect from the specified channel.
      Parameters:
        `result` - the callback to invoke with the result of the disconnect request

    - #### publish

          public void publish(String event,
                              Object data)

      Send a message to the host on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent

    - #### publish

          public void publish(String event,
                              Object data,
                              byte[] payload)

      Send a message and (binary) payload to the host on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `payload` - binary data to be sent

    - #### publish

          public void publish(String event,
                              Object data,
                              String target)

      Send a message on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `target` - the target (host, all, broadcast, ...) of this message

    - #### publish

          public void publish(String event,
                              Object data,
                              String target,
                              byte[] payload)

      Send a message and (binary) payload on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `target` - the target (host, all, broadcast, ...) of this message
        `payload` - binary data to be sent

    - #### publish

          public void publish(String event,
                              Object data,
                              Client client)

      Send a message to the specified client on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `client` - the client for this message

    - #### publish

          public void publish(String event,
                              Object data,
                              Client client,
                              byte[] payload)

      Send a message and (binary) payload to the specified client on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `client` - the client for this message
        `payload` - binary data to be sent

    - #### publish

          public void publish(String event,
                              Object data,
                              List<Client> clients)

      Send a message to the specified clients on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `clients` - the clients for this message

    - #### publish

          public void publish(String event,
                              Object data,
                              List<Client> clients,
                              byte[] payload)

      Send a message and (binary) payload to the specified client on this channel.
      Parameters:
        `event` - an application specified event
        `data` - the data to be sent
        `clients` - the clients for this message
        `payload` - binary data to be sent

    - #### addOnMessageListener

          public void addOnMessageListener(String event,
                                           Channel.OnMessageListener onMessageListener)

      Add a listener for messages on the specified channel.
      Parameters:
        `event` - the event on this channel to subscribe to
        `onMessageListener` - the message listener to invoke when a message is received with the specified event on this channel

    - #### removeOnMessageListeners

          public void removeOnMessageListeners(String event)

      Remove all message listeners subscribed to the given event on this channel.
      Parameters:
        `event` - the event for which all message listeners will be removed

    - #### removeOnMessageListener

          public void removeOnMessageListener(String event,
                                              Channel.OnMessageListener onMessageListener)

      Remove the specified message listener subscribed to the event on this channel.
      Parameters:
        `event` - the event on this channel to remove the message listener from
        `onMessageListener` - the message listener to remove

    - #### removeOnMessageListeners

          public void removeOnMessageListeners()

      Remove all message listeners on this channel.

    - #### removeAllListeners

          public void removeAllListeners()

      Remove all listeners from this channel.

    - #### setConnectionTimeout

          public void setConnectionTimeout(int timeout)

      Sets the interval for checking the channel connection. If the channel is not connected, then connection checking will start after connection with a service. If the channel is already connected, then connection checking will start immediately. Set the timeout to 0 to disable connection checking.
      Parameters:
        `timeout` - the timeout in milliseconds

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getUri

          public Uri getUri()

      This channel's uri.

    - #### getId

          public String getId()

      This channel's id.

    - #### getClients

          public Clients getClients()

      Retrieve the clients subscribed to this channel.

    - #### isSecurityMode

          public boolean isSecurityMode()

      Retrieve whether security mode was set or not

    - #### setOnConnectListener

          public void setOnConnectListener(Channel.OnConnectListener onConnectListener)

      Set the listener for connect events. Setting the parameter to `null` will remove the listener.

    - #### setOnDisconnectListener

          public void setOnDisconnectListener(Channel.OnDisconnectListener onDisconnectListener)

      Set the listener for disconnect events. Setting the parameter to `null` will remove the listener.

    - #### setOnClientConnectListener

          public void setOnClientConnectListener(Channel.OnClientConnectListener onClientConnectListener)

      Set the listener for client connect (subscribe) events. Setting the parameter to `null` will remove the listener.

    - #### setOnClientDisconnectListener

          public void setOnClientDisconnectListener(Channel.OnClientDisconnectListener onClientDisconnectListener)

      Set the listener for client disconnect (unsubscribe) events. Setting the parameter to `null` will remove the listener.

    - #### setOnReadyListener

          @Deprecated
          public void setOnReadyListener(Channel.OnReadyListener onReadyListener)

      Deprecated.
      Set the listener for ready events (when the has subscribed to the channel and is "ready" to handle messages). Setting the parameter to `null` will remove the listener.

    - #### setOnErrorListener

          public void setOnErrorListener(Channel.OnErrorListener onErrorListener)

      Set the listener for error events. Setting the parameter to `null` will remove the listener.

    - #### setDebug

          public void setDebug(boolean debug)

      Get whether debug is set.

    - #### isDebug

          public boolean isDebug()

      Get whether debug is set.