From 848cbfebefab08cc49b0285155edb84463aed862 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期三, 13 十一月 2024 17:19:53 +0800 Subject: [PATCH] 提交home项目所用可视对讲sdk --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java | 105 ++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 77 insertions(+), 28 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 37ef91b..4410e57 100644 --- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java +++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java @@ -1,13 +1,17 @@ package com.hdl.hdllinphonesdk; +import static java.lang.Thread.sleep; + +import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; 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; @@ -21,16 +25,13 @@ import org.linphone.core.AuthInfo; import org.linphone.core.Call; import org.linphone.core.CallParams; +import org.linphone.core.ChatMessage; +import org.linphone.core.ChatRoom; import org.linphone.core.Core; import org.linphone.core.CoreException; import org.linphone.core.Factory; 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. @@ -60,12 +61,14 @@ public static final String KEY_TITLE_NAME = "lpTitleName"; public static final String KEY_SIP_ACCOUNT = "lpSipAccount"; public static final String HDLLinphoneKitNAME = "HDLLinphoneKit"; + public static final String KEY_CALL_ALL_REJECTION = "callAllRejection"; private volatile static HDLLinphoneKit instance; private Context viewContext; private ServiceWaitThread mServiceWaitThread; private String mUsername, mPassword, mServerIP; // private TextureView mRenderingView, mPreviewView; private boolean isAutoJumpCallView;//鏄惁鑷姩璺宠浆鍛煎彨椤甸潰 + private String intercomeType; private HDLLinphoneKit() { @@ -144,7 +147,7 @@ @Override public void incomingCall(Call linphoneCall) { super.incomingCall(linphoneCall); - Log.d("HDLLinphoneKit","------incomingCall------"); + Log.d("HDLLinphoneKit", "------incomingCall------"); if (linphoneCall != null) { String callUsername = linphoneCall.getRemoteAddress().getUsername(); HDLLog.I("鏉ョ數鍙风爜锛�" + callUsername); @@ -163,21 +166,21 @@ @Override public void outgoingInit() { super.outgoingInit(); - Log.d("HDLLinphoneKit","------outgoingInit------"); + Log.d("HDLLinphoneKit", "------outgoingInit------"); } @Override public void callConnected() { super.callConnected(); // 瑙嗛閫氳瘽榛樿鍏嶆彁锛岃闊抽�氳瘽榛樿闈炲厤鎻� - Log.d("HDLLinphoneKit","------callConnected------"); + Log.d("HDLLinphoneKit", "------callConnected------"); toggleSpeaker(true); } @Override public void callEnd() { super.callEnd(); - Log.d("HDLLinphoneKit","------callEnd------"); + Log.d("HDLLinphoneKit", "------callEnd------"); // context.sendBroadcast(new Intent(HDLLinphoneIntercomActivity.RECEIVE_FINISH_VIDEO_ACTIVITY)); } }); @@ -196,6 +199,24 @@ } } + private HDLLinphoneService mService; + private final ServiceConnection connection = new ServiceConnection() { + + @Override + public void onServiceConnected(ComponentName name, IBinder ibinder) { + HDLLinphoneService.LinphoneBinder binder = (HDLLinphoneService.LinphoneBinder) ibinder; + mService = binder.getService(); + //鍒濆鍖� + mService.initCore(); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + mService = null; + } + + }; + /** * 寮�鍚湇鍔� * @@ -206,12 +227,8 @@ if (!HDLLinphoneService.isReady()) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(context, HDLLinphoneService.class); - context.startService(intent); -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { -// context.startForegroundService(intent);//瑙e喅android8.0浠ヤ笂鏃犳硶鍚姩鏈嶅姟鐨勯棶棰� -// } else { -// context.startService(intent); -// } + context.bindService(intent, connection, Context.BIND_AUTO_CREATE); + } } catch (Exception e) { e.printStackTrace(); @@ -251,7 +268,12 @@ mUsername = username; mPassword = password; mServerIP = serverIP; + intercomeType = inter_type; login(inter_type); + } + + public String getIntercomeType() { + return intercomeType; } /** @@ -352,6 +374,8 @@ * 鐧诲綍 SIP 鏈嶅姟鍣� */ private void loginToServer(String inter_type) { + Log.e("==========", "loginToServer: "); + try { if (mUsername == null || mPassword == null || mServerIP == null) { throw new RuntimeException("The sip account is not configured."); @@ -380,12 +404,12 @@ Core mLinphoneCore = HDLLinphoneService.getCore(); if (mLinphoneCore == null) return; - AuthInfo authInfo = Factory.instance().createAuthInfo(name, null, password, null, null, host); + AuthInfo authInfo = Factory.instance().createAuthInfo(name, name, password, null, null, host); AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null); mAccountCreator.setUsername(name); mAccountCreator.setDomain(host); mAccountCreator.setPassword(password); - mAccountCreator.setTransport(TransportType.Udp); + mAccountCreator.setTransport(TransportType.Tcp); ProxyConfig prxCfg = mAccountCreator.createProxyConfig(); prxCfg.enableQualityReporting(false); @@ -419,7 +443,8 @@ prxCfg.setQualityReportingCollector(null); prxCfg.setQualityReportingInterval(0); prxCfg.enableRegister(true); - prxCfg.setServerAddr("sip:139.159.157.75:46000;transport=udp"); + //鍏ㄨ閫氶渶瑕佽缃浐瀹氫唬鐞嗘湇鍔″櫒ip + prxCfg.setServerAddr("sip:" + domain + ";transport=udp"); mLinphoneCore.addProxyConfig(prxCfg);//娣诲姞浠g悊閰嶇疆銆傚鏋滃惎鐢ㄤ簡娉ㄥ唽锛岃繖灏嗗紑濮嬪湪浠g悊涓婃敞鍐屻�� mLinphoneCore.addAuthInfo(authInfo);//娣诲姞璁よ瘉淇℃伅鍒�,璇ヤ俊鎭墖娈靛皢鍦ㄦ墍鏈夐渶瑕佺殑SIP浜嬪姟涓娇鐢ㄨ韩浠介獙璇� @@ -451,10 +476,12 @@ if (addressToCall != null) { call = core.inviteAddressWithParams(addressToCall, params); - // 璁剧疆澶栨斁 - for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { - if (audioDevice.getType() == AudioDevice.Type.Speaker) { - call.setOutputAudioDevice(audioDevice); + if (call != null) { + // 璁剧疆澶栨斁 + for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { + if (audioDevice.getType() == AudioDevice.Type.Speaker) { + call.setOutputAudioDevice(audioDevice); + } } } } @@ -488,7 +515,7 @@ params.enableLowBandwidth(false); params.setAudioBandwidthLimit(0); // disable limitation currentCall.acceptWithParams(params); - Log.d("HDLLinphoneKit","---acceptCall= "); + Log.d("HDLLinphoneKit", "---acceptCall= "); } catch (Exception e) { e.printStackTrace(); @@ -528,6 +555,28 @@ } } + public void sendSipMessage(String sipAccount, String sipAddress, String message) { + try { + Core mLinphoneCore = HDLLinphoneService.getCore(); + if (mLinphoneCore == null) return; + + //瀵规柟鐨剆ip鍦板潃,sipAddress:"sip:瀵规柟璐﹀彿@鏈嶅姟鍣ㄥ湴鍧�" + Address address = mLinphoneCore.interpretUrl("sip:" + sipAccount + "@" + sipAddress); + + //寤虹珛瀵硅瘽 + ChatRoom chatRoom = mLinphoneCore.getChatRoom(address); + + //鍒涘缓娑堟伅 + ChatMessage chatMessage = chatRoom.createMessageFromUtf8(message); + + //鍙戦�佹秷鎭� + chatMessage.send(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * 鏄惁闈欓煶 * @@ -552,7 +601,7 @@ * 璁剧疆澶栨斁璁惧 */ private void routeAudioToSpeakerHelper(boolean speakerOn) { - Log.d("HDLLinphoneKit","璁剧疆澶栨斁璁惧[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece")); + Log.d("HDLLinphoneKit", "璁剧疆澶栨斁璁惧[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece")); try { if (HDLLinphoneService.getCore() == null) return; if (HDLLinphoneService.getCore().getCallsNb() == 0) return; @@ -561,14 +610,14 @@ if (currentCall == null) return; for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { - Log.d("HDLLinphoneKit","audioDevice.getType()= " + audioDevice.getType()); + Log.d("HDLLinphoneKit", "audioDevice.getType()= " + audioDevice.getType()); } for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { - Log.d("HDLLinphoneKit","璁剧疆澶栨斁璁惧speakerOn=" + speakerOn + " audioDevice.getType()=" + audioDevice.getType()); + Log.d("HDLLinphoneKit", "璁剧疆澶栨斁璁惧speakerOn=" + speakerOn + " audioDevice.getType()=" + audioDevice.getType()); if (speakerOn && audioDevice.getType() == AudioDevice.Type.Speaker) { currentCall.setOutputAudioDevice(audioDevice); - Log.d("HDLLinphoneKit","AudioDevice.Type.Speaker"); + Log.d("HDLLinphoneKit", "AudioDevice.Type.Speaker"); return; } else if (!speakerOn && audioDevice.getType() == AudioDevice.Type.Earpiece) { currentCall.setOutputAudioDevice(audioDevice); -- Gitblit v1.8.0