Raise Hand using PubSub - iOS
This guide shows how to use PubSub to implement Raise Hand. If you are not familiar with the PubSub mechanism and PubSub class, you can follow this guide.
Implementing Raise Hand
- The first step is choosing the topic that all participants publish and subscribe to, so they know when a participant raises their hand. We will use
RAISE_HANDas the topic. - On the raiseHand button, publish any message to that specific topic.
- Swift
extension RoomViewController {
//Button that will send the Raise Hand message when tapped
@IBAction func raiseHandTapped(_ sender: Any) {
// publish message
Task {
do {
try await self.room?.pubSub.publish(topic: "RAISE_HAND", message: "raise hand", options: PubSubPublishOptions(persist: true))
} catch {
print("publish error: \(error)")
}
}
}
}
- Now let us show an alert to all the participants showing who raised the hand.
- Swift
extension RoomViewController: RoomEventListener {
func onRoomJoined() {
//subscribe to the topic 'RAISE_HAND' when onRoomJoined is triggered
Task {
do {
try await room?.pubSub.subscribe(topic: "RAISE_HAND", listener: self)
} catch {
print("subscribe error: \(error)")
}
}
}
}
extension RoomViewController: PubSubMessageListener {
// read message when it is received
func onMessageReceived(_ message: PubSubMessage) {
print(message.senderName, "just Raised the hand")
}
}
API Reference
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord

