diff --git a/shared/video-sdk/get-started/get-started-sdk/project-implementation/windows.mdx b/shared/video-sdk/get-started/get-started-sdk/project-implementation/windows.mdx index 2e695119e..c2a23215b 100644 --- a/shared/video-sdk/get-started/get-started-sdk/project-implementation/windows.mdx +++ b/shared/video-sdk/get-started/get-started-sdk/project-implementation/windows.mdx @@ -24,9 +24,7 @@ using namespace agora::media::base; // Define message IDs #define WM_MSGID(code) (WM_USER+0x200+code) -#define EID_ERROR 0x00000001 #define EID_JOIN_CHANNEL_SUCCESS 0x00000002 -#define EID_LEAVE_CHANNEL 0x00000003 #define EID_USER_JOINED 0x00000004 #define EID_USER_OFFLINE 0x00000004 @@ -62,24 +60,6 @@ public: } } - // Register onLeaveChannel callback - // Triggered when the local host successfully leaves the channel - virtual void onLeaveChannel(const RtcStats& stats) { - if (m_hMsgHanlder) { - ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_LEAVE_CHANNEL), 0, 0); - } - } - - // Register onError callback - // Triggered when an error occurs during SDK runtime - virtual void onError(int err, const char* msg) { - if (m_hMsgHanlder) { - char* message = new char[1024] {0}; - memcpy(message, msg, strlen(msg)); - ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_ERROR), (WPARAM)message, err); - } - } - private: HWND m_hMsgHanlder; }; @@ -103,8 +83,6 @@ public: afx_msg void OnBnClickedBtnLeave(); // Handling user joining/leaving channel callback events afx_msg LRESULT OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lParam); - afx_msg LRESULT OnEIDError(WPARAM wParam, LPARAM lParam); - afx_msg LRESULT OnEIDLeaveChannel(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnEIDUserJoined(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnEIDUserOffline(WPARAM wParam, LPARAM lParam); @@ -200,8 +178,6 @@ BEGIN_MESSAGE_MAP(CAgoraQuickStartDlg, CDialog) ON_BN_CLICKED(ID_BTN_JOIN, &CAgoraQuickStartDlg::OnBnClickedBtnJoin) ON_BN_CLICKED(ID_BTN_LEAVE, &CAgoraQuickStartDlg::OnBnClickedBtnLeave) ON_MESSAGE(WM_MSGID(EID_JOIN_CHANNEL_SUCCESS), CAgoraQuickStartDlg::OnEIDJoinChannelSuccess) - ON_MESSAGE(WM_MSGID(EID_ERROR), &CAgoraQuickStartDlg::OnEIDError) - ON_MESSAGE(WM_MSGID(EID_LEAVE_CHANNEL), CAgoraQuickStartDlg::OnEIDLeaveChannel) ON_MESSAGE(WM_MSGID(EID_USER_JOINED), &CAgoraQuickStartDlg::OnEIDUserJoined) ON_MESSAGE(WM_MSGID(EID_USER_OFFLINE), &CAgoraQuickStartDlg::OnEIDUserOffline) END_MESSAGE_MAP() @@ -286,6 +262,10 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { option.autoSubscribeAudio = true; // Automatically subscribe to video streams in the channel option.autoSubscribeVideo = true; + // Publish the microphone track + option.publishMicrophoneTrack = true; + // Publish the camera track + option.publishCameraTrack = true; // Join the channel with the temporary token obtained from the Agora Console int ret = m_rtcEngine->joinChannel(token, cs2utf8(strChannelName).c_str(), 0, option); // Render local view @@ -294,6 +274,8 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { canvas.uid = 0; canvas.view = m_staLocal.GetSafeHwnd(); m_rtcEngine->setupLocalVideo(canvas); + // Preview the local video + m_rtcEngine->startPreview(); } void CAgoraQuickStartDlg::OnBnClickedBtnLeave() { // Leave the channel @@ -303,16 +285,14 @@ void CAgoraQuickStartDlg::OnBnClickedBtnLeave() { canvas.uid = 0; m_rtcEngine->setupLocalVideo(canvas); m_remoteRender = false; + // Stop the preview + m_rtcEngine->startPreview(); } LRESULT CAgoraQuickStartDlg::OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lParam) { // Join channel success callback uid_t localUid = wParam; return 0; } -LRESULT CAgoraQuickStartDlg::OnEIDLeaveChannel(WPARAM wParam, LPARAM lParam) { - // Leave channel callback - return 0; -} LRESULT CAgoraQuickStartDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam) { // Remote user joined callback uid_t remoteUid = wParam; @@ -340,10 +320,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDUserOffline(WPARAM wParam, LPARAM lParam) { m_rtcEngine->setupRemoteVideo(canvas); m_remoteRender = false; return 0; -} -LRESULT CAgoraQuickStartDlg::OnEIDError(WPARAM wParam, LPARAM lParam) { - // Error callback - return 0; }`} @@ -412,8 +388,6 @@ BEGIN_MESSAGE_MAP(CAgoraQuickStartDlg, CDialog) ON_BN_CLICKED(ID_BTN_JOIN, &CAgoraQuickStartDlg::OnBnClickedBtnJoin) ON_BN_CLICKED(ID_BTN_LEAVE, &CAgoraQuickStartDlg::OnBnClickedBtnLeave) ON_MESSAGE(WM_MSGID(EID_JOIN_CHANNEL_SUCCESS), CAgoraQuickStartDlg::OnEIDJoinChannelSuccess) - ON_MESSAGE(WM_MSGID(EID_ERROR), &CAgoraQuickStartDlg::OnEIDError) - ON_MESSAGE(WM_MSGID(EID_LEAVE_CHANNEL), CAgoraQuickStartDlg::OnEIDLeaveChannel) ON_MESSAGE(WM_MSGID(EID_USER_JOINED), &CAgoraQuickStartDlg::OnEIDUserJoined) ON_MESSAGE(WM_MSGID(EID_USER_OFFLINE), &CAgoraQuickStartDlg::OnEIDUserOffline) END_MESSAGE_MAP() @@ -518,6 +492,8 @@ void CAgoraQuickStartDlg::OnBnClickedBtnLeave() { VideoCanvas canvas; canvas.uid = 0; m_rtcEngine->setupLocalVideo(canvas); + // Star the local video preview + m_rtcEngine->startPreview(); m_remoteRender = false; } LRESULT CAgoraQuickStartDlg::OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lParam) { @@ -525,10 +501,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lPara uid_t localUid = wParam; return 0; } -LRESULT CAgoraQuickStartDlg::OnEIDLeaveChannel(WPARAM wParam, LPARAM lParam) { - // Leave channel callback - return 0; -} LRESULT CAgoraQuickStartDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam) { // Remote user joined callback uid_t remoteUid = wParam; @@ -542,6 +514,8 @@ LRESULT CAgoraQuickStartDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam) { canvas.view = m_staRemote.GetSafeHwnd(); m_rtcEngine->setupRemoteVideo(canvas); m_remoteRender = true; + // Stop the local video preview + m_rtcEngine->stopPreview(); return 0; } LRESULT CAgoraQuickStartDlg::OnEIDUserOffline(WPARAM wParam, LPARAM lParam) { @@ -556,10 +530,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDUserOffline(WPARAM wParam, LPARAM lParam) { m_rtcEngine->setupRemoteVideo(canvas); m_remoteRender = false; return 0; -} -LRESULT CAgoraQuickStartDlg::OnEIDError(WPARAM wParam, LPARAM lParam) { - // Error callback - return 0; }`} @@ -628,8 +598,6 @@ BEGIN_MESSAGE_MAP(CAgoraQuickStartDlg, CDialog) ON_BN_CLICKED(ID_BTN_JOIN, &CAgoraQuickStartDlg::OnBnClickedBtnJoin) ON_BN_CLICKED(ID_BTN_LEAVE, &CAgoraQuickStartDlg::OnBnClickedBtnLeave) ON_MESSAGE(WM_MSGID(EID_JOIN_CHANNEL_SUCCESS), CAgoraQuickStartDlg::OnEIDJoinChannelSuccess) - ON_MESSAGE(WM_MSGID(EID_ERROR), &CAgoraQuickStartDlg::OnEIDError) - ON_MESSAGE(WM_MSGID(EID_LEAVE_CHANNEL), CAgoraQuickStartDlg::OnEIDLeaveChannel) ON_MESSAGE(WM_MSGID(EID_USER_JOINED), &CAgoraQuickStartDlg::OnEIDUserJoined) ON_MESSAGE(WM_MSGID(EID_USER_OFFLINE), &CAgoraQuickStartDlg::OnEIDUserOffline) END_MESSAGE_MAP() @@ -726,6 +694,8 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { canvas.uid = 0; canvas.view = m_staLocal.GetSafeHwnd(); m_rtcEngine->setupLocalVideo(canvas); + // Start the local video preview + m_rtcEngine->startPreview(); } void CAgoraQuickStartDlg::OnBnClickedBtnLeave() { // Leave the channel @@ -734,6 +704,8 @@ void CAgoraQuickStartDlg::OnBnClickedBtnLeave() { VideoCanvas canvas; canvas.uid = 0; m_rtcEngine->setupLocalVideo(canvas); + // Stop the local video preview + m_rtcEngine->stopPreview(); m_remoteRender = false; } LRESULT CAgoraQuickStartDlg::OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lParam) { @@ -741,10 +713,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lPara uid_t localUid = wParam; return 0; } -LRESULT CAgoraQuickStartDlg::OnEIDLeaveChannel(WPARAM wParam, LPARAM lParam) { - // Leave channel callback - return 0; -} LRESULT CAgoraQuickStartDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam) { // Remote user joined callback uid_t remoteUid = wParam; @@ -772,10 +740,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDUserOffline(WPARAM wParam, LPARAM lParam) { m_rtcEngine->setupRemoteVideo(canvas); m_remoteRender = false; return 0; -} -LRESULT CAgoraQuickStartDlg::OnEIDError(WPARAM wParam, LPARAM lParam) { - // Error callback - return 0; }`} @@ -857,8 +821,6 @@ BEGIN_MESSAGE_MAP(CAgoraQuickStartDlg, CDialog) ON_BN_CLICKED(ID_BTN_JOIN, &CAgoraQuickStartDlg::OnBnClickedBtnJoin) ON_BN_CLICKED(ID_BTN_LEAVE, &CAgoraQuickStartDlg::OnBnClickedBtnLeave) ON_MESSAGE(WM_MSGID(EID_JOIN_CHANNEL_SUCCESS), &CAgoraQuickStartDlg::OnEIDJoinChannelSuccess) - ON_MESSAGE(WM_MSGID(EID_ERROR), &CAgoraQuickStartDlg::OnEIDError) - ON_MESSAGE(WM_MSGID(EID_LEAVE_CHANNEL), &CAgoraQuickStartDlg::OnEIDLeaveChannel) ON_MESSAGE(WM_MSGID(EID_USER_JOINED), &CAgoraQuickStartDlg::OnEIDUserJoined) ON_MESSAGE(WM_MSGID(EID_USER_OFFLINE), &CAgoraQuickStartDlg::OnEIDUserOffline) END_MESSAGE_MAP() @@ -988,6 +950,8 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() option.clientRoleType = CLIENT_ROLE_BROADCASTER; // Auto subscribe to all audio streams in the channel option.autoSubscribeAudio = true; + // Publish the microphone track + option.publishMicrophoneTrack = true; // Fill in your temporary Token from the console to join the channel m_rtcEngine->joinChannel(token, cs2utf8(strChannelName).c_str(), 0, option); @@ -1006,11 +970,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDJoinChannelSuccess(WPARAM wParam, LPARAM lPara return 0; } -LRESULT CAgoraQuickStartDlg::OnEIDLeaveChannel(WPARAM wParam, LPARAM lParam) { - // Callback for leaving channel - return 0; -} - LRESULT CAgoraQuickStartDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam) { // Callback for remote user join uid_t remoteUid = wParam; @@ -1021,12 +980,6 @@ LRESULT CAgoraQuickStartDlg::OnEIDUserOffline(WPARAM wParam, LPARAM lParam) { // Callback for remote user leaving uid_t remoteUid = wParam; return 0; -} - - -LRESULT CAgoraQuickStartDlg::OnEIDError(WPARAM wParam, LPARAM lParam) { - // Error callback - return 0; }`} @@ -1069,7 +1022,7 @@ Add callbacks to receive notification of users joining and leaving the channel. class CAgoraQuickStartRtcEngineEventHandler : public IRtcEngineEventHandler { public: // Register onJoinChannelSuccess callback - // Triggered when the local user successfully joins the channel + // This callback is triggered when the local user successfully joins the channel virtual void onJoinChannelSuccess(const char* channel, uid_t uid, int elapsed) { if (m_hMsgHanlder) { ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_JOIN_CHANNEL_SUCCESS), uid, 0); @@ -1077,7 +1030,7 @@ public: } // Register onUserJoined callback - // Triggered when a remote user successfully joins the channel + // This callback is triggered when a remote broadcaster successfully joins the channel virtual void onUserJoined(uid_t uid, int elapsed) { if (m_hMsgHanlder) { ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_USER_JOINED), uid, 0); @@ -1085,31 +1038,13 @@ public: } // Register onUserOffline callback - // Triggered when a remote user leaves the channel or goes offline + // This callback is triggered when a remote broadcaster leaves the channel or goes offline virtual void onUserOffline(uid_t uid, USER_OFFLINE_REASON_TYPE reason) { if (m_hMsgHanlder) { ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_USER_OFFLINE), uid, 0); } } - // Register onLeaveChannel callback - // Triggered when the local user successfully leaves the channel - virtual void onLeaveChannel(const RtcStats& stats) { - if (m_hMsgHanlder) { - ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_LEAVE_CHANNEL), 0, 0); - } - } - - // Register onError callback - // Triggered when an error occurs during SDK runtime - virtual void onError(int err, const char* msg) { - if (m_hMsgHanlder) { - char* message = new char[1024] {0}; - memcpy(message, msg, strlen(msg)); - ::PostMessage(m_hMsgHanlder, WM_MSGID(EID_ERROR), (WPARAM)message, err); - } - } - private: HWND m_hMsgHanlder; }; @@ -1142,13 +1077,16 @@ m_rtcEngine->setupLocalVideo(canvas); ### Join a channel -Set the channel name and user role, and use a temporary token to join a channel. +Call the `joinChannel`[2/2] method, fill in the temporary token obtained from the console, the channel name used when obtaining the token, and set the user role. + ```cpp -void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { +void CAgoraQuickStartDlg::OnBnClickedBtnJoin() +{ + CString strChannelName; - // Get channel name + // Get the channel name m_edtChannelName.GetWindowText(strChannelName); if (strChannelName.IsEmpty()) { AfxMessageBox(_T("Fill channel name first")); @@ -1156,16 +1094,21 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { } ChannelMediaOptions option; - // Set channel profile to live broadcasting - option.channelProfile = CHANNEL_PROFILE_COMMUNICATION; - // Set user role to broadcaster; keep default value if setting user role to audience + // Set the channel profile to live broadcasting + option.channelProfile = CHANNEL_PROFILE_LIVE_BROADCASTING; + // Set the user role to broadcaster; to set the user role as audience, keep the default value option.clientRoleType = CLIENT_ROLE_BROADCASTER; + // Publish the audio stream captured by the microphone + option.publishMicrophoneTrack = true; // Automatically subscribe to all audio streams + // Publish the microphone track + option.publishMicrophoneTrack = true; + // Publish the camera track + option.publishCameraTrack = true; option.autoSubscribeAudio = true; - // Automatically subscribe to all video streams - option.autoSubscribeVideo = true; - // Fill in your temporary token obtained from the Agora Console to join the channel + // Join the channel using the temporary token obtained from the console m_rtcEngine->joinChannel(token, cs2utf8(strChannelName).c_str(), 0, option); + } ``` @@ -1194,6 +1137,10 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { option.channelProfile = CHANNEL_PROFILE_LIVE_BROADCASTING; // Set user role to broadcaster; keep default value if setting user role to audience option.clientRoleType = CLIENT_ROLE_BROADCASTER; + // Publish the local video track + option.publishMicrophoneTrack = true; + // Publish the camera track + option.publishCameraTrack = true; // Automatically subscribe to all audio streams option.autoSubscribeAudio = true; // Automatically subscribe to all video streams @@ -1232,6 +1179,10 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() { option.channelProfile = CHANNEL_PROFILE_LIVE_BROADCASTING; // Set user role to broadcaster; keep default value if setting user role to audience option.clientRoleType = CLIENT_ROLE_BROADCASTER; + // Publish the microphone track + option.publishMicrophoneTrack = true; + // Publish the camera track + option.publishCameraTrack = true; // Automatically subscribe to all audio streams option.autoSubscribeAudio = true; // Automatically subscribe to all video streams @@ -1264,6 +1215,8 @@ void CAgoraQuickStartDlg::OnBnClickedBtnJoin() option.channelProfile = CHANNEL_PROFILE_LIVE_BROADCASTING; // Set the user role as broadcaster; keep the default value if you want to set the user role as audience option.clientRoleType = CLIENT_ROLE_BROADCASTER; + // Publish the microphone track + option.publishMicrophoneTrack = true; // Automatically subscribe to all audio streams option.autoSubscribeAudio = true; // Fill in the temporary token you obtained from the console to join the channel