Commit c8b2a138 authored by Dele Olajide's avatar Dele Olajide Committed by dele

Rayo plugin - work-in-progress

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13770 b35dd754-fafc-0310-a699-88a17e54d16e
parent 386c2b90
......@@ -196,10 +196,21 @@
stopTone();
},
onBusy: function(callId, headers) {
//console.log('onBusy ' + callId);
onBusy: function(call, headers) {
//console.log('onBusy ' + call.id);
//console.log(headers);
window.candybar.setState('inactive');
var cli = headers.caller_name ? headers.caller_name : call.from;
window.candybar.setUser({
name: cli,
number: cli,
picUrl: 'unknown.jpg'
});
window.candybar.call = call;
window.candybar.setState('busy');
window.dialer.setCallLabel('Join');
stopTone();
......@@ -221,7 +232,7 @@
},
onUnjoin: function(callId, jid, mixer) {
console.log('onUnjoin ' + jid + " " + mixer + " " + callId);
//console.log('onUnjoin ' + jid + " " + mixer + " " + callId);
},
onError: function(e) {
......@@ -237,16 +248,22 @@
//console.log("makeCall " + destination);
var sipUri = prefix + destination + "@" + domain
var groupname = "family";
if (prefix == "sip:") sipUri = prefix + destination + "@" + domain
if (prefix == "tel:") sipUri = prefix + destination
if (prefix == "xmpp:") sipUri = prefix + destination + "@" + domain + "/" + destination;
if (prefix == "xmpp:")
{
sipUri = prefix + destination + "@" + domain + "/" + destination;
}
if (!username) groupname = null;
window.connection.rayo.dial("xmpp:" + window.connection.jid, sipUri, {
codec_name: "PCMU",
/* group_name: "12345678" */
group_name: groupname
});
window.candybar.setUser({
......
......@@ -51,7 +51,7 @@ Strophe.addConnectionPlugin('rayo',
hangup: function(callId)
{
//console.log("hangup " + callId);
console.log("hangup " + callId);
var that = this;
var iq = $iq({to: callId + "@rayo." + this._connection.domain, from: this._connection.jid, type: "get"}).c("hangup", {xmlns: Strophe.NS.RAYO_CORE});
......@@ -129,7 +129,7 @@ Strophe.addConnectionPlugin('rayo',
var name = hdrs[i];
var value = headers[name];
iq.c("header", {name: name, value: value}).up();
if (value) iq.c("header", {name: name, value: value}).up();
}
}
......@@ -154,13 +154,7 @@ Strophe.addConnectionPlugin('rayo',
var that = this;
var mixer = "rayo-outgoing-" + Math.random().toString(36).substr(2,9);
var callId = "rayo-call-" + Math.random().toString(36).substr(2,9);
if (to.indexOf("xmpp:") == 0)
{
callId = Strophe.escapeNode(to.substring(5));
}
var mixer = "rayo-outgoing-" + Math.random().toString(36).substr(2,9);
if (this._isOffhook()) this._onhook();
......@@ -168,8 +162,6 @@ 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});
iq.c("header", {name: "call_id", value: callId}).up();
if (headers)
{
var hdrs = Object.getOwnPropertyNames(headers)
......@@ -179,7 +171,7 @@ Strophe.addConnectionPlugin('rayo',
var name = hdrs[i];
var value = headers[name];
iq.c("header", {name: name, value: value}).up();
if (value) iq.c("header", {name: name, value: value}).up();
}
}
......@@ -356,8 +348,8 @@ Strophe.addConnectionPlugin('rayo',
_handlePresence: function(presence)
{
console.log('Rayo plugin handlePresence');
console.log(presence);
//console.log('Rayo plugin handlePresence');
//console.log(presence);
var that = this;
var from = $(presence).attr('from');
......@@ -391,7 +383,7 @@ Strophe.addConnectionPlugin('rayo',
var callTo = $(this).attr('to');
var callId = Strophe.getNodeFromJid(from);
var mixer = headers['mixer_name']
var mixer = headers.mixer_name;
var call = {
digit: function(tone) {that.digit(callId, tone);},
......@@ -416,7 +408,7 @@ Strophe.addConnectionPlugin('rayo',
var name = hdrs[i];
var value = headers[name];
iq.c("header", {name: name, value: value}).up();
if (value) iq.c("header", {name: name, value: value}).up();
}
//console.log(iq.toString());
......@@ -433,7 +425,9 @@ Strophe.addConnectionPlugin('rayo',
})
$(presence).find('joined').each(function()
{
{
//console.log('Rayo plugin handlePresence joined');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
......@@ -450,7 +444,9 @@ Strophe.addConnectionPlugin('rayo',
});
$(presence).find('unjoined').each(function()
{
{
//console.log('Rayo plugin handlePresence unjoined');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
......@@ -494,11 +490,14 @@ Strophe.addConnectionPlugin('rayo',
});
$(presence).find('answered').each(function()
{
{
//console.log('Rayo plugin handlePresence answered');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
var jid = Strophe.unescapeNode(callId);
var jid = Strophe.unescapeNode(headers.call_owner);
var busy = false;
......@@ -517,8 +516,20 @@ Strophe.addConnectionPlugin('rayo',
if (busy)
{
var mixer = headers.mixer_name;
var call = {
digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);},
answer: function() {that.answer(callId, mixer, headers);},
join: function() {that.join(mixer, headers);},
leave: function() {that.leave(mixer);},
id: callId,
from: Strophe.getNodeFromJid(jid)
}
if (that.callbacks && that.callbacks.onHook) that.callbacks.onHook();
if (that.callbacks && that.callbacks.onBusy) that.callbacks.onBusy(callId, headers);
if (that.callbacks && that.callbacks.onBusy) that.callbacks.onBusy(call, headers);
} else {
......@@ -530,6 +541,8 @@ Strophe.addConnectionPlugin('rayo',
$(presence).find('end').each(function()
{
//console.log('Rayo plugin handlePresence end');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
......
......@@ -57,6 +57,7 @@ public class ConferenceManager {
private String conferenceId; // conference identifier
private String displayName; // user readable name
private String callId; // target call id
private ArrayList memberList; // for iterating members
......@@ -512,10 +513,40 @@ public class ConferenceManager {
return conferenceId;
}
public String getCallId() {
return callId;
}
public void setCallId(String callId) {
this.callId = callId;
}
public static String getCallId(String conferenceId)
{
try {
ConferenceManager conferenceManager = findConferenceManager(conferenceId);
return conferenceManager.getCallId();
} catch (ParseException e) {
return null;
}
}
public static void setCallId(String conferenceId, String callId)
{
try {
ConferenceManager conferenceManager = findConferenceManager(conferenceId);
conferenceManager.setCallId(callId);
} catch (ParseException e) {
}
}
public String getDisplayName() {
return displayName;
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
......
......@@ -470,7 +470,6 @@ public class RayoComponent extends AbstractComponent
try {
cp.setStartTimestamp(System.currentTimeMillis());
cp.setHeaders(headers);
//cp.setCallOwner(iq.getFrom().toString());
String recording = cp.getConferenceId() + "-" + cp.getStartTimestamp() + ".au";
ConferenceManager.recordConference(cp.getConferenceId(), true, recording, "au");
......@@ -641,7 +640,6 @@ public class RayoComponent extends AbstractComponent
boolean toPhone = to.indexOf("sip:") == 0 || to.indexOf("tel:") == 0;
boolean toXmpp = to.indexOf("xmpp:") == 0;
String callId = headers.get("call_id");
String callerName = headers.get("caller_name");
String calledName = headers.get("called_name");
......@@ -661,12 +659,6 @@ public class RayoComponent extends AbstractComponent
} else {
if (callId == null)
{
callId = "rayo-call-" + System.currentTimeMillis();
headers.put("call_id", callId);
}
if (callerName == null)
{
callerName = iq.getFrom().getNode();
......@@ -710,9 +702,11 @@ public class RayoComponent extends AbstractComponent
headers.put("mixer_name", channel.getHandset().mixer);
headers.put("codec_name", channel.getHandset().codec);
ConferenceManager.setCallId(channel.getHandset().mixer, source);
if (findUser(destination.getNode()) != null)
{
routeXMPPCall(reply, destination, source, callId, calledName, headers);
routeXMPPCall(reply, destination, source, calledName, headers);
} else {
int count = 0;
......@@ -728,7 +722,7 @@ public class RayoComponent extends AbstractComponent
for (ClientSession session : sessions)
{
routeXMPPCall(reply, session.getAddress(), source, callId, calledName, headers);
routeXMPPCall(reply, session.getAddress(), source, calledName, headers);
count++;
}
}
......@@ -762,13 +756,13 @@ public class RayoComponent extends AbstractComponent
return reply;
}
private void routeXMPPCall(IQ reply, JID destination, String source, String callId, String calledName, Map<String, String> headers)
private void routeXMPPCall(IQ reply, JID destination, String source, String calledName, Map<String, String> headers)
{
Presence presence = new Presence();
presence.setFrom(source + "@rayo." + getDomain());
presence.setTo(destination);
OfferEvent offer = new OfferEvent(callId);
OfferEvent offer = new OfferEvent(null);
try {
offer.setFrom(new URI("xmpp:" + JID.unescapeNode(source)));
......@@ -970,6 +964,7 @@ public class RayoComponent extends AbstractComponent
try {
cp.setConferenceId(mixer);
cp.setCallId(mixer);
conferenceManager.setCallId(mixer);
cp.setStartTimestamp(System.currentTimeMillis());
String recording = mixer + "-" + cp.getStartTimestamp() + ".au";
......@@ -1021,8 +1016,6 @@ public class RayoComponent extends AbstractComponent
Log.info("RayoComponent callEventNotification found call paticipant " + cp);
Map<String, String> headers = cp.getHeaders();
headers.put("call_id", callEvent.getCallId());
headers.put("mixer_name", callEvent.getConferenceId());
headers.put("call_protocol", cp.getProtocol());
......@@ -1157,6 +1150,11 @@ public class RayoComponent extends AbstractComponent
ConferenceManager conferenceManager = ConferenceManager.findConferenceManager(conferenceEvent.getConferenceId());
String groupName = conferenceManager.getDisplayName();
String callId = conferenceManager.getCallId();
if (callId == null) callId = conferenceEvent.getConferenceId(); // special case of SIP incoming
CallHandler callHandler = CallHandler.findCall(conferenceEvent.getCallId());
if (callHandler != null)
......@@ -1165,17 +1163,15 @@ public class RayoComponent extends AbstractComponent
CallParticipant callParticipant = callHandler.getCallParticipant();
if (callParticipant != null)
if (callParticipant != null )
{
int memberCount = conferenceManager.getMemberList().size();
Log.info("RayoComponent notifyConferenceMonitors found owner " + callParticipant.getCallOwner() + " " + memberCount);
String groupName = ConferenceManager.getDisplayName(conferenceEvent.getConferenceId());
if (groupName == null)
{
routeJoinEvent(callParticipant.getCallOwner(), callParticipant, conferenceEvent, memberCount, groupName);
routeJoinEvent(callParticipant.getCallOwner(), callParticipant, conferenceEvent, memberCount, groupName, callId);
} else {
......@@ -1187,7 +1183,7 @@ public class RayoComponent extends AbstractComponent
for (ClientSession session : sessions)
{
routeJoinEvent(memberJID.toString(), callParticipant, conferenceEvent, memberCount, groupName);
routeJoinEvent(memberJID.toString(), callParticipant, conferenceEvent, memberCount, groupName, callId);
}
}
}
......@@ -1207,18 +1203,17 @@ public class RayoComponent extends AbstractComponent
}
}
private void routeJoinEvent(String callee, CallParticipant callParticipant, ConferenceEvent conferenceEvent, int memberCount, String groupName)
private void routeJoinEvent(String callee, CallParticipant callParticipant, ConferenceEvent conferenceEvent, int memberCount, String groupName, String callId)
{
Log.info( "RayoComponent routeJoinEvent " + callee);
Log.info( "RayoComponent routeJoinEvent " + callee + " " + callId + " " + groupName);
Presence presence = new Presence();
presence.setFrom(conferenceEvent.getCallId() + "@rayo." + getDomain());
presence.setFrom(callId + "@rayo." + getDomain());
presence.setTo(callee);
Map<String, String> headers = callParticipant.getHeaders();
headers.put("call_owner", callParticipant.getCallOwner());
headers.put("call_id", conferenceEvent.getCallId());
headers.put("call_action", conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT) ? "leave" : "join");
headers.put("call_protocol", callParticipant.getProtocol());
......@@ -1295,6 +1290,8 @@ public class RayoComponent extends AbstractComponent
cp.setCallId(callId);
cp.setConferenceId(callId);
ConferenceManager.setCallId(callId, callId);
Map<String, String> headers = cp.getHeaders();
headers.put("mixer_name", callId);
headers.put("call_protocol", "SIP");
......@@ -1337,7 +1334,7 @@ public class RayoComponent extends AbstractComponent
presence.setFrom(callId + "@rayo." + getDomain());
presence.setTo(callee);
OfferEvent offer = new OfferEvent(callId);
OfferEvent offer = new OfferEvent(null);
try {
offer.setTo(new URI("xmpp:" + callee.toString()));
......
......@@ -51,7 +51,7 @@ Strophe.addConnectionPlugin('rayo',
hangup: function(callId)
{
//console.log("hangup " + callId);
console.log("hangup " + callId);
var that = this;
var iq = $iq({to: callId + "@rayo." + this._connection.domain, from: this._connection.jid, type: "get"}).c("hangup", {xmlns: Strophe.NS.RAYO_CORE});
......@@ -129,7 +129,7 @@ Strophe.addConnectionPlugin('rayo',
var name = hdrs[i];
var value = headers[name];
iq.c("header", {name: name, value: value}).up();
if (value) iq.c("header", {name: name, value: value}).up();
}
}
......@@ -154,13 +154,7 @@ Strophe.addConnectionPlugin('rayo',
var that = this;
var mixer = "rayo-outgoing-" + Math.random().toString(36).substr(2,9);
var callId = "rayo-call-" + Math.random().toString(36).substr(2,9);
if (to.indexOf("xmpp:") == 0)
{
callId = Strophe.escapeNode(to.substring(5));
}
var mixer = "rayo-outgoing-" + Math.random().toString(36).substr(2,9);
if (this._isOffhook()) this._onhook();
......@@ -168,8 +162,6 @@ 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});
iq.c("header", {name: "call_id", value: callId}).up();
if (headers)
{
var hdrs = Object.getOwnPropertyNames(headers)
......@@ -179,7 +171,7 @@ Strophe.addConnectionPlugin('rayo',
var name = hdrs[i];
var value = headers[name];
iq.c("header", {name: name, value: value}).up();
if (value) iq.c("header", {name: name, value: value}).up();
}
}
......@@ -356,8 +348,8 @@ Strophe.addConnectionPlugin('rayo',
_handlePresence: function(presence)
{
console.log('Rayo plugin handlePresence');
console.log(presence);
//console.log('Rayo plugin handlePresence');
//console.log(presence);
var that = this;
var from = $(presence).attr('from');
......@@ -391,7 +383,7 @@ Strophe.addConnectionPlugin('rayo',
var callTo = $(this).attr('to');
var callId = Strophe.getNodeFromJid(from);
var mixer = headers['mixer_name']
var mixer = headers.mixer_name;
var call = {
digit: function(tone) {that.digit(callId, tone);},
......@@ -416,7 +408,7 @@ Strophe.addConnectionPlugin('rayo',
var name = hdrs[i];
var value = headers[name];
iq.c("header", {name: name, value: value}).up();
if (value) iq.c("header", {name: name, value: value}).up();
}
//console.log(iq.toString());
......@@ -433,7 +425,9 @@ Strophe.addConnectionPlugin('rayo',
})
$(presence).find('joined').each(function()
{
{
//console.log('Rayo plugin handlePresence joined');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
......@@ -450,7 +444,9 @@ Strophe.addConnectionPlugin('rayo',
});
$(presence).find('unjoined').each(function()
{
{
//console.log('Rayo plugin handlePresence unjoined');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
......@@ -494,11 +490,14 @@ Strophe.addConnectionPlugin('rayo',
});
$(presence).find('answered').each(function()
{
{
//console.log('Rayo plugin handlePresence answered');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
var jid = Strophe.unescapeNode(callId);
var jid = Strophe.unescapeNode(headers.call_owner);
var busy = false;
......@@ -517,8 +516,20 @@ Strophe.addConnectionPlugin('rayo',
if (busy)
{
var mixer = headers.mixer_name;
var call = {
digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);},
answer: function() {that.answer(callId, mixer, headers);},
join: function() {that.join(mixer, headers);},
leave: function() {that.leave(mixer);},
id: callId,
from: Strophe.getNodeFromJid(jid)
}
if (that.callbacks && that.callbacks.onHook) that.callbacks.onHook();
if (that.callbacks && that.callbacks.onBusy) that.callbacks.onBusy(callId, headers);
if (that.callbacks && that.callbacks.onBusy) that.callbacks.onBusy(call, headers);
} else {
......@@ -530,6 +541,8 @@ Strophe.addConnectionPlugin('rayo',
$(presence).find('end').each(function()
{
//console.log('Rayo plugin handlePresence end');
//console.log(presence);
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
......
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