lss
2022-05-26 ff886457f58791eea4532f6167af51184d9dfe43
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,12 +27,36 @@
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";
@@ -47,6 +73,7 @@
    /**
     * getInstance
     *
     * @return HDLLinphoneKit
     */
    public static synchronized HDLLinphoneKit getInstance() {
@@ -76,6 +103,7 @@
    /**
     * 初始化Linphone
     *
     * @param context
     */
    public void initLinphone(Context context) {
@@ -83,7 +111,6 @@
        if (!HDLLinphoneService.isReady()) {
            CheckIfNeedstartService();
        } else {
        }
    }
@@ -98,7 +125,6 @@
                super.registrationOk();
                HDLLog.e(HDLLinphoneKitNAME, "registrationOk: ");
                callBackRegistrationOk(viewContext);
            }
            @Override
@@ -159,9 +185,13 @@
     * 跳转打开呼叫页面
     */
    public void gotoHDLLinphoneIntercomActivity() {
        try {
        Intent intent = new Intent(viewContext, HDLLinphoneIntercomActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        viewContext.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
@@ -215,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);
    }
    /**
@@ -228,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);
@@ -242,10 +271,8 @@
    /**
     * 登录到 SIP 服务器
     */
    public void login() {
        new Thread(new Runnable() {
            @Override
            public void run() {
    public void login(String inter_type) {
        new Thread(() -> {
                while (!HDLLinphoneService.isReady()) {
                    try {
                        sleep(80);
@@ -253,8 +280,7 @@
                        e.printStackTrace();
                    }
                }
                loginToServer();
            }
            loginToServer(inter_type);
        }).start();
    }
@@ -323,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.");
            }
            if (inter_type.equals(INTER_PHONE_TYPE_FREEVIEW)) {
                // 全视通可视对讲注册
                freeViewRegisterUserAuth(mUsername, mPassword, mServerIP);
            } else {
                // 其他可视对讲注册
            registerUserAuth(mUsername, mPassword, mServerIP);
            }
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    /**
     * 提交账号和密码注册到服务器
     *
@@ -345,9 +378,7 @@
        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, null, password, null, null, host);
        AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null);
        mAccountCreator.setUsername(name);
        mAccountCreator.setDomain(host);
@@ -365,7 +396,37 @@
    }
    /**
     * 呼叫
     * 提交账号和密码注册到全视通服务器
     *
     * @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);//添加代理配置。如果启用了注册,这将开始在代理上注册。
        mLinphoneCore.addAuthInfo(authInfo);//添加认证信息到,该信息片段将在所有需要的SIP事务中使用身份验证
        mLinphoneCore.setDefaultProxyConfig(prxCfg);//设置默认代理。
    }
    /**
     * 呼叫,全视通可视对讲需要将 外出代理服务器打开,才能使用 空间号呼叫;
     * 暂时没找到怎么打开,所以需要手动加上proxy
     */
    public Call startSingleCallingTo(String userName, boolean isVideoCall) {
        Core mLinphoneCore = HDLLinphoneService.getCore();
@@ -518,6 +579,7 @@
    /**
     * 设置播放View
     *
     * @param o
     */
    private void setVideoWindow(Object o) {
@@ -526,6 +588,7 @@
            linphoneCore.setNativeVideoWindowId(o);
        }
    }
    /**
     * 移除播放View
     */
@@ -538,6 +601,7 @@
    /**
     * 设置本机摄像头采集的View
     *
     * @param o
     */
    private void setPreviewWindow(Object o) {
@@ -546,6 +610,7 @@
            linphoneCore.setNativePreviewWindowId(o);
        }
    }
    /**
     * 移除视频采集View
     */
@@ -587,6 +652,7 @@
    /**
     * 设置是否自动跳转呼叫页面标志
     *
     * @param autoJumpCallView
     */
    public void setAutoJumpCallView(boolean autoJumpCallView) {
@@ -631,6 +697,7 @@
    /**
     * 获取onHDLLinphoneCallListener
     * 接听、挂断、开锁等 Listener实现
     *
     * @return OnHDLLinphoneCallListener
     */
    public OnHDLLinphoneCallListener getOnHDLLinphoneCallListener() {
@@ -639,6 +706,7 @@
    /**
     * 设置onHDLLinphoneCallListener
     *
     * @param onHDLLinphoneCallListener
     */
    public void setOnHDLLinphoneCallListener(OnHDLLinphoneCallListener onHDLLinphoneCallListener) {