HMSUpdateListener

PROTOCOL

@objc public protocol HMSUpdateListener: AnyObject

100ms SDK provides callbacks to the client app about any change or update happening in the room after a user has joined by implementing HMSUpdateListener. These updates can be used to render the video on screen or to display other info regarding the room.

Methods

on(join:)

@objc(onJoin:) func on(join room: HMSRoom)

This will be called on a successful JOIN of the room by the user This is the point where applications can stop showing its loading state

  • Parameter room: the room which was joined

Parameters

NameDescription
roomthe room which was joined

on(room:update:)

@objc(onRoom:update:) func on(room: HMSRoom, update: HMSRoomUpdate)

This is called when there is a change in any property of the Room

  • Parameters:
    • room: the room which was joined
    • update: the triggered update type. Should be used to perform different UI Actions

Parameters

NameDescription
roomthe room which was joined
updatethe triggered update type. Should be used to perform different UI Actions

on(peer:update:)

@objc(onPeer:update:) func on(peer: HMSPeer, update: HMSPeerUpdate)

This will be called whenever there is an update on an existing peer or a new peer got added/existing peer is removed. This callback can be used to keep a track of all the peers in the room

  • Parameters:
    • peer: the peer who joined/left or was updated
    • update: the triggered update type. Should be used to perform different UI Actions

Parameters

NameDescription
peerthe peer who joined/left or was updated
updatethe triggered update type. Should be used to perform different UI Actions

on(track:update:for:)

@objc(onTrack:update:peer:) func on(track: HMSTrack, update: HMSTrackUpdate, for peer: HMSPeer)

This is called when there are updates on an existing track or a new track got added/existing track is removed This callback can be used to render the video on screen whenever a track gets added

  • Parameters:
    • track: the track which was added, removed or updated
    • update: the triggered update type
    • peer: the peer for which track was added, removed or updated

Parameters

NameDescription
trackthe track which was added, removed or updated
updatethe triggered update type
peerthe peer for which track was added, removed or updated

on(error:)

@objc(onError:) func on(error: HMSError)

This will be called when there is an error in the system and SDK has already retried to fix the error

  • Parameter error: the error that occured

Parameters

NameDescription
errorthe error that occured

on(message:)

@objc(onMessage:) func on(message: HMSMessage)

This is called when there is a new broadcast message from any other peer in the room This can be used to implement chat is the room

  • Parameter message: the received broadcast message

Parameters

NameDescription
messagethe received broadcast message

on(roleChangeRequest:)

@objc(roleChangeRequest:) optional func on(roleChangeRequest: HMSRoleChangeRequest)

This is called when a role change request arrives

  • Parameter roleChangeRequest: the request for role change info

Parameters

NameDescription
roleChangeRequestthe request for role change info

on(changeTrackStateRequest:)

@objc(changeTrackStateRequest:) optional func on(changeTrackStateRequest: HMSChangeTrackStateRequest)

This is called when a change track state request arrives

  • Parameter changeTrackStateRequest: the request for changing track state

Parameters

NameDescription
changeTrackStateRequestthe request for changing track state

on(removedFromRoom:)

@objc(removedFromRoom:) optional func on(removedFromRoom notification: HMSRemovedFromRoomNotification)

This is called when someone removes the local peer for the current room

  • Parameter notification: the notification containing reason for removing and the initiating peer

Parameters

NameDescription
notificationthe notification containing reason for removing and the initiating peer

on(updated:)

@objc(onUpdatedSpeakers:) func on(updated speakers: [HMSSpeaker])

This is called every 1 second with list of active speakers

A HMSSpeaker object contains -

  • peer: the peer who is speaking
  • track: the track which is emitting audio
  • level: a number within range 1-100 indicating the audio volume A peer who is not present in the list indicates that the peer is not speaking This can be used to highlight currently speaking peers in the room
  • Parameter speakers: the list of speakers

Parameters

NameDescription
speakersthe list of speakers

onReconnecting()

@objc func onReconnecting()

This is called when SDK detects a network issue and is trying to recover

onReconnected()

@objc func onReconnected()

This is called when SDK successfully recovered from a network issue a network issue