Commit 7692b193 authored by Dele Olajide's avatar Dele Olajide Committed by dele

work-in-progress

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13758 b35dd754-fafc-0310-a699-88a17e54d16e
parent ca711647
...@@ -109,6 +109,9 @@ ...@@ -109,6 +109,9 @@
{ {
window.connection.rayo.phone( window.connection.rayo.phone(
{ {
codec_name: "PCMU",
stereo_pan: "0",
offHook: function() { offHook: function() {
$("#status").html("Off Hook"); $("#status").html("Off Hook");
}, },
...@@ -131,7 +134,7 @@ ...@@ -131,7 +134,7 @@
if (window.candybar.call == null) // ignore when user has active call if (window.candybar.call == null) // ignore when user has active call
{ {
var cli = headers['caller-name'] ? headers['caller-name']: call.from; var cli = headers.caller_name ? headers.caller_name : call.from;
window.candybar.setUser({ window.candybar.setUser({
name: cli, name: cli,
...@@ -193,7 +196,10 @@ ...@@ -193,7 +196,10 @@
if (prefix == "xmpp:") sipUri = prefix + destination + "@" + domain + "/" + destination; if (prefix == "xmpp:") sipUri = prefix + destination + "@" + domain + "/" + destination;
window.candybar.call = window.connection.rayo.dial("xmpp:" + window.connection.jid, sipUri); window.candybar.call = window.connection.rayo.dial("xmpp:" + window.connection.jid, sipUri, {
codec_name: "PCMU",
});
window.candybar.setUser({ window.candybar.setUser({
name: destination, name: destination,
......
...@@ -132,7 +132,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -132,7 +132,7 @@ Strophe.addConnectionPlugin('rayo',
var that = this; var that = this;
var mixer = "rayo-mixer-" + Math.random().toString(36).substr(2,9); var mixer = "rayo-outgoing-" + Math.random().toString(36).substr(2,9);
var callId = "rayo-call-" + Math.random().toString(36).substr(2,9); var callId = "rayo-call-" + Math.random().toString(36).substr(2,9);
if (to.indexOf("xmpp:") == 0) if (to.indexOf("xmpp:") == 0)
...@@ -146,7 +146,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -146,7 +146,7 @@ Strophe.addConnectionPlugin('rayo',
{ {
var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("dial", {xmlns: Strophe.NS.RAYO_CORE, to: to, from: from}); var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("dial", {xmlns: Strophe.NS.RAYO_CORE, to: to, from: from});
iq.c("header", {name: "call-id", value: callId}).up(); iq.c("header", {name: "call_id", value: callId}).up();
if (headers) if (headers)
{ {
...@@ -212,6 +212,9 @@ Strophe.addConnectionPlugin('rayo', ...@@ -212,6 +212,9 @@ Strophe.addConnectionPlugin('rayo',
//console.log('Rayo plugin _offhook1 ' + mixer); //console.log('Rayo plugin _offhook1 ' + mixer);
var that = this; var that = this;
var codec = (headers && headers.codec_name) ? headers.codec_name : (that.callbacks.codec_name ? that.callbacks.codec_name : "OPUS");
that.pc1 = new webkitRTCPeerConnection(null); that.pc1 = new webkitRTCPeerConnection(null);
that.pc2 = new webkitRTCPeerConnection(null); that.pc2 = new webkitRTCPeerConnection(null);
...@@ -230,7 +233,12 @@ Strophe.addConnectionPlugin('rayo', ...@@ -230,7 +233,12 @@ Strophe.addConnectionPlugin('rayo',
that.pc1.setLocalDescription(desc); that.pc1.setLocalDescription(desc);
var sdpObj1 = WebrtcSDP.parseSDP(desc.sdp); var sdpObj1 = WebrtcSDP.parseSDP(desc.sdp);
if (codec == "PCMU")
sdpObj1.contents[0].codecs = [{clockrate: "8000", id: "0", name: "PCMU", channels: 1}];
else
sdpObj1.contents[0].codecs = [{clockrate: "48000", id: "111", name: "opus", channels: 2}]; sdpObj1.contents[0].codecs = [{clockrate: "48000", id: "111", name: "opus", channels: 2}];
var sdp = WebrtcSDP.buildSDP(sdpObj1); var sdp = WebrtcSDP.buildSDP(sdpObj1);
//console.log(sdp); //console.log(sdp);
that.cryptoSuite = sdpObj1.contents[0].crypto['crypto-suite']; that.cryptoSuite = sdpObj1.contents[0].crypto['crypto-suite'];
...@@ -257,8 +265,8 @@ Strophe.addConnectionPlugin('rayo', ...@@ -257,8 +265,8 @@ Strophe.addConnectionPlugin('rayo',
//console.log('Rayo plugin _offhook2 ' + this.cryptoSuite + " " + this.localCrypto + " " + this.remoteCrypto + " " + mixer); //console.log('Rayo plugin _offhook2 ' + this.cryptoSuite + " " + this.localCrypto + " " + this.remoteCrypto + " " + mixer);
var that = this; var that = this;
var stereo = (headers && headers.stereo) ? headers.stereo : "0"; var stereo = (headers && headers.stereo_pan) ? headers.stereo_pan : (that.callbacks.stereo_pan ? that.callbacks.stereo_pan : "0");
var codec = (headers && headers.codec) ? headers.codec : "OPUS"; var codec = (headers && headers.codec_name) ? headers.codec_name : (that.callbacks.codec_name ? that.callbacks.codec_name : "OPUS");
var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("offhook", {xmlns: Strophe.NS.RAYO_HANDSET, cryptoSuite: that.cryptoSuite, localCrypto: that.localCrypto, remoteCrypto: that.remoteCrypto, codec: codec, stereo: stereo, mixer: mixer}); var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("offhook", {xmlns: Strophe.NS.RAYO_HANDSET, cryptoSuite: that.cryptoSuite, localCrypto: that.localCrypto, remoteCrypto: that.remoteCrypto, codec: codec, stereo: stereo, mixer: mixer});
...@@ -346,7 +354,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -346,7 +354,7 @@ Strophe.addConnectionPlugin('rayo',
var callTo = $(this).attr('to'); var callTo = $(this).attr('to');
var callId = Strophe.getNodeFromJid(from); var callId = Strophe.getNodeFromJid(from);
var mixer = headers['mixer-name'] var mixer = headers['mixer_name']
var call = { var call = {
digit: function(tone) {that.digit(callId, tone);}, digit: function(tone) {that.digit(callId, tone);},
...@@ -396,7 +404,14 @@ Strophe.addConnectionPlugin('rayo', ...@@ -396,7 +404,14 @@ Strophe.addConnectionPlugin('rayo',
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
var callId = Strophe.getNodeFromJid(from);
if (callId.indexOf("rayo-incoming-") == 0)
{
that._onhook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
}
} }
}); });
...@@ -433,7 +448,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -433,7 +448,7 @@ Strophe.addConnectionPlugin('rayo',
{ {
var callId = Strophe.getNodeFromJid(from); var callId = Strophe.getNodeFromJid(from);
if (headers['call-protocol'] == "WebRtc") if (headers['call_protocol'] == "WebRtc")
{ {
if (that.callbacks && that.callbacks.offHook) that.callbacks.offHook(); if (that.callbacks && that.callbacks.offHook) that.callbacks.offHook();
......
...@@ -23,12 +23,6 @@ ...@@ -23,12 +23,6 @@
package com.sun.voip.server; package com.sun.voip.server;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.JID;
import com.sun.voip.CallParticipant; import com.sun.voip.CallParticipant;
import com.sun.voip.CallState; import com.sun.voip.CallState;
import com.sun.voip.CallEvent; import com.sun.voip.CallEvent;
...@@ -40,6 +34,9 @@ import java.io.IOException; ...@@ -40,6 +34,9 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketException; import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.text.ParseException; import java.text.ParseException;
...@@ -48,6 +45,8 @@ import java.util.Collection; ...@@ -48,6 +45,8 @@ import java.util.Collection;
import org.voicebridge.Application; import org.voicebridge.Application;
import org.voicebridge.Config; import org.voicebridge.Config;
import org.ifsoft.rayo.RayoComponent;
/** /**
* Handle an incoming call. The call is placed into a temporary conference. * Handle an incoming call. The call is placed into a temporary conference.
...@@ -109,38 +108,12 @@ public class IncomingCallHandler extends CallHandler ...@@ -109,38 +108,12 @@ public class IncomingCallHandler extends CallHandler
System.out.println("Incoming SIP, call " + cp); System.out.println("Incoming SIP, call " + cp);
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(); if (RayoComponent.self.routeIncomingSIP(cp))
boolean foundUser = false;
for (ClientSession session : sessions)
{
try{
String userId = session.getAddress().getNode();
if (cp.getToPhoneNumber().equals(userId))
{
System.out.println("Incoming SIP, call route to user " + userId);
foundUser = true;
break;
}
} catch (Exception e) { }
}
if (foundUser) // send this call to conf with username and invite user to join with Jingle RTMP
{ {
String sid = "incoming-" + String.valueOf(System.currentTimeMillis());
cp.setConferenceId(sid);
haveIncomingConferenceId = true; haveIncomingConferenceId = true;
CallEvent callEvent = new CallEvent(CallEvent.STATE_CHANGED); } else {
callEvent.setCallState(new CallState(CallState.INCOMING)); // conf bridge
callEvent.setInfo(cp.getPhoneNumber());
callEvent.setCallId(sid);
sendCallEventNotification(callEvent);
} else { // conf bridge
if (Config.getInstance().getConferenceExten().equals(cp.getToPhoneNumber())) if (Config.getInstance().getConferenceExten().equals(cp.getToPhoneNumber()))
{ {
......
...@@ -369,7 +369,7 @@ public class MemberSender { ...@@ -369,7 +369,7 @@ public class MemberSender {
callHandler.getMember().adjustVolume(dataToSend, outputVolume); callHandler.getMember().adjustVolume(dataToSend, outputVolume);
} }
dataToSend = normalize(dataToSend); //dataToSend = normalize(dataToSend);
try { try {
/* /*
......
...@@ -380,8 +380,7 @@ public class SipServer implements SipListener { ...@@ -380,8 +380,7 @@ public class SipServer implements SipListener {
String from = fromHeader.getAddress().toString(); String from = fromHeader.getAddress().toString();
String to = toHeader.getAddress().toString(); String to = toHeader.getAddress().toString();
Logger.writeFile("SipServer: duplicate INVITE from " Logger.writeFile("SipServer: duplicate INVITE from " + from + " to " + to);
+ from + " to " + to);
return; return;
} }
...@@ -434,6 +433,7 @@ public class SipServer implements SipListener { ...@@ -434,6 +433,7 @@ public class SipServer implements SipListener {
* we should send back a 500 Internal Server Error * we should send back a 500 Internal Server Error
*/ */
Logger.exception("processRequest", e); Logger.exception("processRequest", e);
e.printStackTrace();
} }
} }
......
...@@ -19,7 +19,14 @@ package org.ifsoft.rayo; ...@@ -19,7 +19,14 @@ package org.ifsoft.rayo;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.xmpp.packet.JID;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.component.ComponentManagerFactory; import org.xmpp.component.ComponentManagerFactory;
...@@ -372,16 +379,21 @@ public class RayoComponent extends AbstractComponent ...@@ -372,16 +379,21 @@ public class RayoComponent extends AbstractComponent
private IQ handleAcceptCommand(AcceptCommand command, IQ iq) private IQ handleAcceptCommand(AcceptCommand command, IQ iq)
{ {
Log.info("RayoComponent handleAcceptCommand " + iq.getFrom() + " " + iq.getTo().getNode()); String callId = iq.getTo().getNode();
Log.info("RayoComponent handleAcceptCommand " + iq.getFrom() + " " + callId);
IQ reply = IQ.createResultIQ(iq); IQ reply = IQ.createResultIQ(iq);
JID callJID = getJID(callId);
if (callJID != null) // only for XMPP calls
{
Map<String, String> headers = command.getHeaders(); Map<String, String> headers = command.getHeaders();
headers.put("call-protocol", "XMPP"); headers.put("call_protocol", "XMPP");
try { try {
Presence presence = new Presence(); Presence presence = new Presence();
presence.setFrom(iq.getTo()); presence.setFrom(iq.getTo());
presence.setTo(JID.unescapeNode(iq.getTo().getNode())); presence.setTo(callJID);
presence.getElement().add(rayoProvider.toXML(new RingingEvent(null, headers))); presence.getElement().add(rayoProvider.toXML(new RingingEvent(null, headers)));
sendPacket(presence); sendPacket(presence);
...@@ -389,22 +401,30 @@ public class RayoComponent extends AbstractComponent ...@@ -389,22 +401,30 @@ public class RayoComponent extends AbstractComponent
} catch (Exception e) { } catch (Exception e) {
reply.setError(PacketError.Condition.item_not_found); reply.setError(PacketError.Condition.item_not_found);
} }
}
return reply; return reply;
} }
private IQ handleAnswerCommand(AnswerCommand command, IQ iq) private IQ handleAnswerCommand(AnswerCommand command, IQ iq)
{ {
Log.info("RayoComponent AnswerCommand " + iq.getFrom() + " " + iq.getTo().getNode()); String callId = iq.getTo().getNode();
Log.info("RayoComponent AnswerCommand " + iq.getFrom() + " " + callId);
IQ reply = IQ.createResultIQ(iq); IQ reply = IQ.createResultIQ(iq);
JID callJID = getJID(callId);
Map<String, String> headers = command.getHeaders(); Map<String, String> headers = command.getHeaders();
headers.put("call-protocol", "XMPP"); CallHandler callHandler = null;
if (callJID != null) // XMPP call
{
headers.put("call_protocol", "XMPP");
try { try {
Presence presence1 = new Presence(); //to caller Presence presence1 = new Presence(); //to caller
presence1.setFrom(iq.getTo()); presence1.setFrom(iq.getTo());
presence1.setTo(JID.unescapeNode(iq.getTo().getNode())); presence1.setTo(callJID);
presence1.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers))); presence1.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers)));
sendPacket(presence1); sendPacket(presence1);
...@@ -414,13 +434,29 @@ public class RayoComponent extends AbstractComponent ...@@ -414,13 +434,29 @@ public class RayoComponent extends AbstractComponent
presence2.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers))); presence2.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers)));
sendPacket(presence2); sendPacket(presence2);
String handsetId = iq.getTo().getNode(); // use mixer of caller RelayChannel channel = plugin.getRelayChannel(callId);
RelayChannel channel = plugin.getRelayChannel(handsetId);
if (channel != null) if (channel != null)
{ {
Handset handset = channel.getHandset(); callHandler = channel.getCallHandler();
CallHandler callHandler = channel.getCallHandler();
} else reply.setError(PacketError.Condition.item_not_found);
} catch (Exception e) {
reply.setError(PacketError.Condition.item_not_found);
e.printStackTrace();
}
} else {
callHandler = CallHandler.findCall(callId); // SIP call;
Presence presence = new Presence(); //to called
presence.setFrom(iq.getTo());
presence.setTo(iq.getFrom());
presence.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers)));
sendPacket(presence);
}
if (callHandler != null) if (callHandler != null)
{ {
...@@ -430,23 +466,26 @@ public class RayoComponent extends AbstractComponent ...@@ -430,23 +466,26 @@ public class RayoComponent extends AbstractComponent
if (cp != null) if (cp != null)
{ {
String username = iq.getFrom().getNode();
ConferenceManager conferenceManager = ConferenceManager.getConference( handset.mixer,
channel.getMediaPreference(),
username, false);
try { try {
cp.setStartTimestamp(System.currentTimeMillis()); cp.setStartTimestamp(System.currentTimeMillis());
cp.setHeaders(headers); cp.setHeaders(headers);
String recording = handset.mixer + "-" + cp.getStartTimestamp() + ".au"; String recording = cp.getConferenceId() + "-" + cp.getStartTimestamp() + ".au";
conferenceManager.recordConference(true, recording, "au"); ConferenceManager.recordConference(cp.getConferenceId(), true, recording, "au");
String source = (new JID(JID.unescapeNode(iq.getTo().getNode()))).getNode();
String destination = iq.getFrom().getNode(); String destination = iq.getFrom().getNode();
String source = cp.getName();
if (callJID != null)
{
source = callJID.getNode();
Config.createCallRecord(source, recording, "xmpp:" + iq.getFrom(), cp.getStartTimestamp(), 0, "dialed") ;
Config.createCallRecord(destination, recording, "xmpp:" + callJID, cp.getStartTimestamp(), 0, "received") ;
} else { // incoming SIP
Config.createCallRecord(source, recording, destination, cp.getStartTimestamp(), 0, "dialed") ; Config.createCallRecord(destination, recording, "sip:" + cp.getPhoneNumber(), cp.getStartTimestamp(), 0, "received") ;
Config.createCallRecord(destination, recording, source, cp.getStartTimestamp(), 0, "received") ; }
} catch (ParseException e1) { } catch (ParseException e1) {
reply.setError(PacketError.Condition.internal_server_error); reply.setError(PacketError.Condition.internal_server_error);
...@@ -455,16 +494,11 @@ public class RayoComponent extends AbstractComponent ...@@ -455,16 +494,11 @@ public class RayoComponent extends AbstractComponent
} else reply.setError(PacketError.Condition.item_not_found); } else reply.setError(PacketError.Condition.item_not_found);
} else reply.setError(PacketError.Condition.item_not_found);
} catch (Exception e) {
reply.setError(PacketError.Condition.item_not_found);
e.printStackTrace();
}
return reply; return reply;
} }
private IQ handleHangupCommand(IQ iq) private IQ handleHangupCommand(IQ iq)
{ {
String callId = iq.getTo().getNode(); String callId = iq.getTo().getNode();
...@@ -479,15 +513,17 @@ public class RayoComponent extends AbstractComponent ...@@ -479,15 +513,17 @@ public class RayoComponent extends AbstractComponent
{ {
Log.info("RayoComponent handleHangupCommand found callhandler " + callId); Log.info("RayoComponent handleHangupCommand found callhandler " + callId);
CallHandler.hangup(iq.getTo().getNode(), "User requested call termination"); CallHandler.hangup(callId, "User requested call termination");
} else { } else {
reply.setError(PacketError.Condition.item_not_found); reply.setError(PacketError.Condition.item_not_found);
} }
try { try {
JID otherParty = new JID(JID.unescapeNode(callId)); JID otherParty = getJID(callId);
if (otherParty != null)
{
Log.info("RayoComponent handleHangupCommand found other party " + otherParty); Log.info("RayoComponent handleHangupCommand found other party " + otherParty);
Presence presence1 = new Presence(); Presence presence1 = new Presence();
...@@ -495,12 +531,28 @@ public class RayoComponent extends AbstractComponent ...@@ -495,12 +531,28 @@ public class RayoComponent extends AbstractComponent
presence1.setTo(otherParty); presence1.setTo(otherParty);
presence1.getElement().add(rayoProvider.toXML(new EndEvent(null, null))); presence1.getElement().add(rayoProvider.toXML(new EndEvent(null, null)));
sendPacket(presence1); sendPacket(presence1);
}
} catch (Exception e) { } } catch (Exception e) { }
return reply; return reply;
} }
private JID getJID(String jid)
{
jid = JID.unescapeNode(jid);
if (jid.indexOf("@") == -1 || jid.indexOf("/") == -1) return null;
try {
return new JID(jid);
} catch (Exception e) {
return null;
}
}
private IQ handleDtmfCommand(DtmfCommand command, IQ iq) private IQ handleDtmfCommand(DtmfCommand command, IQ iq)
{ {
Log.info("RayoComponent handleDtmfCommand " + iq.getFrom()); Log.info("RayoComponent handleDtmfCommand " + iq.getFrom());
...@@ -591,9 +643,9 @@ public class RayoComponent extends AbstractComponent ...@@ -591,9 +643,9 @@ public class RayoComponent extends AbstractComponent
boolean toPhone = to.indexOf("sip:") == 0 || to.indexOf("tel:") == 0; boolean toPhone = to.indexOf("sip:") == 0 || to.indexOf("tel:") == 0;
boolean toXmpp = to.indexOf("xmpp:") == 0; boolean toXmpp = to.indexOf("xmpp:") == 0;
String callId = headers.get("call-id"); String callId = headers.get("call_id");
String callerName = headers.get("caller-name"); String callerName = headers.get("caller_name");
String calledName = headers.get("called-name"); String calledName = headers.get("called_name");
String handsetId = iq.getFrom().toString(); String handsetId = iq.getFrom().toString();
...@@ -614,13 +666,13 @@ public class RayoComponent extends AbstractComponent ...@@ -614,13 +666,13 @@ public class RayoComponent extends AbstractComponent
if (callId == null) if (callId == null)
{ {
callId = "rayo-call-" + System.currentTimeMillis(); callId = "rayo-call-" + System.currentTimeMillis();
headers.put("call-id", callId); headers.put("call_id", callId);
} }
if (callerName == null) if (callerName == null)
{ {
callerName = iq.getFrom().getNode(); callerName = iq.getFrom().getNode();
headers.put("caller-name", callerName); headers.put("caller_name", callerName);
} }
if (toPhone) if (toPhone)
...@@ -628,7 +680,7 @@ public class RayoComponent extends AbstractComponent ...@@ -628,7 +680,7 @@ public class RayoComponent extends AbstractComponent
if (calledName == null) if (calledName == null)
{ {
calledName = to; calledName = to;
headers.put("called-name", calledName); headers.put("called_name", calledName);
} }
CallParticipant cp = new CallParticipant(); CallParticipant cp = new CallParticipant();
...@@ -646,7 +698,7 @@ public class RayoComponent extends AbstractComponent ...@@ -646,7 +698,7 @@ public class RayoComponent extends AbstractComponent
} else if (toXmpp){ } else if (toXmpp){
headers.put("call-protocol", "XMPP"); headers.put("call_protocol", "XMPP");
String destination = to.substring(5); String destination = to.substring(5);
String source = JID.escapeNode(handsetId); String source = JID.escapeNode(handsetId);
...@@ -655,7 +707,8 @@ public class RayoComponent extends AbstractComponent ...@@ -655,7 +707,8 @@ public class RayoComponent extends AbstractComponent
if (channel != null) if (channel != null)
{ {
headers.put("mixer-name", channel.getHandset().mixer); headers.put("mixer_name", channel.getHandset().mixer);
headers.put("codec_name", channel.getHandset().codec);
Presence presence = new Presence(); Presence presence = new Presence();
presence.setFrom(source + "@rayo." + getDomain()); presence.setFrom(source + "@rayo." + getDomain());
...@@ -675,7 +728,7 @@ public class RayoComponent extends AbstractComponent ...@@ -675,7 +728,7 @@ public class RayoComponent extends AbstractComponent
if (calledName == null) if (calledName == null)
{ {
calledName = presence.getTo().getNode(); calledName = presence.getTo().getNode();
headers.put("called-name", calledName); headers.put("called_name", calledName);
} }
offer.setHeaders(headers); offer.setHeaders(headers);
...@@ -715,10 +768,10 @@ public class RayoComponent extends AbstractComponent ...@@ -715,10 +768,10 @@ public class RayoComponent extends AbstractComponent
boolean fromHandset = from.indexOf("handset:") == 0; boolean fromHandset = from.indexOf("handset:") == 0;
String mixer = null; String mixer = null;
String callerId = headers.get("caller-id"); String callerId = headers.get("caller_id");
String calledId = headers.get("called-id"); String calledId = headers.get("called_id");
String callerName = headers.get("caller-name"); String callerName = headers.get("caller_name");
String calledName = headers.get("called-name"); String calledName = headers.get("called_name");
JoinCommand join = command.getJoin(); JoinCommand join = command.getJoin();
...@@ -901,7 +954,7 @@ public class RayoComponent extends AbstractComponent ...@@ -901,7 +954,7 @@ public class RayoComponent extends AbstractComponent
public void callEventNotification(com.sun.voip.CallEvent callEvent) public void callEventNotification(com.sun.voip.CallEvent callEvent)
{ {
Log.info("RayoComponent callEventNotification " + callEvent); Log.info("RayoComponent callEventNotification " + callEvent);
JID from = new JID(callEvent.getCallInfo()); JID from = getJID(callEvent.getCallInfo());
if (from != null) if (from != null)
{ {
...@@ -923,9 +976,9 @@ public class RayoComponent extends AbstractComponent ...@@ -923,9 +976,9 @@ public class RayoComponent extends AbstractComponent
Map<String, String> headers = cp.getHeaders(); Map<String, String> headers = cp.getHeaders();
headers.put("call-id", callEvent.getCallId()); headers.put("call_id", callEvent.getCallId());
headers.put("mixer-name", callEvent.getConferenceId()); headers.put("mixer_name", callEvent.getConferenceId());
headers.put("call-protocol", cp.getProtocol()); headers.put("call_protocol", cp.getProtocol());
Presence presence = new Presence(); Presence presence = new Presence();
presence.setFrom(callEvent.getCallId() + "@rayo." + getDomain()); presence.setFrom(callEvent.getCallId() + "@rayo." + getDomain());
...@@ -945,16 +998,7 @@ public class RayoComponent extends AbstractComponent ...@@ -945,16 +998,7 @@ public class RayoComponent extends AbstractComponent
presence.getElement().add(rayoProvider.toXML(new EndEvent(null, EndEvent.Reason.valueOf("HANGUP"), headers))); presence.getElement().add(rayoProvider.toXML(new EndEvent(null, EndEvent.Reason.valueOf("HANGUP"), headers)));
sendPacket(presence); sendPacket(presence);
if (cp.getStartTimestamp() > 0) finishCallRecord(cp);
{
cp.setEndTimestamp(System.currentTimeMillis());
Config.updateCallRecord(cp.getStartTimestamp(), (int)((cp.getEndTimestamp() - cp.getStartTimestamp()) / 1000));
ConferenceManager conferenceManager = ConferenceManager.findConferenceManager(callEvent.getConferenceId());
conferenceManager.recordConference(false, null, null);
cp.setStartTimestamp(0);
}
} }
} else if ("250 STARTED SPEAKING".equals(myEvent)) { } else if ("250 STARTED SPEAKING".equals(myEvent)) {
...@@ -987,6 +1031,23 @@ public class RayoComponent extends AbstractComponent ...@@ -987,6 +1031,23 @@ public class RayoComponent extends AbstractComponent
} }
} }
private void finishCallRecord(CallParticipant cp)
{
if (cp.getStartTimestamp() > 0)
{
cp.setEndTimestamp(System.currentTimeMillis());
Config.updateCallRecord(cp.getStartTimestamp(), (int)((cp.getEndTimestamp() - cp.getStartTimestamp()) / 1000));
try {
ConferenceManager conferenceManager = ConferenceManager.findConferenceManager(cp.getConferenceId());
conferenceManager.recordConference(false, null, null);
} catch (Exception e) {}
cp.setStartTimestamp(0);
}
}
public void initiated(String name, String callId) public void initiated(String name, String callId)
{ {
Log.info( "RayoComponent initiated " + name + " " + callId); Log.info( "RayoComponent initiated " + name + " " + callId);
...@@ -1072,6 +1133,9 @@ public class RayoComponent extends AbstractComponent ...@@ -1072,6 +1133,9 @@ public class RayoComponent extends AbstractComponent
{ {
UnjoinedEvent event = new UnjoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER); UnjoinedEvent event = new UnjoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event)); presence.getElement().add(rayoProvider.toXML(event));
finishCallRecord(callParticipant);
} else { } else {
JoinedEvent event = new JoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER); JoinedEvent event = new JoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event)); presence.getElement().add(rayoProvider.toXML(event));
...@@ -1100,4 +1164,70 @@ public class RayoComponent extends AbstractComponent ...@@ -1100,4 +1164,70 @@ public class RayoComponent extends AbstractComponent
e.printStackTrace(); e.printStackTrace();
} }
} }
private JID findUser(String username)
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
JID foundUser = null;
for (ClientSession session : sessions)
{
try{
String userId = session.getAddress().getNode();
if (username.equals(userId))
{
Log.info("Incoming SIP, findUser " + session.getAddress());
foundUser = session.getAddress();
break;
}
} catch (Exception e) { }
}
return foundUser;
}
public boolean routeIncomingSIP(CallParticipant cp)
{
Log.info("Incoming SIP, call route to user " + cp.getToPhoneNumber());
JID foundUser = findUser(cp.getToPhoneNumber());
if (foundUser != null) // send this call to user
{
String callId = "rayo-incoming-" + System.currentTimeMillis();
cp.setCallId(callId);
cp.setConferenceId(callId);
cp.setCallOwner(foundUser.toString());
Map<String, String> headers = cp.getHeaders();
headers.put("mixer_name", callId);
headers.put("call_protocol", "SIP");
Presence presence = new Presence();
presence.setFrom(callId + "@rayo." + getDomain());
presence.setTo(foundUser);
OfferEvent offer = new OfferEvent(callId);
try {
offer.setTo(new URI("xmpp:" + foundUser.toString()));
offer.setFrom(new URI("sip:" + cp.getPhoneNumber()));
} catch (URISyntaxException e) {
Log.error("SIP phone nos not URI " + cp.getPhoneNumber() + " " + foundUser);
}
headers.put("called_name", foundUser.getNode());
headers.put("caller_name", cp.getName());
offer.setHeaders(headers);
presence.getElement().add(rayoProvider.toXML(offer));
sendPacket(presence);
}
return foundUser != null;
}
} }
...@@ -132,7 +132,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -132,7 +132,7 @@ Strophe.addConnectionPlugin('rayo',
var that = this; var that = this;
var mixer = "rayo-mixer-" + Math.random().toString(36).substr(2,9); var mixer = "rayo-outgoing-" + Math.random().toString(36).substr(2,9);
var callId = "rayo-call-" + Math.random().toString(36).substr(2,9); var callId = "rayo-call-" + Math.random().toString(36).substr(2,9);
if (to.indexOf("xmpp:") == 0) if (to.indexOf("xmpp:") == 0)
...@@ -146,7 +146,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -146,7 +146,7 @@ Strophe.addConnectionPlugin('rayo',
{ {
var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("dial", {xmlns: Strophe.NS.RAYO_CORE, to: to, from: from}); var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("dial", {xmlns: Strophe.NS.RAYO_CORE, to: to, from: from});
iq.c("header", {name: "call-id", value: callId}).up(); iq.c("header", {name: "call_id", value: callId}).up();
if (headers) if (headers)
{ {
...@@ -212,6 +212,9 @@ Strophe.addConnectionPlugin('rayo', ...@@ -212,6 +212,9 @@ Strophe.addConnectionPlugin('rayo',
//console.log('Rayo plugin _offhook1 ' + mixer); //console.log('Rayo plugin _offhook1 ' + mixer);
var that = this; var that = this;
var codec = (headers && headers.codec_name) ? headers.codec_name : (that.callbacks.codec_name ? that.callbacks.codec_name : "OPUS");
that.pc1 = new webkitRTCPeerConnection(null); that.pc1 = new webkitRTCPeerConnection(null);
that.pc2 = new webkitRTCPeerConnection(null); that.pc2 = new webkitRTCPeerConnection(null);
...@@ -230,7 +233,12 @@ Strophe.addConnectionPlugin('rayo', ...@@ -230,7 +233,12 @@ Strophe.addConnectionPlugin('rayo',
that.pc1.setLocalDescription(desc); that.pc1.setLocalDescription(desc);
var sdpObj1 = WebrtcSDP.parseSDP(desc.sdp); var sdpObj1 = WebrtcSDP.parseSDP(desc.sdp);
if (codec == "PCMU")
sdpObj1.contents[0].codecs = [{clockrate: "8000", id: "0", name: "PCMU", channels: 1}];
else
sdpObj1.contents[0].codecs = [{clockrate: "48000", id: "111", name: "opus", channels: 2}]; sdpObj1.contents[0].codecs = [{clockrate: "48000", id: "111", name: "opus", channels: 2}];
var sdp = WebrtcSDP.buildSDP(sdpObj1); var sdp = WebrtcSDP.buildSDP(sdpObj1);
//console.log(sdp); //console.log(sdp);
that.cryptoSuite = sdpObj1.contents[0].crypto['crypto-suite']; that.cryptoSuite = sdpObj1.contents[0].crypto['crypto-suite'];
...@@ -257,8 +265,8 @@ Strophe.addConnectionPlugin('rayo', ...@@ -257,8 +265,8 @@ Strophe.addConnectionPlugin('rayo',
//console.log('Rayo plugin _offhook2 ' + this.cryptoSuite + " " + this.localCrypto + " " + this.remoteCrypto + " " + mixer); //console.log('Rayo plugin _offhook2 ' + this.cryptoSuite + " " + this.localCrypto + " " + this.remoteCrypto + " " + mixer);
var that = this; var that = this;
var stereo = (headers && headers.stereo) ? headers.stereo : "0"; var stereo = (headers && headers.stereo_pan) ? headers.stereo_pan : (that.callbacks.stereo_pan ? that.callbacks.stereo_pan : "0");
var codec = (headers && headers.codec) ? headers.codec : "OPUS"; var codec = (headers && headers.codec_name) ? headers.codec_name : (that.callbacks.codec_name ? that.callbacks.codec_name : "OPUS");
var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("offhook", {xmlns: Strophe.NS.RAYO_HANDSET, cryptoSuite: that.cryptoSuite, localCrypto: that.localCrypto, remoteCrypto: that.remoteCrypto, codec: codec, stereo: stereo, mixer: mixer}); var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("offhook", {xmlns: Strophe.NS.RAYO_HANDSET, cryptoSuite: that.cryptoSuite, localCrypto: that.localCrypto, remoteCrypto: that.remoteCrypto, codec: codec, stereo: stereo, mixer: mixer});
...@@ -346,7 +354,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -346,7 +354,7 @@ Strophe.addConnectionPlugin('rayo',
var callTo = $(this).attr('to'); var callTo = $(this).attr('to');
var callId = Strophe.getNodeFromJid(from); var callId = Strophe.getNodeFromJid(from);
var mixer = headers['mixer-name'] var mixer = headers['mixer_name']
var call = { var call = {
digit: function(tone) {that.digit(callId, tone);}, digit: function(tone) {that.digit(callId, tone);},
...@@ -396,7 +404,14 @@ Strophe.addConnectionPlugin('rayo', ...@@ -396,7 +404,14 @@ Strophe.addConnectionPlugin('rayo',
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
var callId = Strophe.getNodeFromJid(from);
if (callId.indexOf("rayo-incoming-") == 0)
{
that._onhook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
}
} }
}); });
...@@ -433,7 +448,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -433,7 +448,7 @@ Strophe.addConnectionPlugin('rayo',
{ {
var callId = Strophe.getNodeFromJid(from); var callId = Strophe.getNodeFromJid(from);
if (headers['call-protocol'] == "WebRtc") if (headers['call_protocol'] == "WebRtc")
{ {
if (that.callbacks && that.callbacks.offHook) that.callbacks.offHook(); if (that.callbacks && that.callbacks.offHook) that.callbacks.offHook();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment