Windows
This topic describes the basic features of DingRTC, which include initializing the software development kit (SDK), joining a channel, publishing local streams, subscribing to remote streams, and leaving a channel.
Prerequisites
You have downloaded and integrated the latest version of the SDK. For more information, see How to integrate the Real-Time Communication SDK for Windows.
You have obtained the channel authentication token required to join a channel. For more information, see Use a token for authentication.
Procedure
Initialize the SDK.
Create an RtcEngine instance and register callbacks. For more information about callback interfaces, see Callbacks and listeners.
engine_ = ding::rtc::RtcEngine::Create(""); // do not pass NULL pointer! // MyEngineEventListerner implements RtcEngineEventListener listener_ = new MyEngineEventListerner(); engine_->SetEngineEventListener((ding::rtc::RtcEngineEventListener *)listener_);Preview the local video. After you create the RtcEngine instance, you can set up a canvas layout to preview the local video stream.
HWND local_view = GetDlgItem(IDC_STATIC_LOCAL)->m_hWnd; ding::rtc::RtcEngineVideoCanvas canvas; canvas.displayView = local_view; canvas.mirrorMode = ding::rtc::RtcEngineRenderMirrorModeAllMirror; canvas.renderMode = ding::rtc::RtcEngineRenderMode::RtcEngineRenderModeCrop; engine_->SetLocalViewConfig(canvas, ding::rtc::RtcEngineVideoTrackCamera); engine_->StartPreview();Optional: Stop the local video preview.
engine_->stopPreview();Set publishing and subscription preferences.
The SDK does not automatically publish streams when a user joins a channel. To publish streams immediately after joining, add the following code to your application:
class MyEngineEventListerner : public ding::rtc::RtcEngineEventListener { public: .. void OnJoinChannelResult(int result, const char *channel, const char *userId, int elapsed) override { // Do not call SDK APIs in the SDK message callback. UpdateMeetingInfoParam *param = new UpdateMeetingInfoParam; param->in_room = true; main_wnd_->UpdateUIAsync(param); } .. };By default, the SDK automatically subscribes to remote audio and video streams after a user joins a channel. To disable automatic subscription, call the following methods before the user joins the channel:
// Set automatic stream pulling and video definition. // Configure these values as needed. bool auto_sub_audio_ = true; bool auto_sub_video_ = true; ding::rtc::RtcEngineVideoStreamType prefer_video_quality_ = ding::rtc::RtcEngineVideoStreamType::RtcEngineVideoStreamTypeFHD; engine_->SubscribeAllRemoteAudioStreams(auto_sub_audio_); engine_->SubscribeAllRemoteVideoStreams(auto_sub_video_); engine_->SetRemoteDefaultVideoStreamType(prefer_video_quality_);
Join a channel.
ding::rtc::RtcEngineAuthInfo auth; auth.channelId = /* Channel ID */; auth.appId = /* Application ID */; auth.token = /* Channel authentication token */; auth.userId = /* User ID */; auth.gslbServer = /* GSLB address. This is optional. */; engine_->JoinChannel(auth, nick /* Display name */);Parameter
Description
appId
The application ID. Create and view it on the Application Management page in the console.
channelId
The channel ID. It must be 1 to 64 characters in length and can contain uppercase letters, lowercase letters, digits, underscores (_), and hyphens (-).
userId
The user ID. It must be 1 to 64 characters in length and can contain uppercase letters, lowercase letters, digits, underscores (_), and hyphens (-).
NoteIf the same user ID logs on from another client, the client that joined the channel first is kicked out of the channel by the client that joined later.
token
The channel authentication token.
gslbServer
The service endpoint. This parameter can be empty. The default value is
"https://gslb.dingrtc.com". Send this address from your business server to the client SDK. Do not hardcode the address in the client code.Important: Do not pass an empty value. Use the GSLB address that is returned from your business server (AppServer).
Publish or unpublish a local stream.
After joining a channel, you can change the publishing status.
Publish local audio and video streams
If no stream is being published, you can call the following methods to publish the audio or video stream:
engine_->PublishLocalVideoStream(true); engine_->PublishLocalAudioStream(true);Or, to unpublish the stream:
engine_->PublishLocalVideoStream(false); engine_->PublishLocalAudioStream(false);Audio and video can be controlled independently.
Publish a low-bitrate stream
The latest SDK supports low-bitrate streams. It uses simulcast to provide four quality levels: Full High Definition (FHD) (1080p or higher), High Definition (HD) (720p or higher), Standard Definition (SD) (480p or higher), and Low Definition (LD) (lower than 480p). For example, if you publish an FHD stream, the SDK automatically adds streams with lower resolutions. A maximum of two lower-resolution layers can be added. This feature is enabled automatically in your application and requires no additional code.
Subscribe to or unsubscribe from a remote stream.
Subscribe to remote audio and video streams
If you have not configured stream subscription settings before joining the channel, the SDK automatically subscribes to remote audio and video streams after the user joins. If you disabled automatic subscription before joining the channel, you can call the following methods to subscribe manually:
// // For bulk operations: subscribe to all or unsubscribe from all // // Audio engine_->SubscribeAllRemoteAudioStreams(true); // false indicates unsubscribe // Video engine_->SubscribeAllRemoteVideoStreams(true); engine_->SetRemoteDefaultVideoStreamType(prefer_video_quality_); // Set the maximum quality for stream pulling // // For individual operations // // Audio // The SDK does not currently support individual audio stream subscriptions // Video engine_->SubscribeRemoteVideoStream(remoteUid, ding::rtc::RtcEngineVideoTrack::RtcEngineVideoTrackCamera, true); // false indicates unsubscribe engine_->SetRemoteVideoStreamType(remoteUid, type); // type: RtcEngineVideoStreamTypeFHD, RtcEngineVideoStreamTypeHD // RtcEngineVideoStreamTypeSD, RtcEngineVideoStreamTypeLD // Indicates the desired maximum subscription specification. The actual stream is also limited by the network quality of the subscriber.To subscribe to a video stream, you must also set a window to display its content. We recommend setting the window when the OnRemoteTrackAvailableNotify message is received. You can also set it earlier or later.
HWND remote_view = GetDlgItem(IDC_STATIC_REMOTE)->m_hWnd; ding::rtc::RtcEngineVideoCanvas canvas; canvas.displayView = remote_view; canvas.mirrorMode = ding::rtc::RtcEngineRenderMirrorModeAllMirror; canvas.renderMode = ding::rtc::RtcEngineRenderMode::RtcEngineRenderModeCrop; engine_->SetRemoteViewConfig(canvas, p->uid.c_str(), ding::rtc::RtcEngineVideoTrackCamera);
Leave the channel.
engine_->LeaveChannel();Destroy the RtcEngine instance.
if(engine_ != NULL) {
ding::rtc::RtcEngine::Destroy(engine_);
engine_ = NULL;
}
if(listener_ != NULL) {
delete listener_;
listener_ = NULL;
}What to do next
You can download the sample code and run the demo to quickly implement real-time audio and video calls within a channel. For more information, see Run the Windows demo.