我目前正在开发一个voip/sip呼叫的应用程序但是我不知道为什么我不能注册我的registrationListener,我不知道问题是什么我使用星号作为SIP提供商;
这是我的代码
主要活动
public class MainActivity extends AppCompatActivity {
private static final int CALL_ADDRESS = 1;
Button Connect_Button;
public SipManager manager = null;
public SipProfile MyProfile = null;
public String sipAddress = null;
public CommsController cc;
public Context ctx = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Connect_Button = (Button) findViewById(R.id.ConnectB);
cc = new CommsController();
cc.createManager(this);
cc.createProfile("example","192.168.1.29","54321");
cc.openProfile(ctx);
try {
System.out.println("+++ IS API SUPPORTED: " + cc.getManager().isApiSupported(this));
System.out.println("+++ IS VOIP SUPORTED: " + cc.getManager().isVoipSupported(this));
System.out.println("+++ MANAGER INSTANCE: " + cc.getManager().toString());
boolean isOpened = cc.getManager().isOpened(cc.getMe().getUriString());
System.out.println("+++ IS OPENED: "+isOpened);
if(isOpened){
cc.createRegistrationListener();
cc.getManager().register(cc.getMe(), 30000, cc.getSrl());
}
}catch(SipException sipex){
System.out.println(sipex.getCause()+", "+ sipex.getMessage());
}
}
public Context getContext(){return ctx;}
public CommsController getCc() {
return cc;
}
}
控制器
public class CommsController {
public String sipAddress = null;
public SipManager manager = null;
public SipProfile me = null;
public SipAudioCall call = null;
public Context ctx;
private PendingIntent pendingIntent;
public SipRegistrationListener srl;
private static final int CALL_ADDRESS = 1;
private static final int SET_AUTH_INFO = 2;
private static final int UPDATE_SETTINGS_DIALOG = 3;
private static final int HANG_UP = 4;
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) {
// Do something.
}
};
public void createManager(Context context) {
if (manager == null) {
manager = SipManager.newInstance(context);
}
}
public boolean createProfile(String uname, String domain, String pass){
try {
SipProfile.Builder builder = new SipProfile.Builder(uname, domain);
builder.setPassword(pass);
builder.setProtocol("TCP");
builder.setPort(5060);
me = builder.build();
setMe(me);
System.out.println("+++ User Profile = CREATED");
return true;
} catch (ParseException e) {
e.printStackTrace();
System.out.println("+++ User Profile = FAILED");
} catch (java.text.ParseException e) {
e.printStackTrace();
}
return false;
}
public void openProfile(Context context){
try {
System.out.println("+++ ATTEMPTING TO OPEN PROFILE: " + me.getUriString());
Intent intent = new Intent();
intent.setAction("android.SipDemo.INCOMING_CALL");
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, Intent.FILL_IN_DATA);
manager.open(getMe(),pendingIntent,srl);
System.out.println("+++ IS OPEN IN CC: " +manager.isOpened(getMe().getUriString()));
} catch (SipException e) {
e.printStackTrace();
System.out.println("+++ Profile Registration = FAILED");
}
}
public void createRegistrationListener(){
System.out.println("+++ CREATING REG LISTENER...");
srl = new SipRegistrationListener() {
@Override
public void onRegistering(String localProfileUri) {
System.out.println("+++ REGISTERING...");
}
@Override
public void onRegistrationDone(String localProfileUri, long expiryTime) {
System.out.println("+++ READY");
}
@Override
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
System.out.println("+++ REGISTRATION FAILED. CHECK SETTINGS. ERROR: "+ errorCode + " MESSAGE: " +errorMessage);
}
};
}
public SipRegistrationListener getSrl(){
return srl;
}
public void closeProfile(SipProfile toClose){
if(manager==null){
return;
}
try {
if (manager != null) {
manager.close(toClose.getUriString());
System.out.println("PROFILE CLOSED: " +toClose.getUriString());
}
} catch (Exception ee) {
ee.printStackTrace();
System.out.println("FAILED TO CLOSE LOCAL PROFILE: "+ toClose.toString());
}
}
public void logOut(){
try {
System.out.println("+++ DEREGISTERING...");
manager.close(me.getUriString());
}catch(SipException se){
System.out.println("+++ DEREGISTRATION FAILED");
se.printStackTrace();
}
}
public void makeCall(String toCall){
try {
call = manager.makeAudioCall(me.getUriString(), toCall, listener, 30);
} catch (SipException e) {
e.printStackTrace();
}
}
public void setMe(SipProfile me) {
this.me = me;
}
public SipProfile getMe() {
return me;
}
public SipManager getManager() {
return manager;
}
public void setManager(SipManager manager) {
this.manager = manager;
}
}
输出
I/System.out: +++ User Profile = CREATED
I/System.out: +++ ATTEMPTING TO OPEN PROFILE: sip:example@192.168.1.29;transport=tcp
I/System.out: +++ IS OPEN IN CC: true
I/System.out: +++ IS API SUPPORTED: true
I/System.out: +++ IS VOIP SUPORTED: true
I/System.out: +++ MANAGER INSTANCE: android.net.sip.SipManager@41bccd58
I/System.out: +++ IS OPENED: true
I/System.out: +++ CREATING REG LISTENER...
D/OpenGLRenderer: Enabling debug mode 0
I/System.out: +++ REGISTRATION FAILED. CHECK SETTINGS. ERROR: -4 MESSAGE: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
请帮助我...
没有办法回答这个问题,因为这是调试问题,而不是问题。
提出的调试方式如下:
- 获取100%工作的软电话,例如Zoiper或Xlite
- 将其连接到星号。
- 获取Wireshark或TCPDUMP并获得SIP数据包的转储
- 获得您的项目的转储
- 比较。