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.
aliRtcEngine.setChannelProfile(AliRTCSDK_Channel_Profile.AliRTCSDK_Interactive_live);
- Set to non-automatic publishing and automatic subscription mode before teachers join
the channel.
aliRtcEngine.setAutoPublishSubscribe(false, true);
- Set the role to AliRTCSDK_Interactive before joining the channel.
aliRtcEngine.setClientRole(AliRTCSDK_Client_Role.AliRTCSDK_Interactive);
Valid values of the AliRTCSDK_Client_Role parameter:
- AliRTCSDK_Interactive: participates in an interactive role and can push and pull streams.
- AliRTCSDK_live: watches only characters and can only pull streams. It is suitable
for ordinary viewers.
Note Do not process the return value of the setClientRole interface.
- Join the channel.
aliRtcEngine.joinChannel(aliRtcAuthInfo, userName);
- Call the publish operation to start publishing.
// Configure the push audio stream. You can enable it as needed.
aliRtcEngine.configLocalAudioPublish(true);
// Configure the push camera stream, which can be enabled as required.
aliRtcEngine.configLocalCameraPublish(true);
// Configure the push screen stream, which can be enabled as required.
aliRtcEngine.configLocalScreenPublish(true);
// Start stream ingest. Note that publish is an asynchronous interface. After receiving the onPublishResult and the result is 0, the stream ingest is successful. For more information, see Set the corresponding callback for the setRtcEngineEventListener interface.
aliRtcEngine.publish();
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.)
/**
* This message is returned when the stream of the remote user changes
* @note If a remote user stops streaming, this message is also sent.
* @param uid User ID
* @param audioTrack Audio
* @param videoTrack Video
*/
void onRemoteTrackAvailableNotify(String uid, AliRtcAudioTrack audioTrack, 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 onUpdateRoleNotify(AliRtcEngine.AliRTCSDK_Client_Role oldRole,
AliRtcEngine.AliRTCSDK_Client_Role 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.
aliRtcEngine.setClientRole(AliRTCSDK_Client_Role.AliRTCSDK_Interactive);
Student end
Set the channel mode to interactive mode before students join the channel.
AliRtcEngine aliRtcEngine = AliRtcEngine.getInstance(getApplicationContext());
aliRtcEngine.setChannelProfile(AliRTCSDK_Channel_Profile.AliRTCSDK_Interactive_live);
Ordinary audience: After you set this parameter to the interactive mode, the default
role type is "Watch only role". 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 AliRTCSDK_Interactive (before calling the publish operation to
ingest streams).
aliRtcEngine.setClientRole(AliRTCSDK_Client_Role.AliRTCSDK_Interactive);
You can receive a callback after the switchover is successful.
/**
* Current role change notification. This callback is fired when a local user calls setClientRole to switch roles successfully after joining a channel
*
* @ param oldRole The role before the switch.
* @ param newRole The role after the switch.
* @ return None.
*/
void onUpdateRoleNotify(AliRtcEngine.AliRTCSDK_Client_Role oldRole, AliRtcEngine.AliRTCSDK_Client_Role newRole);
- After receiving the callback, call the publish operation to start stream ingest.
// Configure the push audio stream. You can enable it as needed.
aliRtcEngine.configLocalAudioPublish(true);
// Configure the push camera stream, which can be enabled as required.
aliRtcEngine.configLocalCameraPublish(true);
// Configure the push screen stream, which can be enabled as required.
aliRtcEngine.configLocalScreenPublish(true);
// Start stream ingest. Publish is an asynchronous interface. After receiving the onPublishResult and the result is 0, the stream ingest is successful. For more information, see Set the corresponding callback for the setRtcEngineEventListener interface.
aliRtcEngine.publish();
- 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.
// Configure the push audio stream and disable it as needed.
aliRtcEngine.configLocalAudioPublish(false);
// Configure the push camera stream and disable it as needed.
aliRtcEngine.configLocalCameraPublish(false);
// Configure the push screen stream and disable it as needed.
aliRtcEngine.configLocalScreenPublish(false);
// Start stream ingest. Publish is an asynchronous interface. After receiving the onPublishResult and the result is 0, the stream ingest is successful. For more information, see Set the corresponding callback for the setRtcEngineEventListener interface.
aliRtcEngine.publish();
- After you stop streaming and receive a callback, you can switch to the normal audience
mode.
aliRtcEngine.setClientRole(AliRTCSDK_Client_Role.AliRTCSDK_live);
- After the switchover is successful, you can receive the onUpdateRoleNotify callback
and continue to pull the stream to watch.