Commit ca711647 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@13757 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1a6c79e9
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
}; };
CandyBar.prototype.setState = function (state) { CandyBar.prototype.setState = function (state) {
if (!this.dom) return this; if (!this.dom) return this;
var buttons = this.dom.querySelectorAll('button'), var buttons = this.dom.querySelectorAll('button'),
callActionsEl = this.dom.querySelector('.callActions'), callActionsEl = this.dom.querySelector('.callActions'),
self = this, self = this,
...@@ -137,10 +137,9 @@ ...@@ -137,10 +137,9 @@
forEach.call(buttons, function (button) { forEach.call(buttons, function (button) {
button.parentElement.removeChild(button); button.parentElement.removeChild(button);
}); });
// add buttons // add buttons
stateDef.buttons.forEach(function (button) { stateDef.buttons.forEach(function (button) {
callActionsEl.appendChild(self.domify('<button class="' + button.cls + '">' + button.label + '</button>')); callActionsEl.appendChild(self.domify('<button class="' + button.cls + '">' + button.label + '</button>'));
}); });
// start/stop timer // start/stop timer
......
...@@ -288,7 +288,7 @@ body { ...@@ -288,7 +288,7 @@ body {
display: block; display: block;
position: relative; } position: relative; }
.cancel { .cancel_dialer {
position: absolute; position: absolute;
top: 4px; top: 4px;
right: 10px; right: 10px;
......
...@@ -109,25 +109,33 @@ ...@@ -109,25 +109,33 @@
{ {
window.connection.rayo.phone( window.connection.rayo.phone(
{ {
onReady: function() { offHook: function() {
console.log('Handset is off hook');
$("#status").html("Off Hook"); $("#status").html("Off Hook");
}, },
onUnready: function() { onHook: function() {
console.log('Handset is on hook');
$("#status").html("On Hook"); $("#status").html("On Hook");
}, },
offSpeaking: function() {
$("#status").html("Stopped Speaking");
},
onSpeaking: function() {
$("#status").html("Started Speaking");
},
onOffer: function(call, headers) { onOffer: function(call, headers) {
console.log('onOffer ' + call.from); //console.log('onOffer ' + call.from);
console.log(headers); //console.log(headers);
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;
window.candybar.setUser({ window.candybar.setUser({
name: call.from, name: cli,
number: call.to, number: cli,
picUrl: 'unknown.jpg' picUrl: 'unknown.jpg'
}); });
...@@ -135,21 +143,24 @@ ...@@ -135,21 +143,24 @@
window.candybar.setState('incoming'); window.candybar.setState('incoming');
window.dialer.setCallLabel('Answer'); window.dialer.setCallLabel('Answer');
} }
startTone("Diggztone_Vibe");
}, },
onEnd: function(callId, headers) { onEnd: function(callId, headers) {
console.log('onEnd ' + callId); //console.log('onEnd ' + callId);
console.log(headers); //console.log(headers);
window.candybar.endGently(); window.candybar.endGently();
window.candybar.call = null; window.candybar.call = null;
window.dialer.setCallLabel('Call'); window.dialer.setCallLabel('Call');
stopTone();
}, },
onAnswer: function(callId, headers) { onAnswer: function(callId, headers) {
console.log('onAnswer ' + callId); //console.log('onAnswer ' + callId);
console.log(headers); //console.log(headers);
window.candybar.setState('active'); window.candybar.setState('active');
window.dialer.setCallLabel('Hangup'); window.dialer.setCallLabel('Hangup');
...@@ -157,8 +168,8 @@ ...@@ -157,8 +168,8 @@
}, },
onRing: function(callId, headers) { onRing: function(callId, headers) {
console.log('onRing ' + callId); //console.log('onRing ' + callId);
console.log(headers); //console.log(headers);
window.candybar.setState('calling'); window.candybar.setState('calling');
startTone("ringback-uk"); startTone("ringback-uk");
...@@ -177,36 +188,20 @@ ...@@ -177,36 +188,20 @@
var sipUri = prefix + destination + "@" + domain var sipUri = prefix + destination + "@" + domain
if (prefix == "sip:") sipUri = prefix + destination + "@" + domain
if (prefix == "tel:") sipUri = prefix + destination if (prefix == "tel:") sipUri = prefix + 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);
window.candybar.setUser({ window.candybar.setUser({
name: sipUri, name: destination,
number: destination, number: destination,
picUrl: 'unknown.jpg' picUrl: 'unknown.jpg'
}); });
} }
function onIncomingCall(call)
{
console.log(' call from ' + call.from);
if (window.candybar.call == null) // ignore when user has active call
{
window.candybar.setUser({
name: call.from,
number: call.to,
picUrl: 'unknown.jpg'
});
window.candybar.call = call;
window.candybar.setState('incoming');
window.dialer.setCallLabel('Answer');
}
}
function urlParam(name) function urlParam(name)
{ {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
...@@ -216,10 +211,13 @@ ...@@ -216,10 +211,13 @@
function startTone(name) function startTone(name)
{ {
ringtone = new Audio(); if (!ringtone)
ringtone.loop = true; {
ringtone.src = "ringtones/" + name + ".mp3"; ringtone = new Audio();
ringtone.play(); ringtone.loop = true;
ringtone.src = "ringtones/" + name + ".mp3";
ringtone.play();
}
} }
function stopTone() function stopTone()
......
...@@ -51,16 +51,16 @@ Strophe.addConnectionPlugin('rayo', ...@@ -51,16 +51,16 @@ Strophe.addConnectionPlugin('rayo',
hangup: function(callId) hangup: function(callId)
{ {
console.log("hangup " + callId); //console.log("hangup " + callId);
var that = this; 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}); var iq = $iq({to: callId + "@rayo." + this._connection.domain, from: this._connection.jid, type: "get"}).c("hangup", {xmlns: Strophe.NS.RAYO_CORE});
console.log(iq.toString()); //console.log(iq.toString());
that._connection.sendIQ(iq, function(response) that._connection.sendIQ(iq, function(response)
{ {
console.log(response); //console.log(response);
if ($(response).attr('type') != "result") if ($(response).attr('type') != "result")
{ {
...@@ -87,18 +87,18 @@ Strophe.addConnectionPlugin('rayo', ...@@ -87,18 +87,18 @@ Strophe.addConnectionPlugin('rayo',
}); });
}, },
answer: function(callId, headers) answer: function(callId, mixer, headers)
{ {
//console.log('Rayo plugin accept ' + callId); //console.log('Rayo plugin accept ' + callId + " " + mixer);
//console.log(headers) //console.log(headers)
var that = this; var that = this;
if (this._isOffhook()) this._onhook(); //if (this._isOffhook()) this._onhook();
this._offhook(callId, headers, function() this._offhook(mixer, headers, function()
{ {
var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("answer", {xmlns: Strophe.NS.RAYO_CORE}); var iq = $iq({to: callId + "@rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("answer", {xmlns: Strophe.NS.RAYO_CORE});
if (headers) if (headers)
{ {
...@@ -113,7 +113,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -113,7 +113,7 @@ Strophe.addConnectionPlugin('rayo',
} }
} }
console.log(iq.toString()); //console.log(iq.toString());
that._connection.sendIQ(iq, function(response) that._connection.sendIQ(iq, function(response)
{ {
...@@ -131,12 +131,18 @@ Strophe.addConnectionPlugin('rayo', ...@@ -131,12 +131,18 @@ Strophe.addConnectionPlugin('rayo',
//console.log(headers) //console.log(headers)
var that = this; var that = this;
var mixer = "rayo-mixer-" + 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 (this._isOffhook()) this._onhook(); if (to.indexOf("xmpp:") == 0)
{
callId = Strophe.escapeNode(to.substring(5));
}
//if (this._isOffhook()) this._onhook();
this._offhook(callId, headers, function() this._offhook(mixer, headers, function()
{ {
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});
...@@ -155,7 +161,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -155,7 +161,7 @@ Strophe.addConnectionPlugin('rayo',
} }
} }
console.log(iq.toString()); //console.log(iq.toString());
that._connection.sendIQ(iq, function(response) that._connection.sendIQ(iq, function(response)
{ {
...@@ -206,7 +212,16 @@ Strophe.addConnectionPlugin('rayo', ...@@ -206,7 +212,16 @@ Strophe.addConnectionPlugin('rayo',
//console.log('Rayo plugin _offhook1 ' + mixer); //console.log('Rayo plugin _offhook1 ' + mixer);
var that = this; var that = this;
that.pc1 = new webkitRTCPeerConnection(null); that.pc1 = new webkitRTCPeerConnection(null);
that.pc2 = new webkitRTCPeerConnection(null);
that.pc2.onaddstream = function(e)
{
that.audio = new Audio();
that.audio.autoplay = true;
that.audio.src = webkitURL.createObjectURL(e.stream)
};
that.pc1.addStream(that.localStream); that.pc1.addStream(that.localStream);
that.pc1.createOffer(function(desc) that.pc1.createOffer(function(desc)
...@@ -234,16 +249,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -234,16 +249,7 @@ Strophe.addConnectionPlugin('rayo',
that._offhook2(mixer, headers, action); that._offhook2(mixer, headers, action);
}); });
}); });
that.pc2 = new webkitRTCPeerConnection(null);
that.pc2.onaddstream = function(e)
{
that.audio = new Audio();
that.audio.autoplay = true;
that.audio.src = webkitURL.createObjectURL(e.stream)
};
}, },
_offhook2: function(mixer, headers, action) _offhook2: function(mixer, headers, action)
...@@ -318,7 +324,8 @@ Strophe.addConnectionPlugin('rayo', ...@@ -318,7 +324,8 @@ Strophe.addConnectionPlugin('rayo',
var value = $(this).attr('value'); var value = $(this).attr('value');
headers[name] = value; headers[name] = value;
}); });
$(presence).find('complete').each(function() $(presence).find('complete').each(function()
{ {
...@@ -336,19 +343,21 @@ Strophe.addConnectionPlugin('rayo', ...@@ -336,19 +343,21 @@ Strophe.addConnectionPlugin('rayo',
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
var callFrom = $(this).attr('from'); var callFrom = $(this).attr('from');
var callTo = $(this).attr('value'); var callTo = $(this).attr('to');
var callId = Strophe.getNodeFromJid(from); var callId = Strophe.getNodeFromJid(from);
var mixer = headers['mixer-name']
var call = { var call = {
digit: function(tone) {that.digit(callId, tone);}, digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);}, hangup: function() {that.hangup(callId);},
answer: function(callId, headers) {that.answer(callId, headers);}, answer: function() {that.answer(callId, mixer, headers);},
from: callFrom, from: callFrom,
to: callTo, to: callTo,
id: callId id: callId
} }
if (that.callbacks && that.callbacks.onOffer) that.callbacks.onOffer(call, headers); if (that.callbacks && that.callbacks.onOffer) that.callbacks.onOffer(call, headers);
var iq = $iq({to: from, from: that._connection.jid, type: "get"}).c("accept", {xmlns: Strophe.NS.RAYO_CORE}); var iq = $iq({to: from, from: that._connection.jid, type: "get"}).c("accept", {xmlns: Strophe.NS.RAYO_CORE});
...@@ -389,17 +398,32 @@ Strophe.addConnectionPlugin('rayo', ...@@ -389,17 +398,32 @@ Strophe.addConnectionPlugin('rayo',
{ {
} }
});
$(presence).find('started-speaking').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
if (that.callbacks && that.callbacks.onSpeaking) that.callbacks.onSpeaking(callId, headers);
}
}); });
$(presence).find('ringing').each(function() $(presence).find('stopped-speaking').each(function()
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
if (that.handsetId != Strophe.getNodeFromJid(from)) var callId = Strophe.getNodeFromJid(from);
{ if (that.callbacks && that.callbacks.offSpeaking) that.callbacks.offSpeaking(callId, headers);
var callId = Strophe.getNodeFromJid(from); }
if (that.callbacks && that.callbacks.onRing) that.callbacks.onRing(callId, headers); });
}
$(presence).find('ringing').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
if (that.callbacks && that.callbacks.onRing) that.callbacks.onRing(callId, headers);
} }
}); });
...@@ -407,30 +431,28 @@ Strophe.addConnectionPlugin('rayo', ...@@ -407,30 +431,28 @@ Strophe.addConnectionPlugin('rayo',
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
if (that.handsetId != Strophe.getNodeFromJid(from)) var callId = Strophe.getNodeFromJid(from);
{
var callId = Strophe.getNodeFromJid(from); if (headers['call-protocol'] == "WebRtc")
if (that.callbacks && that.callbacks.onAnswer) that.callbacks.onAnswer(callId, headers); {
if (that.callbacks && that.callbacks.offHook) that.callbacks.offHook();
} else { } else {
if (that.callbacks && that.callbacks.onReady) that.callbacks.onReady(); if (that.callbacks && that.callbacks.onAnswer) that.callbacks.onAnswer(callId, headers);
} }
} }
}); });
$(presence).find('end').each(function() $(presence).find('end').each(function()
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
if (that.handsetId != Strophe.getNodeFromJid(from)) var callId = Strophe.getNodeFromJid(from);
{ that._onhook();
var callId = Strophe.getNodeFromJid(from);
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers); if (that.callbacks && that.callbacks.onHook) that.callbacks.onHook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
} else {
if (that.callbacks && that.callbacks.onUnready) that.callbacks.onUnready();
}
} }
}); });
......
...@@ -90,7 +90,7 @@ public class CallParticipant { ...@@ -90,7 +90,7 @@ public class CallParticipant {
private String remoteMediaInfo = null; private String remoteMediaInfo = null;
private ProxyCredentials proxyCredentials = null; private ProxyCredentials proxyCredentials = null;
private RelayChannel relayChannel = null; private RelayChannel relayChannel = null;
private boolean autoAnswer = true; private boolean autoAnswer = false;
private long startTimestamp = 0; private long startTimestamp = 0;
private long endTimestamp = 0; private long endTimestamp = 0;
private Map<String, String> headers = new HashMap<String, String>(); private Map<String, String> headers = new HashMap<String, String>();
......
...@@ -376,6 +376,7 @@ public class RayoComponent extends AbstractComponent ...@@ -376,6 +376,7 @@ public class RayoComponent extends AbstractComponent
IQ reply = IQ.createResultIQ(iq); IQ reply = IQ.createResultIQ(iq);
Map<String, String> headers = command.getHeaders(); Map<String, String> headers = command.getHeaders();
headers.put("call-protocol", "XMPP");
try { try {
Presence presence = new Presence(); Presence presence = new Presence();
...@@ -398,17 +399,22 @@ public class RayoComponent extends AbstractComponent ...@@ -398,17 +399,22 @@ public class RayoComponent extends AbstractComponent
IQ reply = IQ.createResultIQ(iq); IQ reply = IQ.createResultIQ(iq);
Map<String, String> headers = command.getHeaders(); Map<String, String> headers = command.getHeaders();
headers.put("call-protocol", "XMPP");
try { try {
String handsetId = JID.escapeNode(iq.getFrom().toString()); Presence presence1 = new Presence(); //to caller
presence1.setFrom(iq.getTo());
Presence presence = new Presence(); presence1.setTo(JID.unescapeNode(iq.getTo().getNode()));
presence.setFrom(iq.getTo()); presence1.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers)));
presence.setTo(JID.unescapeNode(iq.getTo().getNode())); sendPacket(presence1);
presence.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers))); Presence presence2 = new Presence(); //to called
sendPacket(presence); presence2.setFrom(iq.getTo());
presence2.setTo(iq.getFrom());
presence2.getElement().add(rayoProvider.toXML(new AnsweredEvent(null, headers)));
sendPacket(presence2);
String handsetId = iq.getTo().getNode(); // use mixer of caller
RelayChannel channel = plugin.getRelayChannel(handsetId); RelayChannel channel = plugin.getRelayChannel(handsetId);
if (channel != null) if (channel != null)
...@@ -435,14 +441,21 @@ public class RayoComponent extends AbstractComponent ...@@ -435,14 +441,21 @@ public class RayoComponent extends AbstractComponent
String recording = handset.mixer + "-" + cp.getStartTimestamp() + ".au"; String recording = handset.mixer + "-" + cp.getStartTimestamp() + ".au";
conferenceManager.recordConference(true, recording, "au"); conferenceManager.recordConference(true, recording, "au");
Config.createCallRecord(username, recording, "xmpp:" + iq.getFrom().toString(), cp.getStartTimestamp(), 0, "dialed") ;
String source = (new JID(JID.unescapeNode(iq.getTo().getNode()))).getNode();
String destination = iq.getFrom().getNode();
Config.createCallRecord(source, recording, destination, cp.getStartTimestamp(), 0, "dialed") ;
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);
} }
} } 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) { } catch (Exception e) {
reply.setError(PacketError.Condition.item_not_found); reply.setError(PacketError.Condition.item_not_found);
...@@ -454,18 +467,37 @@ public class RayoComponent extends AbstractComponent ...@@ -454,18 +467,37 @@ public class RayoComponent extends AbstractComponent
private IQ handleHangupCommand(IQ iq) private IQ handleHangupCommand(IQ iq)
{ {
Log.info("RayoComponent handleHangupCommand " + iq.getFrom()); String callId = iq.getTo().getNode();
Log.info("RayoComponent handleHangupCommand " + iq.getFrom() + " " + callId);
IQ reply = IQ.createResultIQ(iq); IQ reply = IQ.createResultIQ(iq);
try { CallHandler callHandler = CallHandler.findCall(callId);
CallHandler callHandler = CallHandler.findCall(iq.getTo().getNode());
if (callHandler != null)
{
Log.info("RayoComponent handleHangupCommand found callhandler " + callId);
CallHandler.hangup(iq.getTo().getNode(), "User requested call termination"); CallHandler.hangup(iq.getTo().getNode(), "User requested call termination");
} catch (NoSuchElementException e) { } else {
reply.setError(PacketError.Condition.item_not_found); reply.setError(PacketError.Condition.item_not_found);
} }
try {
JID otherParty = new JID(JID.unescapeNode(callId));
Log.info("RayoComponent handleHangupCommand found other party " + otherParty);
Presence presence1 = new Presence();
presence1.setFrom(iq.getTo());
presence1.setTo(otherParty);
presence1.getElement().add(rayoProvider.toXML(new EndEvent(null, null)));
sendPacket(presence1);
} catch (Exception e) { }
return reply; return reply;
} }
...@@ -591,14 +623,14 @@ public class RayoComponent extends AbstractComponent ...@@ -591,14 +623,14 @@ public class RayoComponent extends AbstractComponent
headers.put("caller-name", callerName); headers.put("caller-name", callerName);
} }
if (calledName == null)
{
calledName = to;
headers.put("called-name", calledName);
}
if (toPhone) if (toPhone)
{ {
if (calledName == null)
{
calledName = to;
headers.put("called-name", calledName);
}
CallParticipant cp = new CallParticipant(); CallParticipant cp = new CallParticipant();
cp.setVoiceDetection(true); cp.setVoiceDetection(true);
cp.setCallOwner(handsetId); cp.setCallOwner(handsetId);
...@@ -614,30 +646,50 @@ public class RayoComponent extends AbstractComponent ...@@ -614,30 +646,50 @@ public class RayoComponent extends AbstractComponent
} else if (toXmpp){ } else if (toXmpp){
headers.put("call-protocol", "XMPP");
String destination = to.substring(5); String destination = to.substring(5);
String mixer = JID.escapeNode(destination); String source = JID.escapeNode(handsetId);
Presence presence = new Presence(); RelayChannel channel = plugin.getRelayChannel(source); // user mixer of caller
presence.setFrom(mixer + "@rayo." + getDomain());
presence.setTo(new JID(destination));
headers.put("mixer-name", mixer); if (channel != null)
{
headers.put("mixer-name", channel.getHandset().mixer);
OfferEvent offer = new OfferEvent(callId); Presence presence = new Presence();
presence.setFrom(source + "@rayo." + getDomain());
presence.setTo(new JID(destination));
try { OfferEvent offer = new OfferEvent(callId);
offer.setFrom(new URI("xmpp:" + iq.getFrom().toString()));
offer.setTo(new URI(to));
} catch (URISyntaxException e) { try {
reply.setError(PacketError.Condition.feature_not_implemented); offer.setFrom(new URI("xmpp:" + iq.getFrom().toString()));
return reply; offer.setTo(new URI(to));
}
} catch (URISyntaxException e) {
reply.setError(PacketError.Condition.feature_not_implemented);
return reply;
}
offer.setHeaders(headers); if (calledName == null)
{
calledName = presence.getTo().getNode();
headers.put("called-name", calledName);
}
presence.getElement().add(rayoProvider.toXML(offer)); offer.setHeaders(headers);
sendPacket(presence);
presence.getElement().add(rayoProvider.toXML(offer));
sendPacket(presence);
final Element childElement = reply.setChildElement("ref", "urn:xmpp:rayo:1");
childElement.addAttribute(URI, (String) "xmpp:" + destination);
childElement.addAttribute(ID, (String) JID.escapeNode(destination));
} else {
reply.setError(PacketError.Condition.item_not_found);
}
} else { } else {
reply.setError(PacketError.Condition.feature_not_implemented); reply.setError(PacketError.Condition.feature_not_implemented);
...@@ -873,6 +925,7 @@ public class RayoComponent extends AbstractComponent ...@@ -873,6 +925,7 @@ public class RayoComponent extends AbstractComponent
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());
Presence presence = new Presence(); Presence presence = new Presence();
presence.setFrom(callEvent.getCallId() + "@rayo." + getDomain()); presence.setFrom(callEvent.getCallId() + "@rayo." + getDomain());
...@@ -880,7 +933,7 @@ public class RayoComponent extends AbstractComponent ...@@ -880,7 +933,7 @@ public class RayoComponent extends AbstractComponent
if ("001 STATE CHANGED".equals(myEvent)) if ("001 STATE CHANGED".equals(myEvent))
{ {
if ("110 ANSWERED".equals(callState)) { if ("100 INVITED".equals(callState)) {
presence.getElement().add(rayoProvider.toXML(new RingingEvent(null, headers))); presence.getElement().add(rayoProvider.toXML(new RingingEvent(null, headers)));
sendPacket(presence); sendPacket(presence);
......
...@@ -51,16 +51,16 @@ Strophe.addConnectionPlugin('rayo', ...@@ -51,16 +51,16 @@ Strophe.addConnectionPlugin('rayo',
hangup: function(callId) hangup: function(callId)
{ {
console.log("hangup " + callId); //console.log("hangup " + callId);
var that = this; 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}); var iq = $iq({to: callId + "@rayo." + this._connection.domain, from: this._connection.jid, type: "get"}).c("hangup", {xmlns: Strophe.NS.RAYO_CORE});
console.log(iq.toString()); //console.log(iq.toString());
that._connection.sendIQ(iq, function(response) that._connection.sendIQ(iq, function(response)
{ {
console.log(response); //console.log(response);
if ($(response).attr('type') != "result") if ($(response).attr('type') != "result")
{ {
...@@ -87,18 +87,18 @@ Strophe.addConnectionPlugin('rayo', ...@@ -87,18 +87,18 @@ Strophe.addConnectionPlugin('rayo',
}); });
}, },
answer: function(callId, headers) answer: function(callId, mixer, headers)
{ {
//console.log('Rayo plugin accept ' + callId); //console.log('Rayo plugin accept ' + callId + " " + mixer);
//console.log(headers) //console.log(headers)
var that = this; var that = this;
if (this._isOffhook()) this._onhook(); //if (this._isOffhook()) this._onhook();
this._offhook(callId, headers, function() this._offhook(mixer, headers, function()
{ {
var iq = $iq({to: "rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("answer", {xmlns: Strophe.NS.RAYO_CORE}); var iq = $iq({to: callId + "@rayo." + that._connection.domain, from: that._connection.jid, type: "get"}).c("answer", {xmlns: Strophe.NS.RAYO_CORE});
if (headers) if (headers)
{ {
...@@ -113,7 +113,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -113,7 +113,7 @@ Strophe.addConnectionPlugin('rayo',
} }
} }
console.log(iq.toString()); //console.log(iq.toString());
that._connection.sendIQ(iq, function(response) that._connection.sendIQ(iq, function(response)
{ {
...@@ -131,12 +131,18 @@ Strophe.addConnectionPlugin('rayo', ...@@ -131,12 +131,18 @@ Strophe.addConnectionPlugin('rayo',
//console.log(headers) //console.log(headers)
var that = this; var that = this;
var mixer = "rayo-mixer-" + 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 (this._isOffhook()) this._onhook(); if (to.indexOf("xmpp:") == 0)
{
callId = Strophe.escapeNode(to.substring(5));
}
//if (this._isOffhook()) this._onhook();
this._offhook(callId, headers, function() this._offhook(mixer, headers, function()
{ {
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});
...@@ -155,7 +161,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -155,7 +161,7 @@ Strophe.addConnectionPlugin('rayo',
} }
} }
console.log(iq.toString()); //console.log(iq.toString());
that._connection.sendIQ(iq, function(response) that._connection.sendIQ(iq, function(response)
{ {
...@@ -206,7 +212,16 @@ Strophe.addConnectionPlugin('rayo', ...@@ -206,7 +212,16 @@ Strophe.addConnectionPlugin('rayo',
//console.log('Rayo plugin _offhook1 ' + mixer); //console.log('Rayo plugin _offhook1 ' + mixer);
var that = this; var that = this;
that.pc1 = new webkitRTCPeerConnection(null); that.pc1 = new webkitRTCPeerConnection(null);
that.pc2 = new webkitRTCPeerConnection(null);
that.pc2.onaddstream = function(e)
{
that.audio = new Audio();
that.audio.autoplay = true;
that.audio.src = webkitURL.createObjectURL(e.stream)
};
that.pc1.addStream(that.localStream); that.pc1.addStream(that.localStream);
that.pc1.createOffer(function(desc) that.pc1.createOffer(function(desc)
...@@ -234,16 +249,7 @@ Strophe.addConnectionPlugin('rayo', ...@@ -234,16 +249,7 @@ Strophe.addConnectionPlugin('rayo',
that._offhook2(mixer, headers, action); that._offhook2(mixer, headers, action);
}); });
}); });
that.pc2 = new webkitRTCPeerConnection(null);
that.pc2.onaddstream = function(e)
{
that.audio = new Audio();
that.audio.autoplay = true;
that.audio.src = webkitURL.createObjectURL(e.stream)
};
}, },
_offhook2: function(mixer, headers, action) _offhook2: function(mixer, headers, action)
...@@ -318,7 +324,8 @@ Strophe.addConnectionPlugin('rayo', ...@@ -318,7 +324,8 @@ Strophe.addConnectionPlugin('rayo',
var value = $(this).attr('value'); var value = $(this).attr('value');
headers[name] = value; headers[name] = value;
}); });
$(presence).find('complete').each(function() $(presence).find('complete').each(function()
{ {
...@@ -336,19 +343,21 @@ Strophe.addConnectionPlugin('rayo', ...@@ -336,19 +343,21 @@ Strophe.addConnectionPlugin('rayo',
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
var callFrom = $(this).attr('from'); var callFrom = $(this).attr('from');
var callTo = $(this).attr('value'); var callTo = $(this).attr('to');
var callId = Strophe.getNodeFromJid(from); var callId = Strophe.getNodeFromJid(from);
var mixer = headers['mixer-name']
var call = { var call = {
digit: function(tone) {that.digit(callId, tone);}, digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);}, hangup: function() {that.hangup(callId);},
answer: function(callId, headers) {that.answer(callId, headers);}, answer: function() {that.answer(callId, mixer, headers);},
from: callFrom, from: callFrom,
to: callTo, to: callTo,
id: callId id: callId
} }
if (that.callbacks && that.callbacks.onOffer) that.callbacks.onOffer(call, headers); if (that.callbacks && that.callbacks.onOffer) that.callbacks.onOffer(call, headers);
var iq = $iq({to: from, from: that._connection.jid, type: "get"}).c("accept", {xmlns: Strophe.NS.RAYO_CORE}); var iq = $iq({to: from, from: that._connection.jid, type: "get"}).c("accept", {xmlns: Strophe.NS.RAYO_CORE});
...@@ -389,17 +398,32 @@ Strophe.addConnectionPlugin('rayo', ...@@ -389,17 +398,32 @@ Strophe.addConnectionPlugin('rayo',
{ {
} }
});
$(presence).find('started-speaking').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
if (that.callbacks && that.callbacks.onSpeaking) that.callbacks.onSpeaking(callId, headers);
}
}); });
$(presence).find('ringing').each(function() $(presence).find('stopped-speaking').each(function()
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
if (that.handsetId != Strophe.getNodeFromJid(from)) var callId = Strophe.getNodeFromJid(from);
{ if (that.callbacks && that.callbacks.offSpeaking) that.callbacks.offSpeaking(callId, headers);
var callId = Strophe.getNodeFromJid(from); }
if (that.callbacks && that.callbacks.onRing) that.callbacks.onRing(callId, headers); });
}
$(presence).find('ringing').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
if (that.callbacks && that.callbacks.onRing) that.callbacks.onRing(callId, headers);
} }
}); });
...@@ -407,30 +431,28 @@ Strophe.addConnectionPlugin('rayo', ...@@ -407,30 +431,28 @@ Strophe.addConnectionPlugin('rayo',
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
if (that.handsetId != Strophe.getNodeFromJid(from)) var callId = Strophe.getNodeFromJid(from);
{
var callId = Strophe.getNodeFromJid(from); if (headers['call-protocol'] == "WebRtc")
if (that.callbacks && that.callbacks.onAnswer) that.callbacks.onAnswer(callId, headers); {
if (that.callbacks && that.callbacks.offHook) that.callbacks.offHook();
} else { } else {
if (that.callbacks && that.callbacks.onReady) that.callbacks.onReady(); if (that.callbacks && that.callbacks.onAnswer) that.callbacks.onAnswer(callId, headers);
} }
} }
}); });
$(presence).find('end').each(function() $(presence).find('end').each(function()
{ {
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE) if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{ {
if (that.handsetId != Strophe.getNodeFromJid(from)) var callId = Strophe.getNodeFromJid(from);
{ that._onhook();
var callId = Strophe.getNodeFromJid(from);
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers); if (that.callbacks && that.callbacks.onHook) that.callbacks.onHook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
} else {
if (that.callbacks && that.callbacks.onUnready) that.callbacks.onUnready();
}
} }
}); });
......
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