Exemple #1
0
        private void button_Join_Click(object sender, EventArgs e)
        {
            ImportDll.setH5CompatibleMode(m_ParamInfo.bH5Mode);
            if (false == ImportDll.initAliSdk())
            {
                MessageBox.Show("sdk初始化失败...");
                return;
            }
            updateParamInfo();
            string   appServerUrl = m_ParamInfo.strAppSer;
            string   channel      = m_ParamInfo.strChannel;
            string   userName     = m_ParamInfo.strUserName;
            string   passward     = "hello1234";
            AuthInfo autoinfo;

            GetPassportFromAppServer(appServerUrl, channel, userName, passward, out autoinfo);

            ImportDll.setLocalViewConfig(this.panel_LocalView.Handle);

            if (0 < ImportDll.startPreview())
            {
                listBox_Tips.Items.Add("加载本地浏览成功...");
            }
            else
            {
                listBox_Tips.Items.Add("加载本地浏览失败...");
            }


            dllJoinChannel(autoinfo);
        }
        private void dllJoinChannel(AuthInfo autoinfo)
        {
            ImportDll.joinResultCB = new ImportDll.setJoinResultCB(OnJoinResult);
            ImportDll.setJoinResultCallBack(ImportDll.joinResultCB);

            ImportDll.RemoteUserOnLineNotifyCB = new ImportDll.setRemoteUserOnLineNotifyCB(onRemoteUserOnLineNotify);
            ImportDll.setRemoteUserOnLineNotifyCallBack(ImportDll.RemoteUserOnLineNotifyCB);
            ImportDll.RemoteUserOffLineNotifyCB = new ImportDll.setRemoteUserOffLineNotifyCB(onRemoteUserOffLineNotify);
            ImportDll.setRemoteUserOffLineNotifyCallBack(ImportDll.RemoteUserOffLineNotifyCB);
            ImportDll.SubscribeChangedNotifyCB = new ImportDll.setSubscribeChangedNotifyCB(onSubscribeChangedNotify);
            ImportDll.setSubscribeChangedNotifyCallBack(ImportDll.SubscribeChangedNotifyCB);
            ImportDll.RemoteTrackAvailableNotifyCB = new ImportDll.setRemoteTrackAvailableNotifyCB(onRemoteTrackAvailableNotify);
            ImportDll.setRemoteTrackAvailableNotifyCallBack(ImportDll.RemoteTrackAvailableNotifyCB);

            ImportDll.ByeCB = new ImportDll.setByeCB(onBye);
            ImportDll.setByeCallBack(ImportDll.ByeCB);
            ImportDll.OccurErrorCB = new ImportDll.setOccurErrorCB(onOccurError);
            ImportDll.setOccurErrorCallBack(ImportDll.OccurErrorCB);


            ImportDll.setLogLevel(AliRtcLogLevel.AliRtcLogLevelInfo);
            ImportDll.setAutoPublishSubscribe(m_ParamInfo.bAutoPush, m_ParamInfo.bAutoSub);
            ImportDll.configLocalAudioPublish(m_ParamInfo.bPushAudio);
            ImportDll.configLocalCameraPublish(m_ParamInfo.bPushCamera);
            ImportDll.configLocalScreenPublish(m_ParamInfo.bPushScreen);
            ImportDll.configLocalSimulcast(true, AliRtcVideoTrack.AliRtcVideoTrackCamera);

            bool bRet = ImportDll.joinChannel(autoinfo.strChannel, autoinfo.strAppId, autoinfo.strUserId, autoinfo.strNonce, autoinfo.strToken, autoinfo.strGlsb, autoinfo.strUserName, autoinfo.iTimesTamp);

            if (bRet == false)
            {
                listBox_Tips.Items.Add("加入房间失败...");
            }
        }
 private void checkAudio_CheckedChanged(object sender, EventArgs e)
 {
     if (!m_bInitialItem)
     {
         return;
     }
     m_ParamInfo.bPushAudio = mainFrm.checkAudio.Checked;
     ImportDll.configLocalAudioPublish(m_ParamInfo.bPushAudio);
     ImportDll.publish();
 }
        private void checkScreen_CheckedChanged(object sender, EventArgs e)
        {
            if (!m_bInitialItem)
            {
                return;
            }
            m_ParamInfo.bPushScreen = mainFrm.checkScreen.Checked;
            ImportDll.configLocalScreenPublish(m_ParamInfo.bPushScreen);

            ImportDll.setPubResultCB PubResultCB;
            PubResultCB = new ImportDll.setPubResultCB(onPubResult);
            ImportDll.setPublishResultCallBack(PubResultCB);
            ImportDll.publish();
        }
        public static void onRemoteTrackAvailableNotify(string strUid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack)
        {
            if (!m_ParamInfo.bAutoSub)
            {
                //当自动订阅开关关闭时,所有用户都手动订阅
                if (audioTrack == AliRtcAudioTrack.AliRtcAudioTrackMic)
                {
                    ImportDll.configRemoteAudio(strUid, true);
                }
                else
                {
                    ImportDll.configRemoteAudio(strUid, false);
                }
                if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackCamera ||
                    videoTrack == AliRtcVideoTrack.AliRtcVideoTrackBoth)
                {
                    ImportDll.configRemoteCameraTrack(strUid, true, true);
                }
                else
                {
                    ImportDll.configRemoteCameraTrack(strUid, true, false);
                }

                if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackScreen ||
                    videoTrack == AliRtcVideoTrack.AliRtcVideoTrackBoth)
                {
                    ImportDll.configRemoteScreenTrack(strUid, true);
                }
                else
                {
                    ImportDll.configRemoteScreenTrack(strUid, false);
                }
                ImportDll.setSubscribeResultCB SubscribeResultCB;
                SubscribeResultCB = new ImportDll.setSubscribeResultCB(onSubscribeResult);
                ImportDll.setSubscribeResultCallBack(SubscribeResultCB);

                bool bRet = ImportDll.subscribe(strUid);

                if (bRet == false)
                {
                    AliRtcSample.mainFrm.listBox_Tips.Items.Add("订阅失败,是否调用onSubscribeResultCallBack回调?");
                }
            }
            else
            {
                //开启自动订阅开关时,订阅所有有流的用户
                onSubscribeResult(strUid, audioTrack, videoTrack);
            }
        }
 public static void onSubscribeResultDE_(string strUid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack)
 {
     if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackNo ||
         videoTrack == AliRtcVideoTrack.AliRtcVideoTrackEnd)
     {
         DeleteViewInfo(strUid, AliRtcVideoTrack.AliRtcVideoTrackCamera);
         DeleteViewInfo(strUid, AliRtcVideoTrack.AliRtcVideoTrackScreen);
     }
     else if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackCamera)
     {
         Panel panel_camera;
         DeleteViewInfo(strUid, AliRtcVideoTrack.AliRtcVideoTrackScreen);
         findOrCreatPanel_(strUid, videoTrack, out panel_camera);
         Debug.Assert(panel_camera != null);
         ImportDll.setRemoteViewConfig(panel_camera.Handle, strUid, videoTrack,
                                       AliRtcRenderMode.AliRtcRenderModeFill, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
     }
     else if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackScreen)
     {
         Panel panel_screen;
         DeleteViewInfo(strUid, AliRtcVideoTrack.AliRtcVideoTrackCamera);
         findOrCreatPanel_(strUid, videoTrack, out panel_screen);
         Debug.Assert(panel_screen != null);
         ImportDll.setRemoteViewConfig(panel_screen.Handle, strUid, videoTrack,
                                       AliRtcRenderMode.AliRtcRenderModeFill, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
     }
     else if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackBoth)
     {
         Panel panel_camera;
         Panel panel_screen;
         findOrCreatPanel_(strUid, AliRtcVideoTrack.AliRtcVideoTrackCamera, out panel_camera);
         findOrCreatPanel_(strUid, AliRtcVideoTrack.AliRtcVideoTrackScreen, out panel_screen);
         Debug.Assert(panel_camera != null);
         Debug.Assert(panel_screen != null);
         ImportDll.setRemoteViewConfig(panel_camera.Handle, strUid, AliRtcVideoTrack.AliRtcVideoTrackCamera,
                                       AliRtcRenderMode.AliRtcRenderModeFill, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
         ImportDll.setRemoteViewConfig(panel_screen.Handle, strUid, AliRtcVideoTrack.AliRtcVideoTrackScreen,
                                       AliRtcRenderMode.AliRtcRenderModeFill, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
     }
     Layout_RemoteView_();
 }
 private void AliRtcSample_FormClosing(object sender, EventArgs e)
 {
     ImportDll.releaseAliSdk();
     mainFrm = null;
 }
        private void button_Leave_Click(object sender, EventArgs e)
        {
            ImportDll.releaseAliSdk();

            listBox_Tips.Items.Add("离开房间...");
        }
        public static void onSubscribeResultDE(string strUid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack)
        {
            if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackNo ||
                videoTrack == AliRtcVideoTrack.AliRtcVideoTrackEnd)
            {
                if (m_uidList.Contains(strUid))
                {
                    m_uidList.Remove(strUid);
                }
                if (m_camaraUid2panelHash.Contains(strUid))
                {
                    m_camaraUid2panelHash.Remove(strUid);
                }
                if (m_screenUid2panelHash.Contains(strUid))
                {
                    m_screenUid2panelHash.Remove(strUid);
                }
            }

            else if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackCamera)
            {
                if (!m_uidList.Contains(strUid))
                {
                    m_uidList.AddLast(strUid);
                }
                if (m_screenUid2panelHash.Contains(strUid))
                {
                    m_screenUid2panelHash.Remove(strUid);
                }
                Panel panel_camera;
                findOrCreatPanel(strUid, videoTrack, out panel_camera);
                Debug.Assert(panel_camera != null);
                ImportDll.setRemoteViewConfig(panel_camera.Handle, strUid, videoTrack,
                                              AliRtcRenderMode.AliRtcRenderModeAuto, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
            }
            else if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackScreen)
            {
                if (!m_uidList.Contains(strUid))
                {
                    m_uidList.AddLast(strUid);
                }
                if (m_camaraUid2panelHash.Contains(strUid))
                {
                    m_camaraUid2panelHash.Remove(strUid);
                }
                Panel panel_screen;
                findOrCreatPanel(strUid, videoTrack, out panel_screen);
                Debug.Assert(panel_screen != null);
                ImportDll.setRemoteViewConfig(panel_screen.Handle, strUid, videoTrack,
                                              AliRtcRenderMode.AliRtcRenderModeAuto, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
            }
            else if (videoTrack == AliRtcVideoTrack.AliRtcVideoTrackBoth)
            {
                if (!m_uidList.Contains(strUid))
                {
                    m_uidList.AddLast(strUid);
                }
                Panel panel_camera;
                Panel panel_screen;
                findOrCreatPanel(strUid, AliRtcVideoTrack.AliRtcVideoTrackCamera, out panel_camera);
                findOrCreatPanel(strUid, AliRtcVideoTrack.AliRtcVideoTrackScreen, out panel_screen);
                Debug.Assert(panel_camera != null);
                Debug.Assert(panel_screen != null);
                ImportDll.setRemoteViewConfig(panel_camera.Handle, strUid, AliRtcVideoTrack.AliRtcVideoTrackCamera,
                                              AliRtcRenderMode.AliRtcRenderModeAuto, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
                ImportDll.setRemoteViewConfig(panel_screen.Handle, strUid, AliRtcVideoTrack.AliRtcVideoTrackScreen,
                                              AliRtcRenderMode.AliRtcRenderModeAuto, AliRtcScaleRatio.AliRtcScaleRatio_16_9, false);
            }
            Layout_RemoteView();
        }
        private void comboBoxCamera_SelectedIndexChanged(object sender, EventArgs e)
        {
            string camera = comboBoxCamera.SelectedItem.ToString();

            ImportDll.setCurrentCamera(camera);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            updateParamInfo();
            ImportDll.setH5CompatibleMode(m_ParamInfo.bH5Mode);
            if (false == ImportDll.initAliSdk())
            {
                MessageBox.Show("sdk初始化失败...");
                return;
            }

            byte[] buf = new byte[100];
            ImportDll.getAudioCaptures(buf);

            string str = Encoding.UTF8.GetString(buf);
            int    pos = str.IndexOf('\0');

            if (pos >= 0)
            {
                str = str.Substring(0, pos);
            }
            Console.WriteLine(str);

            buf = new byte[200];
            ImportDll.getCameraList(buf);

            str = Encoding.UTF8.GetString(buf);

            int k = 0;

            while (k < str.Length)
            {
                pos = str.IndexOf('\0', k);
                if (pos >= 0)
                {
                    string camera = str.Substring(k, pos - k);
                    comboBoxCamera.Items.Add(camera);
                }

                if ((pos < (str.Length - 2)) && (str.ElementAt(pos + 1) == '\0'))
                {
                    break;
                }

                k = pos + 1;
            }

            comboBoxCamera.SelectedIndex = 0;

            buf = new byte[200];
            ImportDll.getAudioRenderers(buf);
            str = Encoding.UTF8.GetString(buf);
            pos = str.IndexOf('\0');
            if (pos >= 0)
            {
                str = str.Substring(0, pos);
            }
            Console.WriteLine(str);

            ImportDll.setLocalViewConfig(this.panel_LocalView.Handle);
            int i = ImportDll.startPreview();

            if (0 <= i)
            {
                listBox_Tips.Items.Add("加载本地浏览成功...");
            }
            else
            {
                listBox_Tips.Items.Add("加载本地浏览失败...");
            }
        }