Raise Hand using PubSub - iOS
Let us see, how we can use PubSub to implement Raise Hand functionality. If you are not familiar with the PubSub mechanism and pubSub
class, you can follow this guide.
Implementing Raise Hand
- First step in raise hand is choosing the topic which all the participants will publish and subscribe to know some participant raise their hand. We will be using
RAISE_HAND
as the topic for this one. - On the raiseHand button, publish any message to that specific topic.
- Swift
class MeetingViewController {
//Button that will send the Raise Hand message when tapped
@IBAction func raiseHandTapped(_ sender: Any) {
// publish message
self.meeting?.pubsub.publish(topic: "RAISE_HAND", message: "raise hand")
}
}
- Now let us show an alert to all the participants showing who raised the hand.
- Swift
extension MeetingViewController: MeetingEventListener {
func onMeetingJoined() {
//subscribe to the topic 'CHAT' when onMeetingJoined is triggered
meeting?.pubsub.subscribe(topic: "RAISE_HAND", forListener: self)
}
}
extension MeetingViewController: 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