向Freeswitch注册时,为什么会出现IN_PROGRESS错误?

时间:2018-10-25 19:39:52

标签: java android sip voip freeswitch

我制作了android sip应用程序,并使用Freeswitch进行voip。 当我尝试在Freeswitch中注册用户时,收到错误IN_PROGRESS(-9)“客户端正在事务中,无法启动新事务。”这是:android.net.sip.SipException:无法创建SipSession;网络不可用? 我在本地主机上执行。 另外,当我从其他Sip应用程序(Zoiper)注册用户时,一切正常。 会是什么?

我的课程:

    public SIPObject(Context mainActivity, String username, String domain, String password){
        this.mainActivity = mainActivity;
        if (mSipManager == null) {
            mSipManager = SipManager.newInstance(mainActivity);
        }
        SipProfile.Builder builder = null;
        try {
            builder = new SipProfile.Builder(username, domain);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        builder.setPassword(password);
        builder.setAuthUserName("1010");
        mSipProfile = builder.build();
        Intent intent = new Intent();
        intent.setAction("ru.tenet.apdu.INCOMING_CALL");
        pi = PendingIntent.getBroadcast(mainActivity, 0, intent, Intent.FILL_IN_DATA);
        try {
            SipRegistrationListener listener = new SipRegistrationListener() {
                @Override
                public void onRegistering(String localProfileUri) {
                    updateStatus("Registering with SIP Server...");
                }
                @Override
                public void onRegistrationDone(String localProfileUri, long expiryTime) {
                    updateStatus("Ready");
                }
                    @Override
                public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
                    updateStatus("Registration failed with error:\n" + SipErrorCode.toString(errorCode) +"\n"+errorMessage);
                    if(errorCode == SipErrorCode.IN_PROGRESS) {
                        closeLocalProfile();
                        try {
                            mSipManager.open(mSipProfile, pi, null);
                        } catch (SipException e) {
                            e.printStackTrace();
                        }
                    }
                }
            };
            mSipManager.open(mSipProfile, pi, null);
            mSipManager.register(mSipProfile, 20, listener);
        } catch (SipException e) {
            e.printStackTrace();
        }
        try {
            mSipManager.setRegistrationListener(mSipProfile.getUriString(),
                    (SipRegistrationListener) listener);
        } catch (SipException e) {
            e.printStackTrace();
        }
        incomeCall();
    }
       public void setSipAudioCall(SipAudioCall c){
        call = c;
    }
    public void incomeCall(){
        Intent intent = new Intent();
        intent.setAction("android.SipDemo.INCOMING_CALL");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mainActivity, 0, intent, Intent.FILL_IN_DATA);
        checkRegister();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            call = mSipManager.makeAudioCall(mSipProfile.getUriString(), String.valueOf(peepSipProfile), listener, 30);
        } catch (SipException e) {
            e.printStackTrace();
        }
    }

    public void checkRegister(){
        try {
            mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
                public void onRegistering(String localProfileUri) {
                    updateStatus("Ready");
                }

                public void onRegistrationDone(String localProfileUri, long expiryTime) {
                    updateStatus("Ready");
                }

                public void onRegistrationFailed(String localProfileUri, int errorCode,
                                                 String errorMessage) {
                    updateStatus("Registration failed.  Please check settings.");
                    Log.d("sip","Registration failed.  Please check settings. " +errorCode+"  "+ errorMessage);
                }
            });
        } catch (SipException e) {
            e.printStackTrace();
            Log.d("sip","SipException  checkRegister "  +e);
        }
    }

    public void updateStatus(String m){
        Log.d("sip", " " + m);
    }

    @SuppressLint("LongLogTag")
    public void closeLocalProfile() {
        if (mSipManager == null) {
            return;
        }
        try {
            if (mSipProfile != null) {
                mSipManager.close(mSipProfile.getUriString());
            }
        } catch (Exception ee) {
            Log.d("sip", "Failed to close local profile.", ee);
        }
    }
    public void makeCall() {
        SipAudioCall.Listener listener = new SipAudioCall.Listener() {

            @Override
            public void onCallEstablished(SipAudioCall call) {
                call.startAudio();
                call.setSpeakerMode(true);
                call.toggleMute();
            }

            @Override

            public void onCallEnded(SipAudioCall call) {
                try {
                    call.endCall();
                } catch (SipException e) {
                    e.printStackTrace();
                }
                call.close();
            }
        };
    }

}






 public class IncomingCallReceiver extends BroadcastReceiver {
    /**
     * Processes the incoming call, answers it, and hands it over to the
     * WalkieTalkieActivity.
     * @param context The context under which the receiver is running.
     * @param intent The intent being received.
     */
    public SIPObject sipObject ;
    MainActivity mainActivity;

    public IncomingCallReceiver(Context context) {
        sipObject = new SIPObject(context, "1007", "192.168.1.3:5060", "4444");
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("sip", "onReceive");
        SipAudioCall incomingCall = null;
        mainActivity = (MainActivity) context;
        try {
            SipAudioCall.Listener listener = new SipAudioCall.Listener() {
                @Override
                public void onRinging(SipAudioCall call, SipProfile caller) {
                    try {
                        call.answerCall(30);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            Thread.sleep(5000);
            sipObject = new SIPObject(context, "1007", "192.168.1.3:5060", "4444");
            Log.d("sip", "sipObject = new SIPObject");
            incomingCall = sipObject.mSipManager.takeAudioCall(intent, listener);
            incomingCall.answerCall(30);
            incomingCall.startAudio();
            incomingCall.setSpeakerMode(true);
            if(incomingCall.isMuted()) {
                incomingCall.toggleMute();
            }
            sipObject.call = incomingCall;
            sipObject.setSipAudioCall(incomingCall);
        } catch (Exception e) {
            if (incomingCall != null) {
                incomingCall.close();
                Log.d("sip", "incomingCall.close(); " + e);
            }
        }
    }
}

0 个答案:

没有答案