Change User Name

Any peer can change their own name before or after joining a room. Before joining, the name would have to be specified in HMSConfig that is passed to the join method. This document shows how the name can be changed after joining.

Changing the name

The peer who wants to change their name should call the changeName method on HMSSDK instance with the new name.

try { const newName = 'new name'; await hmsInstance.changeName(newName); console.log('Change Name Success'); } catch (error) { console.log('Change Name Error: ', error); }

Responding to name changes

Once the name change is successful, all the peers receive HMSUpdateListenerActions.ON_PEER_UPDATE event with HMSPeerUpdate.NAME_CHANGED as update type. When this event is received, the UI for that peer should be updated.

const onPeerListener = ({ peer, type }: { peer: HMSPeer, type: HMSPeerUpdate }) => { if (type === HMSPeerUpdate.NAME_CHANGED) { // Name Changed for Peer console.log(`Update UI of ${peer.name}`); } }; hmsInstance.addEventListener(HMSUpdateListenerActions.ON_PEER_UPDATE, onPeerListener);

Have a suggestion? Recommend changes ->

Was this helpful?

1234