@@ -101,9 +101,6 @@ bool CAgoraMultiChannelDlg::InitAgora()
101101void CAgoraMultiChannelDlg::UnInitAgora ()
102102{
103103 if (m_rtcEngine) {
104- if (m_joinChannel)
105- // leave channel
106- m_joinChannel = !m_rtcEngine->leaveChannel ();
107104 for (auto &info : m_channels)
108105 {
109106 info.channel ->release ();
@@ -216,53 +213,40 @@ void CAgoraMultiChannelDlg::OnBnClickedButtonJoinchannel()
216213 return ;
217214 }
218215 std::string szChannelId = cs2utf8 (strChannelName);
219- if (!m_joinChannel) {
220- // join main channel in the engine.
221- if (0 == m_rtcEngine->joinChannel (APP_TOKEN, szChannelId.c_str (), " " , 0 )) {
222- m_strMainChannel = strChannelName;
223- m_cmbChannelList.InsertString (m_cmbChannelList.GetCount (), strChannelName);
224- m_cmbChannelList.SetCurSel (0 );
225- m_btnJoinChannel.EnableWindow (FALSE );
226- strInfo.Format (_T (" join channel:%s ...." ), strChannelName);
227- m_lstInfo.InsertString (m_lstInfo.GetCount (), strInfo);
228- }
229- }
230- else {
231- CString strTmp;
232- for (int nIndex = 0 ; nIndex < m_cmbChannelList.GetCount (); nIndex++)
233- {
234- m_cmbChannelList.GetLBText (nIndex, strTmp);
235- if (strTmp.Trim () == strChannelName)
236- {
237- AfxMessageBox (_T (" you joined this channel!" ));
238- return ;
239- }
240- }
241- // create channel by channel id.
242- IChannel * pChannel = static_cast <IRtcEngine2 *>(m_rtcEngine)->createChannel (szChannelId.c_str ());
243- // create channel event handler.
244- ChannelEventHandler* pEvt = new ChannelEventHandler;
245- // set message receiver window.
246- pEvt->setMsgHandler (GetSafeHwnd ());
247- // add channels.
248- m_channels.emplace_back (szChannelId, pChannel, pEvt);
249- // set channel event handler.
250- pChannel->setChannelEventHandler (pEvt);
251- ChannelMediaOptions options;
252- options.autoSubscribeAudio = true ;
253- options.autoSubscribeVideo = true ;
254- options.publishLocalAudio = m_chkPublishAudio.GetCheck ();
255- options.publishLocalVideo = m_chkPublishVideo.GetCheck ();
256- pChannel->setClientRole (CLIENT_ROLE_BROADCASTER);
257- // join channel
258- if (0 == pChannel->joinChannel (APP_TOKEN, " " , 0 , options))
216+ CString strTmp;
217+ for (int nIndex = 0 ; nIndex < m_cmbChannelList.GetCount (); nIndex++)
218+ {
219+ m_cmbChannelList.GetLBText (nIndex, strTmp);
220+ if (strTmp.Trim () == strChannelName)
259221 {
260- m_btnJoinChannel.EnableWindow (FALSE );
261- m_cmbChannelList.InsertString (m_cmbChannelList.GetCount (), strChannelName);
262- strInfo.Format (_T (" join channel:%s ...." ), strChannelName);
263- m_lstInfo.InsertString (m_lstInfo.GetCount (), strInfo);
222+ AfxMessageBox (_T (" you joined this channel!" ));
223+ return ;
264224 }
265225 }
226+ // create channel by channel id.
227+ IChannel * pChannel = static_cast <IRtcEngine2 *>(m_rtcEngine)->createChannel (szChannelId.c_str ());
228+ // create channel event handler.
229+ ChannelEventHandler* pEvt = new ChannelEventHandler;
230+ // set message receiver window.
231+ pEvt->setMsgHandler (GetSafeHwnd ());
232+ // add channels.
233+ m_channels.emplace_back (szChannelId, pChannel, pEvt);
234+ // set channel event handler.
235+ pChannel->setChannelEventHandler (pEvt);
236+ ChannelMediaOptions options;
237+ options.autoSubscribeAudio = true ;
238+ options.autoSubscribeVideo = true ;
239+ options.publishLocalAudio = m_chkPublishAudio.GetCheck ();
240+ options.publishLocalVideo = m_chkPublishVideo.GetCheck ();
241+ pChannel->setClientRole (CLIENT_ROLE_BROADCASTER);
242+ // join channel
243+ if (0 == pChannel->joinChannel (APP_TOKEN, " " , 0 , options))
244+ {
245+ m_btnJoinChannel.EnableWindow (FALSE );
246+ m_cmbChannelList.InsertString (m_cmbChannelList.GetCount (), strChannelName);
247+ strInfo.Format (_T (" join channel:%s ...." ), strChannelName);
248+ m_lstInfo.InsertString (m_lstInfo.GetCount (), strInfo);
249+ }
266250}
267251
268252
0 commit comments