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_HANDas the topic for this one. - On the raiseHand button, publish any message to that specific topic.
- Swift
extension MeetingViewController: MeetingEventListener {
func onMeetingJoined() {
//...
Task {
await meeting?.pubsub.subscribe(topic: "RAISE_HAND", forListener: self)
}
//...
}
}
extension MeetingViewController: PubSubMessageListener {
func onMessageReceived(_ message: PubSubMessage) {
//...
if (message.topic == "RAISE_HAND") {
//...
print("Message Received:= " + message.message)
}
}
}
- Now let us show an alert to all the participants showing who raised the hand.
- Swift
extension MeetingViewController: MeetingEventListener {
/// Meeting started
func onMeetingJoined() {
//...
Task {
await meeting?.pubsub.subscribe(topic: "RAISE_HAND", forListener: self)
}
}
}
extension MeetingViewController: PubSubMessageListener {
func onMessageReceived(_ message: PubSubMessage) {
print("Message Received:= " + message.message)
let localParticipantID = participants.first(where: { $0.isLocal == true })?.id
if(message.topic == RAISE_HAND_TOPIC){
self.showToast(message: "\(message.senderId == localParticipantID ? "You" : "\(message.senderName)") raised hand 🖐🏼", font: .systemFont(ofSize: 18))
}
}
}
extension UIViewController {
func showToast(message: String, font: UIFont) {
let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2, y: self.view.frame.size.height, width: 250, height: 50))
toastLabel.font = font
toastLabel.textAlignment = .center;
toastLabel.text = message
self.view.addSubview(toastLabel)
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
toastLabel.removeFromSuperview()
}
}
}
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

