From ff886457f58791eea4532f6167af51184d9dfe43 Mon Sep 17 00:00:00 2001 From: lss <lsc@hdlchina.com.cn> Date: 星期四, 26 五月 2022 17:31:42 +0800 Subject: [PATCH] 送测 --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java | 155 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 112 insertions(+), 43 deletions(-) diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java index 7473487..29227e3 100644 --- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java +++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java @@ -2,10 +2,12 @@ import android.content.Context; import android.content.Intent; +import android.util.Log; import android.view.TextureView; import android.widget.Toast; import com.hdl.hdllinphonesdk.activity.HDLLinphoneIntercomActivity; +import com.hdl.hdllinphonesdk.activity.HDLLinphoneReverseCallActivity; import com.hdl.hdllinphonesdk.callback.OnHDLLinphoneCallListener; import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; import com.hdl.hdllinphonesdk.core.callback.PhoneCallback; @@ -25,19 +27,44 @@ import org.linphone.core.ProxyConfig; import org.linphone.core.TransportType; +import java.io.FileOutputStream; +import java.io.InputStream; + import static java.lang.Thread.sleep; /** * Created by jlchen on 2021/8/4. */ public class HDLLinphoneKit { + /** + * 涓版灄鍙瀵硅 + */ + public static final String INTER_PHONE_TYPE_FLVI = "FLVI"; + /** + * 澶у崕鍙瀵硅 + */ + public static final String INTER_PHONE_TYPE_IMOUVISIAL = "IMOUVISIAL"; + /** + * 钀ょ煶鐚溂 + */ + public static final String INTER_PHONE_TYPE_EZVIZ = "EZVIZ"; + /** + * HDL鍙瀵硅 + */ + public static final String INTER_PHONE_TYPE_HDL = "HDL"; + /** + * 鍏ㄨ閫氬彲瑙嗗璁� + */ + public static final String INTER_PHONE_TYPE_FREEVIEW = "FREEVIEW"; + public static final String KEY_TITLE_NAME = "lpTitleName"; + public static final String KEY_SIP_ACCOUNT = "lpSipAccount"; public static final String HDLLinphoneKitNAME = "HDLLinphoneKit"; private volatile static HDLLinphoneKit instance; private Context viewContext; private ServiceWaitThread mServiceWaitThread; private String mUsername, mPassword, mServerIP; -// private TextureView mRenderingView, mPreviewView; + // private TextureView mRenderingView, mPreviewView; private boolean isAutoJumpCallView;//鏄惁鑷姩璺宠浆鍛煎彨椤甸潰 private HDLLinphoneKit() { @@ -46,6 +73,7 @@ /** * getInstance + * * @return HDLLinphoneKit */ public static synchronized HDLLinphoneKit getInstance() { @@ -65,16 +93,17 @@ * @return Core */ public Core getCore() { - if(!HDLLinphoneService.isReady()){ + if (!HDLLinphoneService.isReady()) { CheckIfNeedstartService(); return null; - }else { + } else { return HDLLinphoneService.getCore(); } } /** * 鍒濆鍖朙inphone + * * @param context */ public void initLinphone(Context context) { @@ -82,14 +111,13 @@ if (!HDLLinphoneService.isReady()) { CheckIfNeedstartService(); } else { - } } /** * startService */ - private synchronized void CheckIfNeedstartService(){ + private synchronized void CheckIfNeedstartService() { startService(viewContext); addCallback(new RegistrationCallback() { @Override @@ -97,7 +125,6 @@ super.registrationOk(); HDLLog.e(HDLLinphoneKitNAME, "registrationOk: "); callBackRegistrationOk(viewContext); - } @Override @@ -158,9 +185,13 @@ * 璺宠浆鎵撳紑鍛煎彨椤甸潰 */ public void gotoHDLLinphoneIntercomActivity() { - Intent intent = new Intent(viewContext, HDLLinphoneIntercomActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - viewContext.startActivity(intent); + try { + Intent intent = new Intent(viewContext, HDLLinphoneIntercomActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + viewContext.startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + } } /** @@ -214,11 +245,11 @@ * @param password 瀵嗙爜 * @param serverIP sip 鏈嶅姟鍣� */ - public void setAccountAndLogin(String username, String password, String serverIP) { + public void setAccountAndLogin(String username, String password, String serverIP, String inter_type) { mUsername = username; mPassword = password; mServerIP = serverIP; - login(); + login(inter_type); } /** @@ -227,8 +258,7 @@ * @param phoneCallback 閫氳瘽鍥炶皟 * @param registrationCallback 娉ㄥ唽鐘舵�佸洖璋� */ - public void addCallback(RegistrationCallback registrationCallback, - PhoneCallback phoneCallback) { + public void addCallback(RegistrationCallback registrationCallback, PhoneCallback phoneCallback) { if (HDLLinphoneService.isReady()) { HDLLinphoneService.addRegistrationCallback(registrationCallback); HDLLinphoneService.addPhoneCallback(phoneCallback); @@ -241,19 +271,16 @@ /** * 鐧诲綍鍒� SIP 鏈嶅姟鍣� */ - public void login() { - new Thread(new Runnable() { - @Override - public void run() { - while (!HDLLinphoneService.isReady()) { - try { - sleep(80); - } catch (InterruptedException e) { - e.printStackTrace(); - } + public void login(String inter_type) { + new Thread(() -> { + while (!HDLLinphoneService.isReady()) { + try { + sleep(80); + } catch (InterruptedException e) { + e.printStackTrace(); } - loginToServer(); } + loginToServer(inter_type); }).start(); } @@ -282,7 +309,7 @@ /** * 娓呴櫎閰嶇疆琛�, 鍒囨崲璐﹀彿鏃朵細鐢ㄥ埌 */ - public void clearProxyConfig(){ + public void clearProxyConfig() { Core core = HDLLinphoneService.getCore(); if (core != null) { core.setDefaultProxyConfig(null); @@ -322,16 +349,23 @@ /** * 鐧诲綍 SIP 鏈嶅姟鍣� */ - private void loginToServer() { + private void loginToServer(String inter_type) { try { if (mUsername == null || mPassword == null || mServerIP == null) { throw new RuntimeException("The sip account is not configured."); } - registerUserAuth(mUsername, mPassword, mServerIP); + if (inter_type.equals(INTER_PHONE_TYPE_FREEVIEW)) { + // 鍏ㄨ閫氬彲瑙嗗璁叉敞鍐� + freeViewRegisterUserAuth(mUsername, mPassword, mServerIP); + } else { + // 鍏朵粬鍙瀵硅娉ㄥ唽 + registerUserAuth(mUsername, mPassword, mServerIP); + } } catch (CoreException e) { e.printStackTrace(); } } + /** * 鎻愪氦璐﹀彿鍜屽瘑鐮佹敞鍐屽埌鏈嶅姟鍣� * @@ -342,11 +376,9 @@ */ public void registerUserAuth(String name, String password, String host) throws CoreException { Core mLinphoneCore = HDLLinphoneService.getCore(); - if(mLinphoneCore == null) return; + if (mLinphoneCore == null) return; - AuthInfo authInfo = Factory.instance().createAuthInfo(name, null, password, - null, null, host); - + AuthInfo authInfo = Factory.instance().createAuthInfo(name, null, password, null, null, host); AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null); mAccountCreator.setUsername(name); mAccountCreator.setDomain(host); @@ -364,15 +396,45 @@ } /** - * 鍛煎彨 + * 鎻愪氦璐﹀彿鍜屽瘑鐮佹敞鍐屽埌鍏ㄨ閫氭湇鍔″櫒 + * + * @throws CoreException + */ + public void freeViewRegisterUserAuth(String userName, String password, String domain) throws CoreException { + Core mLinphoneCore = HDLLinphoneService.getCore(); + if (mLinphoneCore == null) return; + + AuthInfo authInfo = Factory.instance().createAuthInfo(userName, "", password, null, null, domain); + + AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null); + mAccountCreator.setUsername(userName); + mAccountCreator.setDomain("yun"); + mAccountCreator.setPassword(password); + mAccountCreator.setTransport(TransportType.Udp); + + ProxyConfig prxCfg = mAccountCreator.createProxyConfig(); + prxCfg.enableQualityReporting(false); + prxCfg.setQualityReportingCollector(null); + prxCfg.setQualityReportingInterval(0); + prxCfg.enableRegister(true); + prxCfg.setServerAddr("sip:139.159.157.75:46000;transport=udp"); + + mLinphoneCore.addProxyConfig(prxCfg);//娣诲姞浠g悊閰嶇疆銆傚鏋滃惎鐢ㄤ簡娉ㄥ唽锛岃繖灏嗗紑濮嬪湪浠g悊涓婃敞鍐屻�� + mLinphoneCore.addAuthInfo(authInfo);//娣诲姞璁よ瘉淇℃伅鍒�,璇ヤ俊鎭墖娈靛皢鍦ㄦ墍鏈夐渶瑕佺殑SIP浜嬪姟涓娇鐢ㄨ韩浠介獙璇� + mLinphoneCore.setDefaultProxyConfig(prxCfg);//璁剧疆榛樿浠g悊銆� + } + + /** + * 鍛煎彨,鍏ㄨ閫氬彲瑙嗗璁查渶瑕佸皢 澶栧嚭浠g悊鏈嶅姟鍣ㄦ墦寮�锛屾墠鑳戒娇鐢� 绌洪棿鍙峰懠鍙紱 + * 鏆傛椂娌℃壘鍒版�庝箞鎵撳紑锛屾墍浠ラ渶瑕佹墜鍔ㄥ姞涓妏roxy */ public Call startSingleCallingTo(String userName, boolean isVideoCall) { Core mLinphoneCore = HDLLinphoneService.getCore(); - if(mLinphoneCore == null) return null; + if (mLinphoneCore == null) return null; Call call = null; Core core = HDLLinphoneService.getCore(); - if(core != null) { + if (core != null) { Address addressToCall = core.interpretUrl(userName); CallParams params = core.createCallParams(null); @@ -411,7 +473,7 @@ */ public void acceptCall() { try { - if(HDLLinphoneService.getCore() == null) return; + if (HDLLinphoneService.getCore() == null) return; Call currentCall = HDLLinphoneService.getCore().getCurrentCall(); CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall); params.enableVideo(true); @@ -427,7 +489,7 @@ */ public void acceptCallWithVideo(boolean enableVideo) { try { - if(HDLLinphoneService.getCore() == null) return; + if (HDLLinphoneService.getCore() == null) return; Call currentCall = HDLLinphoneService.getCore().getCurrentCall(); CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall); params.enableVideo(enableVideo); @@ -443,7 +505,7 @@ */ public void hangUp() { Core mLinphoneCore = HDLLinphoneService.getCore(); - if(mLinphoneCore == null) return; + if (mLinphoneCore == null) return; Call currentCall = mLinphoneCore.getCurrentCall(); if (currentCall != null) { // mLinphoneCore.terminateCall(currentCall); @@ -462,7 +524,7 @@ */ public void toggleMicro(boolean isMicMuted) { Core mLinphoneCore = HDLLinphoneService.getCore(); - if(mLinphoneCore == null) return; + if (mLinphoneCore == null) return; mLinphoneCore.enableMic(!isMicMuted); } @@ -481,7 +543,7 @@ private void routeAudioToSpeakerHelper(boolean speakerOn) { org.linphone.core.tools.Log.w("[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece")); try { - if(HDLLinphoneService.getCore() == null) return; + if (HDLLinphoneService.getCore() == null) return; if (HDLLinphoneService.getCore().getCallsNb() == 0) return; Call currentCall = HDLLinphoneService.getCore().getCurrentCall(); if (currentCall == null) currentCall = HDLLinphoneService.getCore().getCalls()[0]; @@ -517,6 +579,7 @@ /** * 璁剧疆鎾斁View + * * @param o */ private void setVideoWindow(Object o) { @@ -525,6 +588,7 @@ linphoneCore.setNativeVideoWindowId(o); } } + /** * 绉婚櫎鎾斁View */ @@ -537,6 +601,7 @@ /** * 璁剧疆鏈満鎽勫儚澶撮噰闆嗙殑View + * * @param o */ private void setPreviewWindow(Object o) { @@ -545,6 +610,7 @@ linphoneCore.setNativePreviewWindowId(o); } } + /** * 绉婚櫎瑙嗛閲囬泦View */ @@ -559,9 +625,9 @@ * 鑾峰彇褰撳墠閫氳瘽鐘舵�� */ public Call.State getCallState() { - if(HDLLinphoneService.getInstance() == null) { + if (HDLLinphoneService.getInstance() == null) { return null; - }else { + } else { return HDLLinphoneService.getInstance().getCurrentCallState(); } } @@ -570,9 +636,9 @@ * 鑾峰彇褰撳墠閫氳瘽鐘舵�佹槸鍚︿负鏉ョ數涓� */ public boolean isIncomingReceivedCallState() { - if(HDLLinphoneService.getInstance() == null || HDLLinphoneService.getInstance().getCurrentCallState() == null){ + if (HDLLinphoneService.getInstance() == null || HDLLinphoneService.getInstance().getCurrentCallState() == null) { return false; - }else{ + } else { return (HDLLinphoneService.getInstance().getCurrentCallState() == Call.State.IncomingReceived); } } @@ -586,6 +652,7 @@ /** * 璁剧疆鏄惁鑷姩璺宠浆鍛煎彨椤甸潰鏍囧織 + * * @param autoJumpCallView */ public void setAutoJumpCallView(boolean autoJumpCallView) { @@ -630,6 +697,7 @@ /** * 鑾峰彇onHDLLinphoneCallListener * 鎺ュ惉銆佹寕鏂�佸紑閿佺瓑 Listener瀹炵幇 + * * @return OnHDLLinphoneCallListener */ public OnHDLLinphoneCallListener getOnHDLLinphoneCallListener() { @@ -638,6 +706,7 @@ /** * 璁剧疆onHDLLinphoneCallListener + * * @param onHDLLinphoneCallListener */ public void setOnHDLLinphoneCallListener(OnHDLLinphoneCallListener onHDLLinphoneCallListener) { -- Gitblit v1.8.0