Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-khalid committed Jun 1, 2024
1 parent 2b5ecf7 commit a087315
Showing 1 changed file with 48 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}`}
</CodeBlock>
</ProductWrapper>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -518,17 +492,15 @@ 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) {
// 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;
Expand All @@ -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) {
Expand All @@ -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;
}`}
</CodeBlock>
</ProductWrapper>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -734,17 +704,15 @@ 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) {
// 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;
Expand Down Expand Up @@ -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;
}`}
</CodeBlock>
</ProductWrapper>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}`}
</CodeBlock>
</ProductWrapper>
Expand Down Expand Up @@ -1069,47 +1022,29 @@ 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);
}
}
// 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);
}
}
// 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;
};
Expand Down Expand Up @@ -1142,30 +1077,38 @@ 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.
<ProductWrapper product="video-calling">
```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"));
return;
}
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);
}
```
</ProductWrapper>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a087315

Please sign in to comment.