By reading this article, you can understand the access process of implementing the
interaction mode between teachers and students.
Teacher end
- Set the channel mode to interactive mode before teachers join the channel.
[self.engine setChannelProfile:AliRtcChannelProfileInteractivelive];
- Set to non-automatic publishing and automatic subscription mode before teachers join
the channel.
[self.engine setAutoPublish:NO withAutoSubscribe:YES];
- 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.
- 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.
}
}];
- 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.
- 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;
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:
- Start feeding wheat.
- If ordinary viewers need to switch to Lianmai audience, they need to switch user roles
first.
- 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;
- 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) {
}];
- 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.
- Stops ingesting streams.
[self.engine configLocalAudioPublish:NO];
[self.engine configLocalCameraPublish:NO];
[self.engine publish:^(int err) {
}];
- After you stop stream ingest and receive a callback, you can switch to a normal audience
role.
[self.engine setClientRole:AliRtcClientRolelive];
- You can receive a callback after the switchover is successful.
- (void)onUpdateRoleNotifyWithOldRole:(AliRtcClientRole)oldRole newRole:(AliRtcClientRole)newRole;