Watching a Channel

Last Edit: Nov 27 2020

Once you watch a channel, you will start receiving events for that channel. After watching the channel, you'll need to use a different function to get the updates. More info on that here.

To start watching a channel:


const state = await conversation.watch();
                    

final state = await channel.watch();
                    

channelController.watch().enqueue {
    val channel = it.data()
}
                    

let channel = Client.shared.channel(type: .messaging, id: "general")
channel.watch { (result) in
    // handle result
}
                    
When you watch a channel the API will ensure that the channel exists and create one if necessary and if the user is allowed to create such channel.

Response Schema

Name Type Description
config object The configuration for the channel type.
channel object The Channel object.
online integer Number of online members.
watchers object Users that are watching this channel. Represented as a mapping from the user id to the user object.
members object Channel members. Represented as a mapping from the user id to the user object.
read object Read messages grouped by user id. Represented as a mapping from the user id to the message object.
Watching a channel only works if you have a user set. Make sure to set a user before watching.

Unwatching

To stop watching a channel:


await state.stopWatching();
                    

await channel.stopWatching();
                    

channelController.stopWatching().enqueue {
    val channel = it.data()
}
                    

let channel = Client.shared.channel(type: .messaging, id: "general")
channel.stopWatching()
// or
channel.stopWatching { (result) in
    // handle result
}
                    

Watcher Count

To get the watcher count of a channel:


let channel = Client.shared.channel(type: .messaging, id: "general")
let subscription = channel.subscribeToWatcherCount { count in
    // handle count
}
// Cancel subscription when you want to stop receiving events
subscription.cancel()