2015-01-19 09:20:00 +00:00
|
|
|
/* jshint -W117 */
|
|
|
|
module.exports = function() {
|
|
|
|
Strophe.addConnectionPlugin('rayo',
|
|
|
|
{
|
|
|
|
RAYO_XMLNS: 'urn:xmpp:rayo:1',
|
|
|
|
connection: null,
|
|
|
|
init: function (conn) {
|
|
|
|
this.connection = conn;
|
|
|
|
if (this.connection.disco) {
|
|
|
|
this.connection.disco.addFeature('urn:xmpp:rayo:client:1');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.connection.addHandler(
|
2015-09-11 02:42:15 +00:00
|
|
|
this.onRayo.bind(this), this.RAYO_XMLNS, 'iq', 'set',
|
|
|
|
null, null);
|
2015-01-19 09:20:00 +00:00
|
|
|
},
|
|
|
|
onRayo: function (iq) {
|
|
|
|
console.info("Rayo IQ", iq);
|
|
|
|
},
|
|
|
|
dial: function (to, from, roomName, roomPass) {
|
|
|
|
var self = this;
|
|
|
|
var req = $iq(
|
|
|
|
{
|
|
|
|
type: 'set',
|
2015-01-20 15:56:00 +00:00
|
|
|
to: this.connection.emuc.focusMucJid
|
2015-01-19 09:20:00 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
req.c('dial',
|
|
|
|
{
|
|
|
|
xmlns: this.RAYO_XMLNS,
|
|
|
|
to: to,
|
|
|
|
from: from
|
|
|
|
});
|
|
|
|
req.c('header',
|
|
|
|
{
|
|
|
|
name: 'JvbRoomName',
|
|
|
|
value: roomName
|
|
|
|
}).up();
|
|
|
|
|
|
|
|
if (roomPass !== null && roomPass.length) {
|
|
|
|
|
|
|
|
req.c('header',
|
|
|
|
{
|
|
|
|
name: 'JvbRoomPassword',
|
|
|
|
value: roomPass
|
|
|
|
}).up();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.connection.sendIQ(
|
|
|
|
req,
|
|
|
|
function (result) {
|
|
|
|
console.info('Dial result ', result);
|
|
|
|
|
|
|
|
var resource = $(result).find('ref').attr('uri');
|
2015-09-11 02:42:15 +00:00
|
|
|
self.call_resource = resource.substr('xmpp:'.length);
|
2015-01-19 09:20:00 +00:00
|
|
|
console.info(
|
2015-09-11 02:42:15 +00:00
|
|
|
"Received call resource: " + self.call_resource);
|
2015-01-19 09:20:00 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.info('Dial error ', error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
hang_up: function () {
|
|
|
|
if (!this.call_resource) {
|
|
|
|
console.warn("No call in progress");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var req = $iq(
|
|
|
|
{
|
|
|
|
type: 'set',
|
|
|
|
to: this.call_resource
|
|
|
|
}
|
|
|
|
);
|
|
|
|
req.c('hangup',
|
|
|
|
{
|
|
|
|
xmlns: this.RAYO_XMLNS
|
|
|
|
});
|
|
|
|
|
|
|
|
this.connection.sendIQ(
|
|
|
|
req,
|
|
|
|
function (result) {
|
|
|
|
console.info('Hangup result ', result);
|
|
|
|
self.call_resource = null;
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.info('Hangup error ', error);
|
|
|
|
self.call_resource = null;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|