Windows

更新时间:
复制 MD 格式

This topic describes how to use Real-Time Communication (RTC) SDK to host an interactive class between a teacher and students.

Teacher side

  1. Before a teacher joins the channel, call SetChannelProfile to set the channel mode to interactive.
    pEngine->setChannelProfile(AliRtcChannelProfileInteractiveLive);
  2. Before the teacher joins the channel, call SetClientRole to set the role to interactive.
    pEngine->setClientRole(AliRtcClientRoleInteractive);
    Note You can also set the role after joining a channel. If the role changes, the OnUpdateRoleNotify callback is triggered after the role is successfully set.
  3. Before the teacher joins the channel, set the client to subscribe to audio and video streams by default.
    // Configure default subscription to audio streams. Enable as needed.
    pEngine->SetDefaultSubscribeAllRemoteAudioStreams(true);
    // Configure default subscription to video streams. Enable as needed.
    pEngine->SetDefaultSubscribeAllRemoteVideoStreams(true);
  4. Call JoinChannel to join the channel.
    pEngine->joinChannel(aliRtcAuthInfo, userName);
  5. Start publishing streams.
    // Configure to publish the audio stream. Enable as needed.
    pEngine->PublishLocalAudioStream(true);
    // Configure to publish the camera stream. Enable as needed.
    pEngine->PublishLocalVideoStream(true);
    // Configure to publish the screen stream. Enable as needed.
    pEngine->StartScreenShareByDesktopId(desktopId, config);
    NameTypeDescription
    desktopIdunsigned intThe desktop ID. Obtain it by calling the GetScreenShareSourceInfo interface.
    configconst AliEngineScreenShareConfig &Screen sharing configuration.
  6. After you publish the stream, use the callback to verify that the audio stream was published successfully.
    void OnAudioPublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
    NameTypeDescription
    oldStateAliEnginePublishStateThe previous publishing state.
    newStateAliEnginePublishStateThe current publishing state.
    elapseSinceLastStateintThe time interval since the last state change.
    channelconst char *The current channel ID.
  7. After you publish the stream, use the callback to verify that the video stream was published successfully.
    void OnVideoPublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
    NameTypeDescription
    oldStateAliEnginePublishStateThe previous publishing state.
    newStateAliEnginePublishStateThe current publishing state.
    elapseSinceLastStateintThe time interval since the last state change.
    channelconst char *The current channel ID.
  8. After you publish the stream, use the callback to verify that the screen sharing stream was published successfully.
    void OnScreenSharePublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
    NameTypeDescription
    oldStateAliEnginePublishStateThe previous publishing state.
    newStateAliEnginePublishStateThe current publishing state.
    elapseSinceLastStateintThe time interval since the last state change.
    channelconst char *The current channel ID.
  9. Receive a callback when a remote user starts or stops publishing a stream. (The student client receives the same callback as the teacher client).
    /**
     * @brief This message is returned when a remote user's stream changes.
     * @param uid         The user ID. A unique identifier assigned by the app server.
     * @param audioTrack         The audio stream type. For more information, see AliRtcAudioTrack.
     * @param videoTrack         The video stream type. For more information, see AliRtcVideoTrack.
     * @note This message is also sent when a remote user stops publishing a stream.
     */
    virtual void onRemoteTrackAvailableNotify(const AliRtc::String & uid,
                                              AliRtcAudioTrack audioTrack,
                                              AliRtcVideoTrack videoTrack)
    Note
    • If `audioTrack` is `AliRtcAudioTrackNo` and `videoTrack` is `AliRtcVideoTrackNo`, the remote user has stopped publishing streams. Otherwise, the values indicate the publishing status of the remote user's stream.
    • You can also set the role after joining the channel. You will receive a callback after the role is successfully set.
        void onUpdateRoleNotify(const AliRtcClientRole old_role, const AliRtcClientRole new_role)
    • Note the current value of the role parameter. For example, if the current role is `AliRtcClientRoleInteractive`, calling the interface again with the same value does not trigger a callback.
      pEngine->setClientRole(AliRtcClientRoleInteractive);
    • Separate the logic for switching roles from the logic for publishing and subscribing to streams.

Student side

  1. Before a student joins the channel, call SetChannelProfile to set the channel mode to interactive.
    pEngine->setChannelProfile(AliRtcChannelProfileInteractiveLive);
    Note
    • Regular viewer: After you set the mode to interactive, the default role is viewer. A user with the viewer role can only subscribe to and watch the live stream, but cannot publish streams. This role is suitable for regular viewers and requires no other operations.
    • Interactive viewer: A user with the interactive participant role can publish streams. For more information, see the Go on-mic section below.
  2. Call JoinChannel to join the channel.
    pEngine->JoinChannel(aliRtcAuthInfo, userName);
  3. Go on-mic. (A regular viewer must first switch their user role to go on-mic.)
    1. Switch the role to `AliRtcClientRoleInteractive`. (You must do this before you call the publish interface to publish a stream.)
      pEngine->setClientRole(AliRtcClientRoleInteractive);
    2. After the role is switched successfully, you will receive a callback.
      void onUpdateRoleNotify(const AliRtcClientRole old_role, const AliRtcClientRole new_role) {};
    3. After you receive the callback, start publishing streams.
      // Configure to publish the audio stream. Enable as needed.
      pEngine->PublishLocalAudioStream(true);
      // Configure to publish the camera stream. Enable as needed.
      pEngine->PublishLocalVideoStream(true);
    4. After you publish the stream, use the callback to verify that the audio stream was published successfully.
      void OnAudioPublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
      NameTypeDescription
      oldStateAliEnginePublishStateThe previous publishing state.
      newStateAliEnginePublishStateThe current publishing state.
      elapseSinceLastStateintThe time interval since the last state change.
      channelconst char *The current channel ID.
    5. After you publish the stream, use the callback to verify that the video stream was published successfully.
      void OnVideoPublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
      NameTypeDescription
      oldStateAliEnginePublishStateThe previous publishing state.
      newStateAliEnginePublishStateThe current publishing state.
      elapseSinceLastStateintThe time interval since the last state change.
      channelconst char *The current channel ID.
    6. After you publish the stream, use the callback to verify that the screen sharing stream was published successfully.
      void OnScreenSharePublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
      NameTypeDescription
      oldStateAliEnginePublishStateThe previous publishing state.
      newStateAliEnginePublishStateThe current publishing state.
      elapseSinceLastStateintThe time interval since the last state change.
      channelconst char *The current channel ID.
  4. Go off-mic. This is the reverse of going on-mic. To become a regular viewer, an interactive viewer must first stop publishing streams and then switch their role.
    1. Stop publishing streams.
      // Configure to unpublish the audio stream. Disable as needed.
      pEngine->PublishLocalAudioStream(false);
      // Configure to unpublish the camera stream. Disable as needed.
      pEngine->PublishLocalVideoStream(false);
    2. After you stop publishing the stream, use the callback to verify that the audio stream was unpublished successfully.
      void OnAudioPublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
      NameTypeDescription
      oldStateAliEnginePublishStateThe previous publishing state.
      newStateAliEnginePublishStateThe current publishing state.
      elapseSinceLastStateintThe time interval since the last state change.
      channelconst char *The current channel ID.
    3. After you stop publishing the stream, use the callback to verify that the video stream was unpublished successfully.
      void OnVideoPublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
      NameTypeDescription
      oldStateAliEnginePublishStateThe previous publishing state.
      newStateAliEnginePublishStateThe current publishing state.
      elapseSinceLastStateintThe time interval since the last state change.
      channelconst char *The current channel ID.
    4. After you stop publishing the stream, use the callback to verify that screen sharing was unpublished successfully.
      void OnScreenSharePublishStateChanged(AliEnginePublishState oldState, AliEnginePublishState newState, int elapseSinceLastState, const char *channel);
      NameTypeDescription
      oldStateAliEnginePublishStateThe previous publishing state.
      newStateAliEnginePublishStateThe current publishing state.
      elapseSinceLastStateintThe time interval since the last state change.
      channelconst char *The current channel ID.
    5. After you stop publishing the stream, switch the role to a regular viewer.
      pEngine->setClientRole(AliRtcClientRoleLive);
    6. After the role is switched successfully, you will receive a callback. You can then continue to subscribe to and watch streams.
      void onUpdateRoleNotify(const AliRtcClientRole old_role, const AliRtcClientRole new_role)