How to remove a specific user from a channel?
In real-time audio and video interactions, there are often cases where you need to remove a specific user from the channel. Agora offers several solutions tailored to different scenarios:
Remove inactive users
Scenario: After a call, a user (typically on the web) forgets to leave the channel. Even without an active call, usage is still generated.
Solution: To avoid this, check if the user is publishing an audio stream over time, using the volume indication callback (onAudioVolumeIndication
) or monitor at the app level. If the user is inactive, call leaveChannel
in the app logic to log off the user.
Remove all users
Scenario: Scheduling apps may need to end calls or meetings at a set time. For example, a one hour meeting starts at 10:00 a.m. and needs to end at 11:00 a.m.
Solution: Use one of the following approaches:
-
Set the valid timestamp of the Token (
privilegeExpiredTs
parameter) to the meeting's end time. After this time, the user is automatically removed from the channel. For details, see Secure authentication with tokens. -
Use the server-side RESTful API to remove users. Track the user ID and channel name in the app, then call the Create Rule API to remove the user from the channel. Set the ban time (
time
parameter) to 0 to allow the user to join other channels afterwards.
Remove a user who violates your policies
Scenario: In a live broadcast room, if a connected user makes inappropriate remarks, the host may want to remove the user.
Solution: Use the peer-to-peer messaging function of Signaling. Send an offline notification with sendMessageToPeer
. The user receives this message through the onMessageReceived
callback, and the client calls the leaveChannel
method in the Video SDK to leave the channel.