以下是我的拨号器的代码。我可以使用以下代码成功注册和连接呼叫。但是,呼叫连接后只有另一端(非sipml5)可以听到声音。但是,sipml5端听不到任何声音。但是,我可以使用sipml5网站(sipml5.org/call.htm)中的sipml5客户端连接并传递语音。我必须做错事,但无法弄清楚是什么。
<script src="api/SIPml-api.js" type="text/javascript"> </script>
<script type="text/javascript">
var readyCallback = function(e){
createSipStack(); // see next section
};
var errorCallback = function(e){
onsole.error('Failed to initialize the engine: ' + e.message);
}
SIPml.init(readyCallback, errorCallback);
var sipStack;
var callSession;
function eventsListener(e){
console.info('Change of status|Server response: '+e.type+':'+e.message+':'+e.
session+':'+e.description);
if(e.type == 'started'){
login();
}
else if(e.type == 'i_new_message'){ // incoming new SIP MESSAGE (SMS-like)
acceptMessage(e);
}
else if(e.type == 'i_new_call'){ // incoming audio/video call
if(confirm("Incomming Call Request! Do you accept?")){
acceptCall(e);
}else{
e.newSession.reject()
}
}
else if(e.type == 'connected'){
if(e.session == registerSession){
setStatus(e.type,'Registered...');
}else{
setStatus(e.type,e.description);
}
}
else if(e.type == 'i_ao_request' && e.description == 'Ringing' ){
document.getElementById('call').value = 'End Call';
setStatus(e.type,e.description);
}
else if(e.type == 'terminated' || e.type == 'terminating'){
if(e.session == registerSession){
setStatus('Unable to Register');
}else{
setStatus(e.type,e.description);
}
}
}
function createSipStack(){
sipStack = new SIPml.Stack({
realm: 'foo.bar.com',
impi: 'usertest',
impu: 'sip:usertest@foo.bar.com',
password: '1234',
display_name: 'alice',
websocket_proxy_url: 'ws://11.11.11.0:8080',
enable_rtcweb_breaker: false,
events_listener: { events: '*', listener: eventsListener },
sip_headers: [ // optional
{ name: 'User-Agent', value: 'IM-client/OMA1.0 sipML5-v1.0.0.0' },
{ name: 'Organization', value: 'SuperCops.us' }
]
}
);
}
sipStack.start();
function login(){
registerSession = sipStack.newSession('register', {
events_listener: { events: '*', listener: eventsListener } // optional: '*' means all events
});
registerSession.register();
}
function makeCall(){
var number = document.getElementById('number').value;
if(number == ''){
alert('No number entered');
}
else if(document.getElementById('call').value == 'End Call'){
callSession.hangup();
}else{
setStatus('Trying','Trying to call:'+numberFilter(number));
callSession = sipStack.newSession('call-audio',{
events_listener: { events: '*', listener: eventsListener }
});
callSession.call(numberFilter(number));
}
}
function acceptCall(event){
callSession = event.newSession;
/*('accept',{
events_listener: { events: '*', listener: eventsListener }
});*/
callSession.accept();
eventsListener(callSession);
setStatus('connected','In Call');
}
function setStatus(type,status){
document.getElementById('status').innerHTML = status;
if(type == 'terminated' || type == 'terminating'){
document.getElementById('call').value = 'Call';
}else if(status == 'Ringing' || status == 'Ringing' || status == 'In Call' || type == 'Trying'){
document.getElementById('call').value = 'End Call';
}
}
function numberFilter(number){
return number;
}