Commit 4330588a 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@13763 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7692b193
......@@ -20,10 +20,13 @@
var domain = "81.201.82.25";
var prefix = "sip:";
var ringtone;
var username = null;
var password = null;
var jid = window.location.hostname;
window.dialer = new Dialpad({
onPress: function (key) {
console.log('a key was pressed', key);
//console.log('a key was pressed', key);
if (window.candybar.call) window.candybar.call.digit(key);
},
......@@ -32,12 +35,12 @@
//makeCall(number);
},
onHide: function () {
console.log('removed it');
//console.log('removed it');
},
onCall: function (number) {
if (window.dialer.getCallLabel() == "Call") {
console.log('The call button was pressed', number);
//console.log('The call button was pressed', number);
makeCall(number);
} else if (window.dialer.getCallLabel() == "Hangup") {
......@@ -60,6 +63,8 @@
if (urlParam("prefix")) prefix = urlParam("prefix");
if (urlParam("domain")) domain = urlParam("domain");
if (urlParam("username")) username = urlParam("username");
if (urlParam("password")) password = urlParam("password");
if (domain == "81.201.82.25" && prefix == "sip:") prefix = "sip:883510";
if (prefix == "tel:") domain = "";
......@@ -71,10 +76,17 @@
{
iNum = Math.random().toString(36).substr(2,9);
}
if (username && password)
{
iNum = username;
jid = username + "@" + window.location.hostname
}
window.connection = new Openfire.Connection(window.location.protocol + '//' + window.location.host + '/http-bind/');
window.connection.resource = iNum;
window.connection.connect(window.location.hostname, null, function (status)
window.connection.connect(jid, password, function (status)
{
//console.log("XMPPConnection.connect");
//console.log(status);
......@@ -89,21 +101,21 @@
});
setPhone();
}
});
var destination = urlParam("destination");
var destination = urlParam("destination");
if (destination)
{
makeCall(destination);
}
if (destination)
{
makeCall(destination);
}
}
});
})
function setPhone()
{
console.log("setPhone()");
//console.log("setPhone()");
if (window.connection)
{
......@@ -128,6 +140,11 @@
$("#status").html("Started Speaking");
},
onAccept: function(call) {
window.candybar.call = call;
},
onOffer: function(call, headers) {
//console.log('onOffer ' + call.from);
//console.log(headers);
......@@ -178,7 +195,16 @@
startTone("ringback-uk");
},
onJoin: function(jid, mixer) {
//console.log('onJoin ' + jid + " " + mixer);
},
onUnjoin: function(jid, mixer) {
//console.log('onUnjoin ' + jid + " " + mixer);
},
onError: function(e) {
console.error(e);
}
});
......@@ -187,7 +213,7 @@
function makeCall(destination)
{
console.log("makeCall " + destination);
//console.log("makeCall " + destination);
var sipUri = prefix + destination + "@" + domain
......@@ -196,7 +222,7 @@
if (prefix == "xmpp:") sipUri = prefix + destination + "@" + domain + "/" + destination;
window.candybar.call = window.connection.rayo.dial("xmpp:" + window.connection.jid, sipUri, {
window.connection.rayo.dial("xmpp:" + window.connection.jid, sipUri, {
codec_name: "PCMU",
});
......
......@@ -58,14 +58,13 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
that._connection.sendIQ(iq, null, function(error)
{
//console.log(response);
if ($(response).attr('type') != "result")
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("hangup failure");
}
var errorcode = $(this).attr('code');
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("hangup failure " + errorcode);
});
});
this._onhook();
......@@ -78,12 +77,13 @@ Strophe.addConnectionPlugin('rayo',
var that = this;
var iq = $iq({to: callId + "@rayo." + this._connection.domain, from: this._connection.jid, type: "get"}).c("dtmf", {xmlns: Strophe.NS.RAYO_CORE, tones: key});
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, null, function(error)
{
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dtmf failure");
}
var errorcode = $(this).attr('code');
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dtmf failure " + errorcode);
});
});
},
......@@ -115,12 +115,14 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, null, function(error)
{
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("answer failure");
}
var errorcode = $(this).attr('code');
if (that._isOffhook()) that._onhook();
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("answer failure " + errorcode);
});
});
});
},
......@@ -140,7 +142,7 @@ Strophe.addConnectionPlugin('rayo',
callId = Strophe.escapeNode(to.substring(5));
}
//if (this._isOffhook()) this._onhook();
if (this._isOffhook()) this._onhook();
this._offhook(mixer, headers, function()
{
......@@ -163,24 +165,38 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, function(response) {
$('ref', response).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dial failure");
}
});
});
callId = $(this).attr('id');
return {
digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);},
if (that.callbacks && that.callbacks.onAccept)
{
that.callbacks.onAccept(
{
digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);},
from: from,
to: to,
id: callId
});
}
});
from: from,
to: to,
id: callId
}
}, function(error){
$('error', error).each(function()
{
var errorcode = $(this).attr('code');
if (that._isOffhook()) that._onhook();
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dial failure " + errorcode);
});
that._onhook();
});
});
},
......@@ -267,32 +283,31 @@ Strophe.addConnectionPlugin('rayo',
var that = this;
var stereo = (headers && headers.stereo_pan) ? headers.stereo_pan : (that.callbacks.stereo_pan ? that.callbacks.stereo_pan : "0");
var codec = (headers && headers.codec_name) ? headers.codec_name : (that.callbacks.codec_name ? that.callbacks.codec_name : "OPUS");
var group = (headers && headers.group_name) ? headers.group_name : "";
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, group: group});
//console.log(iq.toString())
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') == "result")
{
$('ref', response).each(function()
{
that.handsetId = $(this).attr('id');
that.handsetUri = $(this).attr('uri');
that.relayHost = $(this).attr('host');
that.relayLocalPort = $(this).attr('localport');
that.relayRemotePort = $(this).attr('remoteport');
that.pc2.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayRemotePort + " typ host generation 0"}));
that.pc1.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayLocalPort + " typ host generation 0"}));
{
$('ref', response).each(function()
{
that.handsetId = $(this).attr('id');
that.handsetUri = $(this).attr('uri');
that.relayHost = $(this).attr('host');
that.relayLocalPort = $(this).attr('localport');
that.relayRemotePort = $(this).attr('remoteport');
action();
});
that.pc2.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayRemotePort + " typ host generation 0"}));
that.pc1.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayLocalPort + " typ host generation 0"}));
} else {
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("offhook failure");
}
action();
});
}, function (error) {
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("offhook failure");
});
},
......@@ -311,7 +326,7 @@ Strophe.addConnectionPlugin('rayo',
that.pc1.close();
that.pc2.close();
that.pc1 = null;
that.pc2 = null;
that.pc2 = null;
});
},
......@@ -382,12 +397,13 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, null, function(error)
{
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("accept failure");
}
var errorcode = $(this).attr('code');
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("accept failure " + errorcode);
});
});
}
})
......@@ -395,22 +411,36 @@ Strophe.addConnectionPlugin('rayo',
$(presence).find('joined').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
{
var callId = Strophe.getNodeFromJid(from);
var jid = Strophe.unescapeNode(callId);
if (jid.indexOf("@") > -1 && jid.indexOf("/") > -1)
{
if (that.callbacks && that.callbacks.onJoin) that.callbacks.onJoin(jid, $(this).attr('mixer-name'));
}
}
});
$(presence).find('unjoined').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
{
var callId = Strophe.getNodeFromJid(from);
var jid = Strophe.unescapeNode(callId);
if (callId.indexOf("rayo-incoming-") == 0)
if (jid.indexOf("@") > -1 && jid.indexOf("/") > -1)
{
that._onhook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
if (that.callbacks && that.callbacks.onUnjoin) that.callbacks.onUnjoin(jid, $(this).attr('mixer-name'));
} else {
if (callId.indexOf("rayo-incoming-") == 0)
{
that._onhook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
}
}
}
});
......
......@@ -49,6 +49,8 @@ public class Handset extends BaseVerb {
@NotNull(message=Handset.MISSING_MIXER)
public String mixer;
public String group;
public Handset(String cryptoSuite, String localCrypto, String remoteCrypto, String codec, String stereo, String mixer)
{
this.cryptoSuite = cryptoSuite;
......
......@@ -76,7 +76,9 @@ public class HandsetProvider extends BaseProvider {
element.attributeValue("stereo"),
element.attributeValue("mixer"));
OffHookCommand command = new OffHookCommand();
handset.group = element.attributeValue("group");
OffHookCommand command = new OffHookCommand();
command.setHandset(handset);
return command;
......
......@@ -516,14 +516,28 @@ public class ConferenceManager {
return displayName;
}
public static String getDisplayName(String conferenceId) {
try {
ConferenceManager conferenceManager =
findConferenceManager(conferenceId);
return conferenceManager.getDisplayName();
} catch (ParseException e) {
return null;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public static String getDisplayName(String conferenceId)
{
try {
ConferenceManager conferenceManager = findConferenceManager(conferenceId);
return conferenceManager.getDisplayName();
} catch (ParseException e) {
return null;
}
}
public static void setDisplayName(String conferenceId, String displayName)
{
try {
ConferenceManager conferenceManager = findConferenceManager(conferenceId);
conferenceManager.setDisplayName(displayName);
} catch (ParseException e) {
}
}
public void setPermanent(boolean permanent) {
......
......@@ -580,7 +580,7 @@ public class ConferenceMember implements TreatmentDoneListener,
}
conferenceManager.joinDistributedConference(this);
joinedDistributedConference = true;
joinedDistributedConference = false;
}
public void reinitialize(ConferenceManager conferenceManager) {
......
......@@ -24,6 +24,9 @@ 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.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.packet.JID;
......@@ -286,6 +289,14 @@ public class RayoComponent extends AbstractComponent
cp.setVoiceDetection(true);
cp.setCallOwner(channel.getFrom().toString());
if (handset.group != null && ! "".equals(handset.group))
{
// set for new or existing conference
ConferenceManager.getConference(handset.mixer, channel.getMediaPreference(), handset.group, false);
ConferenceManager.setDisplayName(handset.mixer, handset.group);
}
callHandler = new OutgoingCallHandler(this, cp);
callHandler.start();
......@@ -469,6 +480,7 @@ 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");
......@@ -700,45 +712,61 @@ public class RayoComponent extends AbstractComponent
headers.put("call_protocol", "XMPP");
String destination = to.substring(5);
String source = JID.escapeNode(handsetId);
RelayChannel channel = plugin.getRelayChannel(source); // user mixer of caller
JID destination = getJID(to.substring(5));
if (channel != null)
if (destination != null)
{
headers.put("mixer_name", channel.getHandset().mixer);
headers.put("codec_name", channel.getHandset().codec);
Presence presence = new Presence();
presence.setFrom(source + "@rayo." + getDomain());
presence.setTo(new JID(destination));
OfferEvent offer = new OfferEvent(callId);
try {
offer.setFrom(new URI("xmpp:" + iq.getFrom().toString()));
offer.setTo(new URI(to));
String source = JID.escapeNode(handsetId);
} catch (URISyntaxException e) {
reply.setError(PacketError.Condition.feature_not_implemented);
return reply;
}
RelayChannel channel = plugin.getRelayChannel(source); // user mixer of caller
if (calledName == null)
if (channel != null)
{
calledName = presence.getTo().getNode();
headers.put("called_name", calledName);
}
headers.put("mixer_name", channel.getHandset().mixer);
headers.put("codec_name", channel.getHandset().codec);
offer.setHeaders(headers);
if (findUser(destination.getNode()) != null)
{
routeXMPPCall(reply, destination, source, callId, calledName, headers);
presence.getElement().add(rayoProvider.toXML(offer));
sendPacket(presence);
} else {
int count = 0;
try {
Group group = GroupManager.getInstance().getGroup(destination.getNode());
for (JID memberJID : group.getMembers())
{
if (iq.getFrom().toBareJID().equals(memberJID.toBareJID()) == false)
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(memberJID.getNode());
for (ClientSession session : sessions)
{
routeXMPPCall(reply, session.getAddress(), source, callId, calledName, headers);
count++;
}
}
}
if (count == 0)
{
reply.setError(PacketError.Condition.item_not_found);
return reply;
}
// tag conf with group name
ConferenceManager.setDisplayName(channel.getHandset().mixer, destination.getNode());
} catch (GroupNotFoundException e) {
reply.setError(PacketError.Condition.item_not_found);
return reply;
}
}
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 {
reply.setError(PacketError.Condition.item_not_found);
......@@ -752,6 +780,40 @@ public class RayoComponent extends AbstractComponent
return reply;
}
private void routeXMPPCall(IQ reply, JID destination, String source, String callId, String calledName, Map<String, String> headers)
{
Presence presence = new Presence();
presence.setFrom(source + "@rayo." + getDomain());
presence.setTo(destination);
OfferEvent offer = new OfferEvent(callId);
try {
offer.setFrom(new URI("xmpp:" + JID.unescapeNode(source)));
offer.setTo(new URI("xmpp:" + destination));
} catch (URISyntaxException e) {
reply.setError(PacketError.Condition.feature_not_implemented);
return;
}
if (calledName == null)
{
calledName = presence.getTo().getNode();
headers.put("called_name", calledName);
}
offer.setHeaders(headers);
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.toString()));
}
private IQ handleBridgedDialCommand(DialCommand command, IQ iq)
{
Log.info("RayoComponent handleBridgedDialCommand " + iq.getFrom());
......@@ -1125,23 +1187,26 @@ public class RayoComponent extends AbstractComponent
{
Log.info("RayoComponent notifyConferenceMonitors found owner " + callParticipant.getCallOwner());
Presence presence = new Presence();
presence.setFrom(conferenceEvent.getCallId() + "@rayo." + getDomain());
presence.setTo(callParticipant.getCallOwner());
String groupName = ConferenceManager.getDisplayName(conferenceEvent.getConferenceId());
if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT))
if (groupName == null)
{
UnjoinedEvent event = new UnjoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event));
finishCallRecord(callParticipant);
routeJoinEvent(callParticipant.getCallOwner(), callParticipant, conferenceEvent);
} else {
JoinedEvent event = new JoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event));
}
sendPacket(presence);
Group group = GroupManager.getInstance().getGroup(groupName);
for (JID memberJID : group.getMembers())
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(memberJID.getNode());
for (ClientSession session : sessions)
{
routeJoinEvent(memberJID.toString(), callParticipant, conferenceEvent);
}
}
}
}
}
......@@ -1165,6 +1230,28 @@ public class RayoComponent extends AbstractComponent
}
}
private void routeJoinEvent(String callee, CallParticipant callParticipant, ConferenceEvent conferenceEvent)
{
Presence presence = new Presence();
presence.setFrom(conferenceEvent.getCallId() + "@rayo." + getDomain());
presence.setTo(callee);
if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT))
{
UnjoinedEvent event = new UnjoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event));
finishCallRecord(callParticipant);
} else {
JoinedEvent event = new JoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event));
}
sendPacket(presence);
}
private JID findUser(String username)
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
......@@ -1195,39 +1282,68 @@ public class RayoComponent extends AbstractComponent
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);
Map<String, String> headers = cp.getHeaders();
headers.put("mixer_name", callId);
headers.put("call_protocol", "SIP");
if (foundUser != null) // send this call to specific user
{
String callId = "rayo-incoming-" + System.currentTimeMillis();
cp.setCallId(callId);
cp.setConferenceId(callId);
cp.setCallOwner(foundUser.toString());
routeSIPCall(foundUser, cp, callId, headers);
return true;
}
// send to members of group
try {
Group group = GroupManager.getInstance().getGroup(cp.getToPhoneNumber());
headers.put("group_name", cp.getToPhoneNumber());
for (JID memberJID : group.getMembers())
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(memberJID.getNode());
for (ClientSession session : sessions)
{
routeSIPCall(memberJID, cp, callId, headers);
}
}
return true;
Map<String, String> headers = cp.getHeaders();
headers.put("mixer_name", callId);
headers.put("call_protocol", "SIP");
} catch (GroupNotFoundException e) {
// Group not found
return false;
}
}
public void routeSIPCall(JID callee, CallParticipant cp, String callId, Map<String, String> headers)
{
Log.info("routeSIPCall to user " + callee);
if (callee != null) // send this call to user
{
Presence presence = new Presence();
presence.setFrom(callId + "@rayo." + getDomain());
presence.setTo(foundUser);
presence.setTo(callee);
OfferEvent offer = new OfferEvent(callId);
try {
offer.setTo(new URI("xmpp:" + foundUser.toString()));
offer.setTo(new URI("xmpp:" + callee.toString()));
offer.setFrom(new URI("sip:" + cp.getPhoneNumber()));
} catch (URISyntaxException e) {
Log.error("SIP phone nos not URI " + cp.getPhoneNumber() + " " + foundUser);
Log.error("SIP phone nos not URI " + cp.getPhoneNumber() + " " + callee);
}
headers.put("called_name", foundUser.getNode());
headers.put("called_name", callee.getNode());
headers.put("caller_name", cp.getName());
offer.setHeaders(headers);
presence.getElement().add(rayoProvider.toXML(offer));
sendPacket(presence);
}
return foundUser != null;
}
}
......@@ -58,14 +58,13 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
that._connection.sendIQ(iq, null, function(error)
{
//console.log(response);
if ($(response).attr('type') != "result")
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("hangup failure");
}
var errorcode = $(this).attr('code');
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("hangup failure " + errorcode);
});
});
this._onhook();
......@@ -78,12 +77,13 @@ Strophe.addConnectionPlugin('rayo',
var that = this;
var iq = $iq({to: callId + "@rayo." + this._connection.domain, from: this._connection.jid, type: "get"}).c("dtmf", {xmlns: Strophe.NS.RAYO_CORE, tones: key});
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, null, function(error)
{
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dtmf failure");
}
var errorcode = $(this).attr('code');
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dtmf failure " + errorcode);
});
});
},
......@@ -115,12 +115,14 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, null, function(error)
{
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("answer failure");
}
var errorcode = $(this).attr('code');
if (that._isOffhook()) that._onhook();
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("answer failure " + errorcode);
});
});
});
},
......@@ -140,7 +142,7 @@ Strophe.addConnectionPlugin('rayo',
callId = Strophe.escapeNode(to.substring(5));
}
//if (this._isOffhook()) this._onhook();
if (this._isOffhook()) this._onhook();
this._offhook(mixer, headers, function()
{
......@@ -163,24 +165,38 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, function(response) {
$('ref', response).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dial failure");
}
});
});
callId = $(this).attr('id');
return {
digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);},
if (that.callbacks && that.callbacks.onAccept)
{
that.callbacks.onAccept(
{
digit: function(tone) {that.digit(callId, tone);},
hangup: function() {that.hangup(callId);},
from: from,
to: to,
id: callId
});
}
});
from: from,
to: to,
id: callId
}
}, function(error){
$('error', error).each(function()
{
var errorcode = $(this).attr('code');
if (that._isOffhook()) that._onhook();
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("dial failure " + errorcode);
});
that._onhook();
});
});
},
......@@ -267,32 +283,31 @@ Strophe.addConnectionPlugin('rayo',
var that = this;
var stereo = (headers && headers.stereo_pan) ? headers.stereo_pan : (that.callbacks.stereo_pan ? that.callbacks.stereo_pan : "0");
var codec = (headers && headers.codec_name) ? headers.codec_name : (that.callbacks.codec_name ? that.callbacks.codec_name : "OPUS");
var group = (headers && headers.group_name) ? headers.group_name : "";
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, group: group});
//console.log(iq.toString())
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') == "result")
{
$('ref', response).each(function()
{
that.handsetId = $(this).attr('id');
that.handsetUri = $(this).attr('uri');
that.relayHost = $(this).attr('host');
that.relayLocalPort = $(this).attr('localport');
that.relayRemotePort = $(this).attr('remoteport');
that.pc2.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayRemotePort + " typ host generation 0"}));
that.pc1.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayLocalPort + " typ host generation 0"}));
{
$('ref', response).each(function()
{
that.handsetId = $(this).attr('id');
that.handsetUri = $(this).attr('uri');
that.relayHost = $(this).attr('host');
that.relayLocalPort = $(this).attr('localport');
that.relayRemotePort = $(this).attr('remoteport');
action();
});
that.pc2.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayRemotePort + " typ host generation 0"}));
that.pc1.addIceCandidate(new RTCIceCandidate({sdpMLineIndex: "0", candidate: "a=candidate:3707591233 1 udp 2113937151 " + that.relayHost + " " + that.relayLocalPort + " typ host generation 0"}));
} else {
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("offhook failure");
}
action();
});
}, function (error) {
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("offhook failure");
});
},
......@@ -311,7 +326,7 @@ Strophe.addConnectionPlugin('rayo',
that.pc1.close();
that.pc2.close();
that.pc1 = null;
that.pc2 = null;
that.pc2 = null;
});
},
......@@ -382,12 +397,13 @@ Strophe.addConnectionPlugin('rayo',
//console.log(iq.toString());
that._connection.sendIQ(iq, function(response)
{
if ($(response).attr('type') != "result")
that._connection.sendIQ(iq, null, function(error)
{
$('error', error).each(function()
{
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("accept failure");
}
var errorcode = $(this).attr('code');
if (that.callbacks && that.callbacks.onError) that.callbacks.onError("accept failure " + errorcode);
});
});
}
})
......@@ -395,22 +411,36 @@ Strophe.addConnectionPlugin('rayo',
$(presence).find('joined').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
{
var callId = Strophe.getNodeFromJid(from);
var jid = Strophe.unescapeNode(callId);
if (jid.indexOf("@") > -1 && jid.indexOf("/") > -1)
{
if (that.callbacks && that.callbacks.onJoin) that.callbacks.onJoin(jid, $(this).attr('mixer-name'));
}
}
});
$(presence).find('unjoined').each(function()
{
if ($(this).attr('xmlns') == Strophe.NS.RAYO_CORE)
{
var callId = Strophe.getNodeFromJid(from);
{
var callId = Strophe.getNodeFromJid(from);
var jid = Strophe.unescapeNode(callId);
if (callId.indexOf("rayo-incoming-") == 0)
if (jid.indexOf("@") > -1 && jid.indexOf("/") > -1)
{
that._onhook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
if (that.callbacks && that.callbacks.onUnjoin) that.callbacks.onUnjoin(jid, $(this).attr('mixer-name'));
} else {
if (callId.indexOf("rayo-incoming-") == 0)
{
that._onhook();
if (that.callbacks && that.callbacks.onEnd) that.callbacks.onEnd(callId, headers);
}
}
}
});
......
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