# Channel

    @objc open class Channel: NSObject

A Channel is a discreet connection where multiple clients can communicate

- `isConnected`

  The connection status of the channel

  #### Declaration

  Swift

      open fileprivate(set) var isConnected: Bool = false

- `uri`

  The uri of the channel (‘chat’)

  #### Declaration

  Swift

      open fileprivate(set) var uri: String! = nil

- `service`

  the service that is suplaying the channel connection

  #### Declaration

  Swift

      open fileprivate(set) var service : Service! = nil

- `me`

  The client that owns this channel instance

  #### Declaration

  Swift

      open var me: ChannelClient!

- `completionQueue`

  Undocumented

  #### Declaration

  Swift

      @objc open class Channel: NSObject

- `delegate`

  The delegate for handling channel events

  #### Declaration

  Swift

      weak open var delegate: ChannelDelegate? = nil

- `connectionTimeout`

  The timeout for channel transport connection. The connection will be closed if no ping is received within the defined timeout

  #### Declaration

  Swift

      open var connectionTimeout: TimeInterval = 5

- `connect()`

  Connects to the channel. This method will asynchronously call the delegate’s onConnect method and post a ChannelEvent.Connect notification upon completion. When a TV application connects to this channel, the onReady method/notification is also fired

  #### Declaration

  Swift

      open func connect()

- `connect(_:)`

  Connects to the channel. This method will asynchronously call the delegate’s onConnect method and post a ChannelEvent.Connect notification upon completion. When a TV application connects to this channel, the onReady method/notification is also fired

  #### Declaration

  Swift

      open func connect(_ attributes: [String:String]?)

  #### Parameters

  `attributes` | Any attributes you want to associate with the client (ie. [“name”:“FooBar”])

- `connect(_:completionHandler:)`

  Connects to the channel. This method will asynchronously call the delegate’s onConnect method and post a ChannelEvent.Connect notification upon completion. When a TV application connects to this channel, the onReady method/notification is also fired

  #### Declaration

  Swift

      open func connect(_ attributes: [String:String]?, completionHandler: ((_ client: ChannelClient?, _ error: NSError?) -> Void)?)

  #### Parameters

  `attributes` | Any attributes you want to associate with the client (ie. [“name”:“FooBar”])
  `completionHandler` | The callback handler

- `disconnect(_:)`

  Disconnects from the channel. This method will asynchronously call the delegate’s onDisconnect and post a ChannelEvent.Disconnect notification upon completion.

  - client: The client that is disconnecting which is yourself

  - error: An error info if disconnect fails

  #### Declaration

  Swift

      open func disconnect(_ completionHandler: ((_ client: ChannelClient?, _ error: NSError?) -> Void)?)

  #### Parameters

  `completionHandler` | The callback handler

- `disconnect()`

  Disconnects from the channel. This method will asynchronously call the delegate’s onDisconnect and post a ChannelEvent.Disconnect notification upon completion.

  #### Declaration

  Swift

      open func disconnect()

- `publish(event:message:)`

  Publish an event containing a text message payload

  #### Declaration

  Swift

      open func publish(event: String, message: AnyObject?)

  #### Parameters

  `event` | The event name
  `message` | A JSON serializable message object

- `publish(event:message:data:)`

  Publish an event containing a text message and binary payload

  #### Declaration

  Swift

      open func publish(event: String, message: AnyObject?, data: Data)

  #### Parameters

  `event` | The event name
  `message` | A JSON serializable message object
  `data` | Any binary data to send with the message

- `publish(event:message:target:)`

  Publish an event with text message payload to one or more targets

  #### Declaration

  Swift

      open func publish(event: String, message: AnyObject?, target: AnyObject)

  #### Parameters

  `event` | The event name
  `message` | A JSON serializable message object
  `target` | The target recipient(s) of the message.Can be a string client id, a collection of ids or a string MessageTarget (like MessageTarget.All.rawValue)

- `publish(event:message:data:target:)`

  Publish an event containing a text message and binary payload to one or more targets

  #### Declaration

  Swift

      open func publish(event: String, message: AnyObject?, data: Data, target: AnyObject )

  #### Parameters

  `event` | The event name
  `message` | A JSON serializable message object
  `data` | Any binary data to send with the message
  `target` | The target recipient(s) of the message.Can be a string client id, a collection of ids or a string MessageTarget (like MessageTarget.All.rawValue)

- `getClients()`

  A snapshot of the list of clients currently connected to the channel

  #### Declaration

  Swift

      open func getClients() -> [ChannelClient]

  #### Return Value

  list of clients currently connected to the channel

- `on(_:performClosure:)`

  A convenience method to subscribe for notifications using blocks.

  #### Declaration

  Swift

      open func on(_ notificationName: String, performClosure:@escaping (Notification!) -> Void) -> AnyObject?

  #### Parameters

  `notificationName` | The name of the notification.
  `performClosure` | The notification closure, which will be executed in the main thread. Make sure to control the ownership of a variables captured by the closure you provide in this parameter (e.g. use [unowned self] or [weak self] to make sure that self is released even if you did not unsubscribe from notification)

  #### Return Value

  An observer handler for removing/unsubscribing the block from notifications

- `off(_:)`

  A convenience method to unsubscribe from notifications

  #### Declaration

  Swift

      open func off(_ observer: AnyObject)

  #### Parameters

  `observer` | The observer object to unregister observations

- `description`

  The description of the client

  #### Declaration

  Swift

      open override var description: String

- `setSecurityMode(security:completionHandler:)`

  Undocumented

  #### Declaration

  Swift

      @objc open class Channel: NSObject