By reading this article, you can understand the access process of implementing the interaction mode between teachers and students.

Teacher end

  1. Set the channel mode to interactive mode before teachers join the channel.
    [self.engine setChannelProfile:AliRtcChannelProfileInteractivelive];
  2. Set to non-automatic publishing and automatic subscription mode before teachers join the channel.
    [self.engine setAutoPublish:NO withAutoSubscribe:YES];
  3. Set the role to AliRtcClientRoleInteractive before the teacher joins the channel.
    [self.engine setClientRole:AliRtcClientRoleInteractive];
    Valid values of the AliRtcClientRole parameter:
    • AliRtcClientRoleInteractive: participates in an interactive role and can push and pull streams.
    • AliRtcClientRolelive: Only watch characters, only pull streams, suitable for ordinary audiences.
    Note Do not process the return value of the setClientRole interface.
  4. Join the channel.
    [self.engine joinChannel:authInfo name:name onResult:^(NSInteger errCode){
        if (errCode == 0) {
        // The channel is added.
        } else {
        // Failed to join the channel.
        }
    }];
  5. Call the publish operation to start publishing.
    [self.engine configLocalAudioPublish:YES];
    [self.engine configLocalCameraPublish:YES];
    [self.engine publish:^(int err) {
    
    }];
    Notice Before calling the publish interface, you must ensure that the channel has been added successfully. Otherwise, calling the publish interface will fail.
  6. Remote user ingest and stop ingest message callback (the callback for receiving remote user ingest messages is the same as that for the teacher.)
    /**
     * @brief This message is returned when the stream of the remote user changes.
     * @note If a remote user stops streaming, this message is also sent.
     */
    - (void)onRemoteTrackAvailableNotify:(NSString *)uid audioTrack:(AliRtcAudioTrack)audioTrack videoTrack:(AliRtcVideoTrack)videoTrack;
    Note
    • If the value of audioTrack is AliRtcAudioTrackNo and the value of videoTrack is AliRtcVideoTrackNo, the stream ingest status of the remote user is stopped. In other cases, the stream ingest status of the remote user is stopped.
    • After joining the channel, you can also set a role. After the setting is successful, you can receive a callback.
      - (void)onUpdateRoleNotifyWithOldRole:(AliRtcClientRole)oldRole newRole:(AliRtcClientRole)newRole;
    • The business side needs to pay attention to the current role parameter value. For example, if the current role is AliRtcClientRoleInteractive, no callback will be received if you call the following interface again. We recommend that the business side distinguish the logic between role switching and push-pull streams.
      [self.engine setClientRole:AliRtcClientRoleInteractive];

Student end

Set the channel mode to interactive mode before students join the channel.
[self.engine setChannelProfile:AliRtcInteractivelive];

Ordinary audience: After you set this parameter to interactive mode, the default role type is "Watch only". That is, you can only pull streams to watch live streams, but not push streams. This role is suitable for ordinary audiences and no other operations are required.

Lian Mai Audience: The role type is "Participating Interactive Role". You can ingest streams. The procedure is as follows:

  1. Start feeding wheat.
    1. If ordinary viewers need to switch to Lianmai audience, they need to switch user roles first.
    2. Switch the role to AliRtcClientRoleInteractive (before calling the publish operation to ingest streams).
      [self.engine setClientRole:AliRtcClientRoleInteractive];
      You can receive a callback after the switchover is successful.
      - (void)onUpdateRoleNotifyWithOldRole:(AliRtcClientRole)oldRole newRole:(AliRtcClientRole)newRole;
    3. After receiving the callback, call the publish operation to start stream ingest.
      [self.engine configLocalAudioPublish:YES];
      [self.engine configLocalCameraPublish:YES];
      [self.engine publish:^(int err) {
      }];
  2. Under the wheat.

    Contrary to the upper wheat logic, if the audience needs to switch to an ordinary audience, they need to stop streaming and then switch roles.

    1. Stops ingesting streams.
      [self.engine configLocalAudioPublish:NO];
      [self.engine configLocalCameraPublish:NO];
      [self.engine publish:^(int err) {
      }];
    2. After you stop stream ingest and receive a callback, you can switch to a normal audience role.
      [self.engine setClientRole:AliRtcClientRolelive];
    3. You can receive a callback after the switchover is successful.
      - (void)onUpdateRoleNotifyWithOldRole:(AliRtcClientRole)oldRole newRole:(AliRtcClientRole)newRole;