环境如下:我们的网络上有 PC 和 Cisco VoIP 电话。网络上有一个允许 VoIP 电话呼叫的电话开关,但我认为该开关与项目的这一部分无关。
这是我第一次将 VoIP 包含到我的软件中,所以我尝试先让我的 PC 向我的 VoIP 电话发出呼叫。从 PC 上,我可以 ping 电话的 IP 地址并得到响应,所以我应该能够与它通信。
到目前为止,我希望电话会响起。我在 Java 中使用 mjsip,我收到一条呼叫失败消息,原因是“请求超时”并且没有响铃。对于接听电话后会发生什么,我还没有完成任何代码,但我想至少让它响起。
我希望有更多 VoIP 经验的人可以验证或排除我的不当行为,或者能够揭露更多的陷阱。例如,我什至可以期望电话仅仅因为它是 VoIP 电话而响应 sip 呼叫吗?即使它是同一网络上的 VoIP 电话,我是否必须通过电话交换机?只是我的代码有问题吗?
假设我已经正确完成了该代码,它正在启动一个 sip 堆栈,设置用户配置文件,并尝试调用与手机 IP 和端口 5060 相对应的 sip 地址(谷歌告诉我 sip 端口通常是 5060 )。
public class SIPTest implements UserAgentListener, SipProviderListener
{
public static void main(String[] args)
{
if(!SipStack.isInit())
SipStack.init();
SipProvider sipProvider = new SipProvider("127.0.0.1", 5060);
UserAgentProfile profile = new UserAgentProfile();
profile.audio = true;
profile.hangup_time = 10;
profile.user = "testuser";
profile.keepalive_time = 8000;
final UserAgent userAgent = new UserAgent(sipProvider, profile, new SIPTest());
sipProvider.addPromiscuousListener(new SIPTest());
userAgent.call(new NameAddress(new SipURL("172.16.1.250", 5060)));
System.out.println("end ...");
}
/**
* begin SipProviderListener
**/
public void onReceivedMessage(SipProvider sip_provider,
Message message)
{
if (message.isInfo())
{
System.out.println("Promisque onReceivedMessage ... message " + message.getMethodId().toString() + "\n body = " + message.getBody());
}
}
/**
* end SipProviderListener
**/
/**
* begin UserAgentListener
**/
public void onUaCallAccepted(UserAgent arg0)
{
System.out.println("onUaCallAccepted ...");
}
public void onUaCallCancelled(UserAgent arg0)
{
System.out.println("onUaCallCancelled ...");
}
public void onUaCallClosed(UserAgent arg0)
{
System.out.println("onUaCallClosed ...");
}
public void onUaCallFailed(UserAgent arg0, String reason)
{
System.out.println("onUaCallFailed ...");
System.out.println("\t" + arg0);
System.out.println("\t" + reason);
}
public void onUaCallIncoming(UserAgent arg0,
NameAddress arg1, NameAddress arg2)
{
System.out.println("onUaCallIncoming ...");
System.out.println("from " + arg2.toString());
System.out.println("to " + arg1.toString());
arg0.accept();
System.out.println("Call accepted ...");
}
public void onUaCallProgress(UserAgent ua)
{
System.out.println("onUaCallProgress ...");
}
public void onUaCallRinging(UserAgent arg0)
{
System.out.println("onUaCallRinging ...");
}
public void onUaCallTransferred(UserAgent arg0)
{
System.out.println("onUaCallTrasferred ...");
}
public void onUaIncomingCall(UserAgent ua, NameAddress callee, NameAddress caller, Vector media_descs)
{
System.out.println("onUaIncomingCall ...");
}
public void onUaMediaSessionStarted(UserAgent ua, String type, String codec)
{
System.out.println("onUaMediaSessionStopped ...");
}
public void onUaMediaSessionStopped(UserAgent ua, String type)
{
System.out.println("onUaMediaSessionStopped ...");
}
public void onUaRegistrationFailed(UserAgent ua, String result)
{
System.out.println("onUaRegistrationFailed ...");
}
public void onUaRegistrationSucceeded(UserAgent ua, String result)
{
System.out.println("onUaRegistrationSucceeded ...");
}
/**
* end UserAgent
**/
}
如果我运行它,以下是我得到的输出。
ExtendedAudioSystem: Supported: PCM_SIGNED PCM_UNSIGNED ALAW ULAW PCM_SIGNED PCM
_UNSIGNED PCM_FLOAT
ExtendedAudioSystem: TargetDataLine: PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes
/frame, little-endian
ExtendedAudioSystem: Supported: PCM_SIGNED PCM_UNSIGNED ALAW ULAW PCM_SIGNED PCM
_UNSIGNED PCM_FLOAT
ExtendedAudioSystem: SourceDataLine: PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes
/frame, little-endian
end ...
onUaCallFailed ...
local.ua.UserAgent@283bbb6
Request Timeout