wxr
2024-09-24 691dbe24f5724f153e07947c7b75bdfea5f0b6d5
HDL_ON/DAL/ThirdPartySdk/HDLLinphone.cs
@@ -13,6 +13,7 @@
using Android.Widget;
using Com.Hdl.Hdllinphonesdk;
#else
using Other;
using Foundation;
using UIKit;
using Shared.IOS.HDLLinphoneSDK;
@@ -65,7 +66,7 @@
        /// false:收到推送并且已经收到sip呼叫才跳转呼叫页面
        /// true:原生收到呼叫马上跳转呼叫页面,不等待推送过来
        /// </summary>
        bool IsAutoJumpCallView = false;
        bool IsAutoJumpCallView = true;
        /// <summary>
        /// 是否初始化了SDK
        /// </summary>
@@ -95,7 +96,7 @@
            Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().InitalLinPhone();
            //设置收到来电后、是否需自动跳转呼叫页面方案
            Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().IsAutoJumpCallView = IsAutoJumpCallView;
            //设置Listener监听
            //设置Listener监听(Shared.IOS.HDLLinphoneSDK)
            mOnHDLLinphoneCallDelegate = new OnHDLLinphoneCallDelegate(this);
            Console.WriteLine(UserInfo.Current.ID);
            Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().HdlLinphoneCallDelegate = mOnHDLLinphoneCallDelegate;
@@ -108,25 +109,60 @@
#endif
        }
        /// <summary>
        /// 设置sip登录账号
        /// </summary>
        /// <param name="mHDLSipInfo"></param>
        public void SetAccountAndLogin(HDLSipInfo mHDLSipInfo)
        public void SetAccountAndLogin(HDLSipInfo mHDLSipInfo, string mInterphoneType)
        {
            this.currentHDLSipInfo = mHDLSipInfo;
            if (mHDLSipInfo == null) return;
            if (mHDLSipInfo == null) {
                //new alert
                return;
            }
            //登录sip服务器
#if __IOS__
            //Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().Login("6666", "85521566", "116.62.26.215:5060");
            Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().Login(mHDLSipInfo.sipAccount, mHDLSipInfo.sipPasswd, mHDLSipInfo.realm);
            string systemVersion = UIKit.UIDevice.CurrentDevice.SystemVersion;
            System.Version currentVersion = new System.Version(systemVersion);
            System.Version version17 = new System.Version(17, 0);
            if (currentVersion.CompareTo(version17) > 0)
            {
                HDLLinPhoneSDK.Instance().Login(mHDLSipInfo.sipAccount, mHDLSipInfo.sipPasswd, mHDLSipInfo.realm, "udp");
            }
            else
            {
                HDLLinPhoneSDK.Instance().Login(mHDLSipInfo.sipAccount, mHDLSipInfo.sipPasswd, mHDLSipInfo.realm, DB_ResidenceData.Instance.linphoneConnectType.ToString());
            }
#else
            HDLLinphoneKit.Instance.SetAccountAndLogin(mHDLSipInfo.sipAccount, mHDLSipInfo.sipPasswd, mHDLSipInfo.realm);
            if (mInterphoneType == InterphoneType.FREEVIEW.ToString())
            {
                HDLLinphoneKit.Instance.SetAccountAndLogin(
                    mHDLSipInfo.sipAccount,
                    mHDLSipInfo.sipPasswd,
                    mHDLSipInfo.realm,
                    //"sip:139.159.157.75:47000;transport=udp",
                    HDLLinphoneKit.InterPhoneTypeFreeview,
                    DB_ResidenceData.Instance.linphoneConnectType.ToString()
                    );
            }
            else
            {
                HDLLinphoneKit.Instance.SetAccountAndLogin(
                   mHDLSipInfo.sipAccount,
                   mHDLSipInfo.sipPasswd,
                   mHDLSipInfo.realm,
                   //mHDLSipInfo.proxy+ ";transport=udp",
                   //"sip:139.159.157.75:47000;transport=udp",
                   HDLLinphoneKit.InterPhoneTypeHdl,
                    DB_ResidenceData.Instance.linphoneConnectType.ToString()
                   );
            }
#endif
        }
        /// <summary>
@@ -140,9 +176,16 @@
            this.mHDLCallVideoInfo = null;
#if __IOS__
            HDLLinPhoneSDK.Instance().LogoutAllLinphoneUser();
            Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().LogoutAllLinphoneUser();
#else
            HDLLinphoneKit.Instance.Logout();
            if (HDLLinphoneKit.Instance != null)
            {
                HDLLinphoneKit.Instance.Logout();
            }
            else
            {
            }
#endif
        }
@@ -153,7 +196,7 @@
        {
#if __IOS__
            HDLLinPhoneSDK.Instance().ClearAllConfigs();
            Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().ClearAllConfigs();
#else
            HDLLinphoneKit.Instance.ClearProxyConfig();
#endif
@@ -197,28 +240,46 @@
        /// 请求服务器获取当前住宅Sip账号信息并初始化LinphoneSDK和登录
        /// </summary>
        /// <param name="homeId"></param>
        public void GetHDLSipInfoAndInitSDK(string homeId, bool clearCallInfo = true)
        public void GetHDLSipInfoAndInitSDK(HDLCallVideoInfo mHDLCallVideoInfo, bool clearCallInfo = true)
        {
            try
            {
                //先清空呼叫和监视设备信息
                if (clearCallInfo)
                {
                    InitCallInfo(null);
                    //InitCallInfo(null);//造成接收呼叫时开锁开锁异常
                }
                HDLSipInfo mHDLSipInfo = GetHDLSipInfo(homeId);
                HDLSipInfo mHDLSipInfo = GetHDLSipInfo(mHDLCallVideoInfo.HomeId);
                if (mHDLSipInfo != null)
                {
                    Application.RunOnMainThread(() =>
                    {
                        InitLinphone();
                        mHDLSipInfo.homeId = homeId;
                        SetAccountAndLogin(mHDLSipInfo);
                        try
                        {
                            InitLinphone();
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"InitLinphone exception : {ex.Message}");
                        }
                        mHDLSipInfo.homeId = mHDLCallVideoInfo.HomeId;
                        try {
                            SetAccountAndLogin(mHDLSipInfo, mHDLCallVideoInfo.InterphoneType);
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"SetAccountAndLogin exception : {ex.Message}");
                        }
                        Utlis.WriteLine("CALL 获取SIP账号成功:" + mHDLSipInfo.sipAccount);
                    });
                }
                else
                {
                    //Application.RunOnMainThread(() =>
                    //{
                    //    new Alert("", $"获取Sip账号信息失败.", "确定").Show();
                    //});
                }
            }
            catch { }
@@ -290,7 +351,7 @@
        #region ■  --  新接听和开锁接口_______________________________
        /// <summary>
        /// 开锁
        /// 可视对讲开锁
        /// </summary>
        public void HDLUnlockAction()
        {
@@ -310,6 +371,10 @@
                Application.RunOnMainThread(() =>
                {
                    if(revertObj == null)
                    {
                        return;
                    }
#if __IOS__
                    if (revertObj.Code == StateCode.SUCCESS)
@@ -374,15 +439,45 @@
            { IsBackground = false }.Start();
        }
        /// <summary>
        /// 拒接(挂段所有呼叫)
        /// </summary>
        public void HDLRejectCallIn() {
            if (CheckmHDLCallVideoInfoIsNullOrEmpty()) return;
            new Thread(() =>
            {
                Dictionary<string, object> dic = new Dictionary<string, object>();
                dic.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
                dic.Add("deviceId", mHDLCallVideoInfo.DeviceId);
                dic.Add("interphoneType", "HDL");
                dic.Add("callId", mHDLCallVideoInfo.CallId);//呼叫id
                var requestJson = HttpUtil.GetSignRequestJson(dic);
                var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_VideoDevice_RejectCallIn, requestJson);
                if (revertObj.Code == StateCode.SUCCESS)
                {
                }
                else
                {
                    Utlis.WriteLine("POST 更新状态失败 code: " + revertObj.Code);
                }
            })
            { IsBackground = false }.Start();
        }
        #endregion
        #region ■  --  跳转监控页面_______________________________
        /// <summary>
        /// 跳转监控页面
        /// </summary>
        /// <param name="mESVideoInfo"></param>
        public void ShowESVideoMonitor(ESVideoInfo mESVideoInfo)
        public void ShowESVideoMonitor(ESVideoInfo mESVideoInfo,string mInterphoneType)
        {
            InitLinphone();
            //sip账号为空
@@ -396,13 +491,19 @@
            mHDLCallVideoInfo.HomeId = mESVideoInfo.HomeId;
            mHDLCallVideoInfo.DeviceId = mESVideoInfo.Lc_DeviceId;
            mHDLCallVideoInfo.DeviceName = mESVideoInfo.DeviceName;
            mHDLCallVideoInfo.InterphoneType = InterphoneType.HDL.ToString();
            mHDLCallVideoInfo.InterphoneType = mInterphoneType;
            mHDLCallVideoInfo.DeviceSipAccount = mESVideoInfo.deviceSipAccount;//监视主动呼叫门口机时用到
            InitCallInfo(mHDLCallVideoInfo);
#if __IOS__
            HDLLinPhoneSDK.Instance().CallWithUserName(mHDLCallVideoInfo.DeviceSipAccount, mHDLCallVideoInfo.DeviceName);
            if (mHDLCallVideoInfo.spk == "door.gate")
            {
                Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().CallHDLSRWithUserName(mHDLCallVideoInfo.DeviceSipAccount, mHDLCallVideoInfo.DeviceName);
            }else{
                Shared.IOS.HDLLinphoneSDK.HDLLinPhoneSDK.Instance().CallWithUserName(mHDLCallVideoInfo.DeviceSipAccount, mHDLCallVideoInfo.DeviceName);
            }
#else
            //1.先呼叫设备
@@ -422,8 +523,16 @@
        /// 收到推送,后判断呼叫住宅是否为当前住宅,不是的话重新获取SIP账号并登录
        /// </summary>
        /// <param name="mESVideoInfo"></param>
        public void ShowESVideoIntercom(ESVideoInfo mESVideoInfo)
        public void ShowESVideoIntercom(ESVideoInfo mESVideoInfo,string mInterphoneType)
        {
            if(this.mHDLCallVideoInfo != null)
            {
                if(this.mHDLCallVideoInfo.CallId == mESVideoInfo.callId)
                {
                    return;
                }
            }
            InitLinphone();
            HDLCallVideoInfo mHDLCallVideoInfo = new HDLCallVideoInfo();
@@ -431,7 +540,7 @@
            mHDLCallVideoInfo.HomeId = mESVideoInfo.HomeId;
            mHDLCallVideoInfo.DeviceId = mESVideoInfo.Lc_DeviceId;
            mHDLCallVideoInfo.DeviceName = mESVideoInfo.DeviceName;
            mHDLCallVideoInfo.InterphoneType = InterphoneType.HDL.ToString();
            mHDLCallVideoInfo.InterphoneType = mInterphoneType;
            mHDLCallVideoInfo.DeviceSipAccount = mESVideoInfo.deviceSipAccount;
            mHDLCallVideoInfo.spk = mESVideoInfo.spk;
            InitCallInfo(mHDLCallVideoInfo);
@@ -449,7 +558,7 @@
                Utlis.WriteLine("CALL 收到推送 其他住宅,重新获取呼叫住宅的SIP账号并登录");
                new Thread(() =>
                {
                    GetHDLSipInfoAndInitSDK(mESVideoInfo.HomeId, false);
                    GetHDLSipInfoAndInitSDK(mHDLCallVideoInfo, false);
                })
                { IsBackground = false }.Start();
@@ -468,16 +577,27 @@
        {
            if (mHDLCallVideoInfo.spk == "door.gate")
            {
#if __IOS__
                //自研可视对讲
                HDLLinPhoneSDK.Instance().GotoHDLSRLinphoneIntercomVC(mHDLCallVideoInfo.DeviceName,mHDLCallVideoInfo.DeviceSipAccount);
           }
                HDLLinPhoneSDK.Instance().GotoHDLSRLinphoneIntercomVC(mHDLCallVideoInfo.DeviceName, mHDLCallVideoInfo.DeviceSipAccount);
#else
                var intent = new Intent(Shared.Application.Activity, typeof(Com.Hdl.Hdllinphonesdk.Activity.HDLLinphoneReverseCallActivity));
                if (mHDLCallVideoInfo != null)
                {
                    //intent.PutExtra(HDLLinphoneKit.KeyTitleName, mHDLCallVideoInfo.DeviceName);
                    intent.PutExtra("lpTitleName", mHDLCallVideoInfo.DeviceName);
                    intent.PutExtra("lpSipAccount", mHDLCallVideoInfo.DeviceSipAccount);
                }
                Shared.Application.Activity.StartActivity(intent);
#endif
            }
            else {
                //狄耐克可视对讲
                //如果开启了自动跳转方案,则无需继续下面处理、无需手动跳转
                if (IsAutoJumpCallView) return;
                //先结束掉之前的线程
                EndCheckIncomingCallThread();
                //检测是否来电了如果是直接调整呼叫页面如果不是则开启线程等待判断
                //检测是否来电了如果是直接调整呼叫页面如果不是则开启线程等待判断(Shared.IOS.HDLLinphoneSDK)
                if (IsIncomingReceivedCallState())
                {
                    Utlis.WriteLine("CALL 已经来电了。。。打开呼叫页面");
@@ -494,12 +614,13 @@
        }
        /// <summary>
        /// 是否来电状态
        /// 是否来电状态(Shared.IOS.HDLLinphoneSDK)
        /// </summary>
        /// <returns></returns>
        bool IsIncomingReceivedCallState() {
        bool IsIncomingReceivedCallState()
        {
#if __IOS__
             return HDLLinPhoneSDK.Instance().IsIncomingReceivedCallState;
            return HDLLinPhoneSDK.Instance().IsIncomingReceivedCallState;
#else
            return HDLLinphoneKit.Instance.IsIncomingReceivedCallState;
#endif
@@ -512,13 +633,15 @@
#if __IOS__
            HDLLinPhoneSDK.Instance().GotoHDLLinphoneIntercomVC(mHDLCallVideoInfo.DeviceName);
#else
            var intent = new Intent(Shared.Application.Activity, typeof(Com.Hdl.Hdllinphonesdk.Activity.HDLLinphoneIntercomActivity));
            if (mHDLCallVideoInfo != null)
            {
                intent.PutExtra(HDLLinphoneKit.KeyTitleName, mHDLCallVideoInfo.DeviceName);
                //intent.PutExtra(HDLLinphoneKit.KeyTitleName, mHDLCallVideoInfo.DeviceName);
                intent.PutExtra(HDLLinphoneKit.KeyTitleName, mHDLCallVideoInfo.CallId);
            }
            Shared.Application.Activity.StartActivity(intent);
#endif
@@ -560,7 +683,7 @@
                                threadTime--;
                                Utlis.WriteLine("CALL 检测中...." + threadTime);
                                Thread.Sleep(1000);
                                //来电了,跳转呼叫页面
                                //来电了,跳转呼叫页面(Shared.IOS.HDLLinphoneSDK)
                                if (IsIncomingReceivedCallState())
                                {
                                    Utlis.WriteLine("CALL 来电了。。。打开呼叫页面");
@@ -643,6 +766,7 @@
            public void OnAnswerAction()
            {
                //showToast("接听");
                HDLLinphoneKit.Instance.SetMediaPlayerLooping(false);
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.RECEIVED, InterphoneType.HDL);
            }
            /// <summary>
@@ -662,6 +786,7 @@
            public void OnRejectCallAction()
            {
                //showToast("拒接");
                HDLLinphoneKit.Instance.SetMediaPlayerLooping(false);
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.REJECT, InterphoneType.HDL);
            }
@@ -689,6 +814,23 @@
            public void OnIncomingCall(string userName)
            {
                Utlis.WriteLine("OnIncomingCall :" + userName);
            }
            /// <summary>
            /// 拒接事件
            /// 全部挂断
            /// </summary>
            public void OnCallAllRejection()
            {
                HDLLinphoneKit.Instance.SetMediaPlayerLooping(false);
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.REJECT, InterphoneType.HDL);
                hdlLinphone.HDLRejectCallIn();
            }
            public void OnMissedCallsAction()
            {
                HDLLinphoneKit.Instance.SetMediaPlayerLooping(false);
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.MISSED, InterphoneType.HDL);
            }
        }
@@ -721,12 +863,12 @@
        /// 
        /// </summary>
        OnHDLLinphoneCallDelegate mOnHDLLinphoneCallDelegate;
        /// <summary>
        /// 
        /// </summary>
        public class OnHDLLinphoneCallDelegate : HDLLinphoneCallDelegate
        {
        {
            [Weak] HDLLinphone hdlLinphone;
            public OnHDLLinphoneCallDelegate(HDLLinphone mHDLLinphone)
@@ -739,6 +881,7 @@
            /// </summary>
            public override void OnAnswerAction()
            {
                Other.SoundPlayer.Ins.StopSound();
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.RECEIVED, InterphoneType.HDL);
            }
@@ -756,22 +899,24 @@
            /// </summary>
            public override void OnRejectCallAction()
            {
                MainPage.Log("iOS 全部拒接");
                Other.SoundPlayer.Ins.StopSound();
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.REJECT, InterphoneType.HDL);
            }
            /// <summary>
            /// 截图成功
            /// </summary>
            /// <param name="image"></param>
            //public override void OnScreenshotSuccessfulAction(UIImage image)
            //{
                ////NSData imageData = UIImagePNGRepresentation(image); UIImage
                //NSData imageData = image.AsPNG();
                //byte[] dataBytes = new byte[imageData.Length];
                //System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, dataBytes, 0, Convert.ToInt32(imageData.Length));
                ////image.g
                ////hdlLinphone.ScreenshotSuccessfulAction(dataBytes);
            //}
            /// <param name = "image" ></ param >
            public override void OnScreenshotSuccessfulAction(UIImage image)
            {
                //NSData imageData = UIImagePNGRepresentation(image); UIImage
                NSData imageData = image.AsPNG();
                byte[] dataBytes = new byte[imageData.Length];
                System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, dataBytes, 0, Convert.ToInt32(imageData.Length));
                //image.g
                //hdlLinphone.ScreenshotSuccessfulAction(dataBytes);
            }
            /// <summary>
            /// 开锁成功
@@ -788,9 +933,19 @@
            {
                Utlis.WriteLine("OnIncomingCall :" + userName);
            }
            public override void OnRejectAllCallAction()
            {
                MainPage.Log("iOS 全部拒接");
                Other.SoundPlayer.Ins.StopSound();
                hdlLinphone.HDLUpdateCallStatus(CallStatusType.REJECT, InterphoneType.HDL);
                hdlLinphone.HDLRejectCallIn();
            }
            //public override void OnScreenshotSuccessfulAction(UIImage image)
            //{
            //    throw new NotImplementedException();
            //}
        }
        #endregion