Skip to content

Advanced Channel Usage

Daniel Rhodes edited this page Mar 3, 2016 · 1 revision

When subscribing to a channel, there are various options in changing the behavior of that channel in regards to its offline behavior.

The easiest approach is simply:

let channel = self.client["RoomChannel"]
# or
let channel = self.client.create("RoomChannel")

In the default case, the channel will automatically subscribe itself if the client is connected and will resubscribe if the client disconnects and reconnects again.

channel["speak"](["message":"Hello"])

Additionally, the default behavior is that any actions sent to the channel while the client is offline/channel is unsubscribed will be buffered until a reconnect happens.

The benefits are that you can get going as quickly as possible and not think about connectivity issues. The downsides are that you are not going to know exactly what was sent and what was not.

To mitigate some of this, you can do the following:

let channel = self.client("RoomChannel", identifier: nil, autoSubscribe: true, bufferActions: false)

# later on in your code
if let error = channel.action("speak", params: ["message":"Hello"]) {
    # deal with error!
}

In this case, the channel will auto-subscribe, but not automatically resend messages that were sent when the channel was not subscribed/the client was offline.

Clone this wiki locally