ZEGO Live
  • iOS
  • Android : Java
  • Introduction
  • Sample app
  • Getting started
  • Guides
    • Room
    • Co-host
    • Face beautify
    • Sound effects
    • Room related Server APIs
  • Error codes
  • Documentation
  • ZEGO Live
  • Guides
  • Co-host

Co-host

Last updated:2022-05-26 10:02

In a live room, participants can initiatively request to co-host or be invited to co-host by the host. This document describes how to implement co-hosting and co-host seat related features.




Prerequisites

  • Contact us to activate the ZEGO Live service.
  • Refer to the Getting started to create a room or join a room.

Make co-hosts

For a host to invite other participants to co-host, call the addCoHost method to send an invitation.

// userID is the ID of the participant you want to invite.
ZegoRoomManager.getInstance().userService.addCoHost(userID, new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the invitation.

   }
});

The invited participant will be notified through the callback onReceiveAddCoHostInvitation. To accept or decline the invite, call the respondCoHostInvitation method. Once the invite is accepted, call the takeSeat method to take a co-host seat.

ZegoRoomManager.getInstance().userService.setListener(new ZegoUserServiceListener() {
    @Override
    public void onReceiveAddCoHostInvitation() {
     // You can implement the callback handling logic here as needed, for example, set a pop-up prompt to notify invitees to accept or decline the invitation.

   }
});

// The invited participant can accept or decline the invitation. Here's an example of accepting the invitation. 
ZegoRoomManager.getInstance().userService.respondCoHostInvitation(true, new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the response.

    }
});

// When the co-host invitation was accepted, the invitee need to initiatively call this method to take a co-host seat.
ZegoRoomManager.getInstance().userService.takeSeat(new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the take a seat.

   }
});

After the invited participant has responded to the invitation, the host will receive the reply through the callback onReceiveAddCoHostRespond.

ZegoRoomManager.getInstance().userService.setListener(new ZegoUserServiceListener() {
    @Override
    public void onReceiveAddCoHostRespond(boolean accept){
     // Implement your handling logic here when receiving the reply.

   }
});

Once a participant takes a co-host seat and becomes a co-host, all participants in the room receive a notification through the callback onReceiveCoHostListUpdate.

ZegoRoomManager.getInstance().roomService.setListener(new ZegoRoomServiceListener() {
    @Override
    public void onReceiveCoHostListUpdate(OperationAction action){
     // Implement the handling logic based on the notification, for example, you can play the co-host's published streams.
    if (action.getType() == OperationActionType.TakeSeat) {
        // streamView view is a view for the local video preview.
        ZegoRoomManager.getInstance().deviceService.playVideoStream(action.getTargetID(), streamView);
    }
   }
});

Request to co-host

When a participant wants to request to co-host, call the requestToCoHost method.

ZegoRoomManager.getInstance().userService.requestToCoHost(new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the invitation.

   }
});

When a participant's co-host request is sent, the host will receive a notification through the callback onReceiveToCoHostRequest. To accept or decline the request, call the respondCoHostRequest method.

ZegoRoomManager.getInstance().userService.setListener(new ZegoUserServiceListener() {
    @Override
    public void onReceiveToCoHostRequest(String requestUserID) {
     // You can implement the callback handling logic here as needed, for example, set a pop-up prompt to notify the host to accept or decline the request.

   }
});

// The host can accept or decline the request. Here's an example of accepting the request. 
// userID refers to the ID of the participant who send the co-host request.
ZegoRoomManager.getInstance().userService.respondCoHostRequest(true, userID, new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the response.

    }
});

After the host has responded to the request, the participant will receive the reply through the callback onReceiveToCoHostRespond. Once the host accepted the request, the participant needs to call the takeSeat method to take a co-host seat.

ZegoRoomManager.getInstance().userService.setListener(new ZegoUserServiceListener() {
    @Override
    public void onReceiveToCoHostRespond() {
     // Implement your handling logic here when receiving the reply.

   }
});

// When the request is accepted, the participant needs to initiatively call this method to take a co-host seat. 
ZegoRoomManager.getInstance().userService.takeSeat(new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the take a seat.

   }
});

Once the participant takes a co-host seat and becomes a co-host, all participants in the room receive a notification through the callback onReceiveCoHostListUpdate.

ZegoRoomManager.getInstance().roomService.setListener(new ZegoRoomServiceListener() {
    @Override
    public void onReceiveCoHostListUpdate(OperationAction action){
     // Implement the handling logic based on the notification, for example, you can play the co-host's published streams.
    if (action.getType() == OperationActionType.TakeSeat) {
        // streamView view is a view for the local video preview.
        ZegoRoomManager.getInstance().deviceService.playVideoStream(action.getTargetID(), streamView);
    }
   }
});

For a participant to cancel the co-host request, call the cancelRequestToCoHost method.

ZegoRoomManager.getInstance().userService.cancelRequestToCoHost(new ZegoRoomCallback() {
   @Override
   public void onRoomCallback(int errorCode) {
   // Callback for the result of the cancel.

   }
});

When the co-host request is canceled, the host will receive a notification through the callback onReceiveCancelToCoHostRequest.

ZegoRoomManager.getInstance().userService.setListener(new ZegoUserServiceListener() {
    @Override
    public void onReceiveCancelToCoHostRequest(String requestUserID) {
    // Implement your handling logic as needed, for example, you can set up a operation to update the co-host request list. 

   }
});

Leave a co-host seat

For a co-host to end the co-hosting and become a participant again, call the leaveSeat method. And the SDK stops publishing streams simultaneously.

ZegoRoomManager.getInstance().userService.leaveSeat(new ZegoRoomCallback(){
   @Override
   public void onRoomCallback(int errorCode){
   // Callback for the result of leave a seat.
   }
});

For the host to end the co-hosting, remove a specified co-host from the co-host seat, call the removeUserFromSeat method.

// userID refers to the ID of the co-host that the host want to remove from the seat. 
ZegoRoomManager.getInstance().userService.removeUserFromSeat(userID, new ZegoRoomCallback(){
   @Override
   public void onRoomCallback(int errorCode){
   // Callback for the result of remove a user from the seat.
   }
});

When a co-host leaves the co-host seat successfully, all participants in the room receive a notification through the callback onReceiveCoHostListUpdate.

ZegoRoomManager.getInstance().roomService.setListener(new ZegoRoomServiceListener() {
    @Override
    public void onReceiveCoHostListUpdate(OperationAction action){
     // Implement the handling logic based on the notification, for example, you can set up a UI refresh operation.

   }
});

Mute/unmute a co-host

For the host to mute a specified co-host, call the muteUser method with userID.

And the muted co-host can only be unmuted by the host, to unmute the co-host, the host needs to call the muteUser method again.

// userID refers to the ID of the co-host that the host wants to mute. 
// To mute a co-host, set the parameter to [true]. To unmute the co-host, set the parameter to [false].
ZegoRoomManager.getInstance().userService.muteUser(true, userID, new ZegoRoomCallback(){
   @Override
   public void onRoomCallback(int errorCode){
   // Callback for the result of mute a user.
   }
});

When a specified co-host is muted by the hose, all participants in the room will receive a notification through the callback onReceiveCoHostListUpdate.

ZegoRoomManager.getInstance().roomService.setListener(new ZegoRoomServiceListener() {
    @Override
    public void onReceiveCoHostListUpdate(OperationAction action){
     // Implement the handling logic based on the notification, for example, you can set up a UI refresh operation.

   }
});
Page Directory