2013-12-16 11:22:23 +00:00
|
|
|
/* jshint -W117 */
|
2014-03-01 07:39:39 +00:00
|
|
|
/* a simple MUC connection plugin
|
2013-12-16 11:22:23 +00:00
|
|
|
* can only handle a single MUC room
|
|
|
|
*/
|
|
|
|
Strophe.addConnectionPlugin('emuc', {
|
|
|
|
connection: null,
|
|
|
|
roomjid: null,
|
|
|
|
myroomjid: null,
|
|
|
|
members: {},
|
2014-02-10 22:25:57 +00:00
|
|
|
list_members: [], // so we can elect a new focus
|
2014-01-24 10:24:18 +00:00
|
|
|
presMap: {},
|
|
|
|
preziMap: {},
|
2013-12-17 13:10:47 +00:00
|
|
|
joined: false,
|
2013-12-16 11:22:23 +00:00
|
|
|
isOwner: false,
|
2014-11-28 15:05:10 +00:00
|
|
|
role: null,
|
2013-12-16 11:22:23 +00:00
|
|
|
init: function (conn) {
|
|
|
|
this.connection = conn;
|
|
|
|
},
|
2014-01-24 10:24:18 +00:00
|
|
|
initPresenceMap: function (myroomjid) {
|
|
|
|
this.presMap['to'] = myroomjid;
|
|
|
|
this.presMap['xns'] = 'http://jabber.org/protocol/muc';
|
|
|
|
},
|
2013-12-16 11:22:23 +00:00
|
|
|
doJoin: function (jid, password) {
|
|
|
|
this.myroomjid = jid;
|
2014-05-13 14:54:35 +00:00
|
|
|
|
|
|
|
console.info("Joined MUC as " + this.myroomjid);
|
|
|
|
|
2014-01-24 10:24:18 +00:00
|
|
|
this.initPresenceMap(this.myroomjid);
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
if (!this.roomjid) {
|
|
|
|
this.roomjid = Strophe.getBareJidFromJid(jid);
|
|
|
|
// add handlers (just once)
|
|
|
|
this.connection.addHandler(this.onPresence.bind(this), null, 'presence', null, null, this.roomjid, {matchBare: true});
|
|
|
|
this.connection.addHandler(this.onPresenceUnavailable.bind(this), null, 'presence', 'unavailable', null, this.roomjid, {matchBare: true});
|
|
|
|
this.connection.addHandler(this.onPresenceError.bind(this), null, 'presence', 'error', null, this.roomjid, {matchBare: true});
|
|
|
|
this.connection.addHandler(this.onMessage.bind(this), null, 'message', null, null, this.roomjid, {matchBare: true});
|
|
|
|
}
|
2013-12-16 17:25:25 +00:00
|
|
|
if (password !== undefined) {
|
2014-02-11 14:05:17 +00:00
|
|
|
this.presMap['password'] = password;
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-02-11 14:05:17 +00:00
|
|
|
this.sendPresence();
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
2014-05-11 22:41:58 +00:00
|
|
|
doLeave: function() {
|
2014-05-11 22:44:05 +00:00
|
|
|
console.log("do leave", this.myroomjid);
|
2014-05-11 22:41:58 +00:00
|
|
|
var pres = $pres({to: this.myroomjid, type: 'unavailable' });
|
|
|
|
this.presMap.length = 0;
|
|
|
|
this.connection.send(pres);
|
|
|
|
},
|
2013-12-16 11:22:23 +00:00
|
|
|
onPresence: function (pres) {
|
|
|
|
var from = pres.getAttribute('from');
|
|
|
|
var type = pres.getAttribute('type');
|
|
|
|
if (type != null) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-24 10:24:18 +00:00
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
// Parse etherpad tag.
|
|
|
|
var etherpad = $(pres).find('>etherpad');
|
|
|
|
if (etherpad.length) {
|
|
|
|
$(document).trigger('etherpadadded.muc', [from, etherpad.text()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse prezi tag.
|
2014-01-24 10:24:18 +00:00
|
|
|
var presentation = $(pres).find('>prezi');
|
|
|
|
if (presentation.length)
|
|
|
|
{
|
|
|
|
var url = presentation.attr('url');
|
|
|
|
var current = presentation.find('>current').text();
|
2014-05-30 15:18:32 +00:00
|
|
|
|
2014-01-24 10:24:18 +00:00
|
|
|
console.log('presentation info received from', from, url);
|
|
|
|
|
|
|
|
if (this.preziMap[from] == null) {
|
|
|
|
this.preziMap[from] = url;
|
|
|
|
|
|
|
|
$(document).trigger('presentationadded.muc', [from, url, current]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(document).trigger('gotoslide.muc', [from, url, current]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.preziMap[from] != null) {
|
|
|
|
var url = this.preziMap[from];
|
|
|
|
delete this.preziMap[from];
|
|
|
|
$(document).trigger('presentationremoved.muc', [from, url]);
|
|
|
|
}
|
|
|
|
|
2014-04-07 10:16:49 +00:00
|
|
|
// Parse audio info tag.
|
|
|
|
var audioMuted = $(pres).find('>audiomuted');
|
|
|
|
if (audioMuted.length) {
|
|
|
|
$(document).trigger('audiomuted.muc', [from, audioMuted.text()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse video info tag.
|
|
|
|
var videoMuted = $(pres).find('>videomuted');
|
|
|
|
if (videoMuted.length) {
|
|
|
|
$(document).trigger('videomuted.muc', [from, videoMuted.text()]);
|
|
|
|
}
|
|
|
|
|
2014-10-16 15:11:26 +00:00
|
|
|
var stats = $(pres).find('>stats');
|
|
|
|
if(stats.length)
|
|
|
|
{
|
|
|
|
var statsObj = {};
|
|
|
|
Strophe.forEachChild(stats[0], "stat", function (el) {
|
|
|
|
statsObj[el.getAttribute("name")] = el.getAttribute("value");
|
|
|
|
});
|
|
|
|
ConnectionQuality.updateRemoteStats(from, statsObj);
|
|
|
|
}
|
|
|
|
|
2014-04-07 10:16:49 +00:00
|
|
|
// Parse status.
|
2013-12-16 11:22:23 +00:00
|
|
|
if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="201"]').length) {
|
|
|
|
// http://xmpp.org/extensions/xep-0045.html#createroom-instant
|
|
|
|
this.isOwner = true;
|
|
|
|
var create = $iq({type: 'set', to: this.roomjid})
|
|
|
|
.c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'})
|
|
|
|
.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
|
|
|
|
this.connection.send(create); // fire away
|
|
|
|
}
|
|
|
|
|
2014-04-07 10:16:49 +00:00
|
|
|
// Parse roles.
|
2013-12-16 11:22:23 +00:00
|
|
|
var member = {};
|
|
|
|
member.show = $(pres).find('>show').text();
|
|
|
|
member.status = $(pres).find('>status').text();
|
|
|
|
var tmp = $(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>item');
|
2013-12-17 13:10:47 +00:00
|
|
|
member.affiliation = tmp.attr('affiliation');
|
2013-12-16 11:22:23 +00:00
|
|
|
member.role = tmp.attr('role');
|
2014-02-11 14:05:17 +00:00
|
|
|
|
|
|
|
var nicktag = $(pres).find('>nick[xmlns="http://jabber.org/protocol/nick"]');
|
|
|
|
member.displayName = (nicktag.length > 0 ? nicktag.text() : null);
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
if (from == this.myroomjid) {
|
2013-12-17 13:10:47 +00:00
|
|
|
if (member.affiliation == 'owner') this.isOwner = true;
|
2014-11-28 15:05:10 +00:00
|
|
|
if (this.role !== member.role) {
|
|
|
|
this.role = member.role;
|
2014-11-28 15:14:54 +00:00
|
|
|
$(document).trigger('local.role.changed.muc', [from, member, pres]);
|
2014-11-28 15:05:10 +00:00
|
|
|
}
|
2013-12-17 13:10:47 +00:00
|
|
|
if (!this.joined) {
|
|
|
|
this.joined = true;
|
|
|
|
$(document).trigger('joined.muc', [from, member]);
|
2014-02-10 22:25:57 +00:00
|
|
|
this.list_members.push(from);
|
2013-12-17 13:10:47 +00:00
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
} else if (this.members[from] === undefined) {
|
|
|
|
// new participant
|
|
|
|
this.members[from] = member;
|
2014-02-10 22:25:57 +00:00
|
|
|
this.list_members.push(from);
|
2014-01-03 20:21:19 +00:00
|
|
|
$(document).trigger('entered.muc', [from, member, pres]);
|
2014-11-28 15:14:54 +00:00
|
|
|
} else {
|
|
|
|
// Presence update for existing participant
|
|
|
|
// Watch role change:
|
|
|
|
if (this.members[from].role != member.role) {
|
|
|
|
this.members[from].role = member.role
|
|
|
|
$(document).trigger('role.changed.muc', [from, member, pres]);
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-03-27 09:30:53 +00:00
|
|
|
// Always trigger presence to update bindings
|
2014-11-28 15:00:57 +00:00
|
|
|
console.log('presence change from', from, pres);
|
2014-03-27 09:30:53 +00:00
|
|
|
$(document).trigger('presence.muc', [from, member, pres]);
|
2014-08-22 14:20:33 +00:00
|
|
|
|
|
|
|
// Trigger status message update
|
|
|
|
if (member.status) {
|
|
|
|
$(document).trigger('presence.status.muc', [from, member, pres]);
|
|
|
|
}
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
onPresenceUnavailable: function (pres) {
|
|
|
|
var from = pres.getAttribute('from');
|
2014-05-11 22:41:58 +00:00
|
|
|
// Status code 110 indicates that this notification is "self-presence".
|
|
|
|
if (!$(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="110"]').length) {
|
|
|
|
delete this.members[from];
|
|
|
|
this.list_members.splice(this.list_members.indexOf(from), 1);
|
|
|
|
$(document).trigger('left.muc', [from]);
|
|
|
|
}
|
|
|
|
// If the status code is 110 this means we're leaving and we would like
|
|
|
|
// to remove everyone else from our view, so we trigger the event.
|
|
|
|
else if (this.list_members.length > 1) {
|
|
|
|
for (var i = 0; i < this.list_members.length; i++) {
|
|
|
|
var member = this.list_members[i];
|
|
|
|
delete this.members[i];
|
|
|
|
this.list_members.splice(i, 1);
|
|
|
|
$(document).trigger('left.muc', member);
|
|
|
|
}
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
onPresenceError: function (pres) {
|
|
|
|
var from = pres.getAttribute('from');
|
|
|
|
if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
|
|
|
|
$(document).trigger('passwordrequired.muc', [from]);
|
2014-08-05 09:13:21 +00:00
|
|
|
} else if ($(pres).find(
|
|
|
|
'>error[type="cancel"]>not-allowed[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
|
|
|
|
var toDomain = Strophe.getDomainFromJid(pres.getAttribute('to'));
|
|
|
|
if(toDomain === config.hosts.anonymousdomain) {
|
|
|
|
// we are connected with anonymous domain and only non anonymous users can create rooms
|
|
|
|
// we must authorize the user
|
|
|
|
$(document).trigger('passwordrequired.main');
|
2014-08-14 15:29:28 +00:00
|
|
|
} else {
|
2014-08-05 09:13:21 +00:00
|
|
|
console.warn('onPresError ', pres);
|
2014-08-14 15:29:28 +00:00
|
|
|
messageHandler.openReportDialog(null,
|
|
|
|
'Oops! Something went wrong and we couldn`t connect to the conference.',
|
|
|
|
pres);
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
} else {
|
|
|
|
console.warn('onPresError ', pres);
|
2014-08-14 15:29:28 +00:00
|
|
|
messageHandler.openReportDialog(null,
|
|
|
|
'Oops! Something went wrong and we couldn`t connect to the conference.',
|
|
|
|
pres);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
sendMessage: function (body, nickname) {
|
|
|
|
var msg = $msg({to: this.roomjid, type: 'groupchat'});
|
|
|
|
msg.c('body', body).up();
|
|
|
|
if (nickname) {
|
|
|
|
msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
|
|
|
|
}
|
|
|
|
this.connection.send(msg);
|
2014-10-27 13:24:09 +00:00
|
|
|
if(APIConnector.isEnabled() && APIConnector.isEventEnabled("outgoingMessage"))
|
|
|
|
{
|
|
|
|
APIConnector.triggerEvent("outgoingMessage", {"message": body});
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
2014-06-20 09:00:49 +00:00
|
|
|
setSubject: function (subject){
|
|
|
|
var msg = $msg({to: this.roomjid, type: 'groupchat'});
|
|
|
|
msg.c('subject', subject);
|
|
|
|
this.connection.send(msg);
|
|
|
|
console.log("topic changed to " + subject);
|
|
|
|
},
|
2013-12-16 11:22:23 +00:00
|
|
|
onMessage: function (msg) {
|
|
|
|
// FIXME: this is a hack. but jingle on muc makes nickchanges hard
|
2014-02-19 14:32:22 +00:00
|
|
|
var from = msg.getAttribute('from');
|
|
|
|
var nick = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]').text() || Strophe.getResourceFromJid(from);
|
2014-06-20 09:00:49 +00:00
|
|
|
|
|
|
|
var txt = $(msg).find('>body').text();
|
|
|
|
var type = msg.getAttribute("type");
|
|
|
|
if(type == "error")
|
|
|
|
{
|
|
|
|
Chat.chatAddError($(msg).find('>text').text(), txt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var subject = $(msg).find('>subject');
|
|
|
|
if(subject.length)
|
|
|
|
{
|
|
|
|
var subjectText = subject.text();
|
|
|
|
if(subjectText || subjectText == "") {
|
|
|
|
Chat.chatSetSubject(subjectText);
|
|
|
|
console.log("Subject is changed to " + subjectText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
if (txt) {
|
|
|
|
console.log('chat', nick, txt);
|
2014-02-19 14:32:22 +00:00
|
|
|
Chat.updateChatConversation(from, nick, txt);
|
2014-11-08 14:41:16 +00:00
|
|
|
if(APIConnector.isEnabled() && APIConnector.isEventEnabled("incomingMessage"))
|
2014-10-27 13:24:09 +00:00
|
|
|
{
|
|
|
|
if(from != this.myroomjid)
|
2014-11-08 14:41:16 +00:00
|
|
|
APIConnector.triggerEvent("incomingMessage",
|
2014-10-27 13:24:09 +00:00
|
|
|
{"from": from, "nick": nick, "message": txt});
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
lockRoom: function (key) {
|
|
|
|
//http://xmpp.org/extensions/xep-0045.html#roomconfig
|
|
|
|
var ob = this;
|
|
|
|
this.connection.sendIQ($iq({to: this.roomjid, type: 'get'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'}),
|
|
|
|
function (res) {
|
|
|
|
if ($(res).find('>query>x[xmlns="jabber:x:data"]>field[var="muc#roomconfig_roomsecret"]').length) {
|
|
|
|
var formsubmit = $iq({to: ob.roomjid, type: 'set'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
|
|
|
|
formsubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
|
|
|
|
formsubmit.c('field', {'var': 'FORM_TYPE'}).c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up();
|
|
|
|
formsubmit.c('field', {'var': 'muc#roomconfig_roomsecret'}).c('value').t(key).up().up();
|
2014-10-08 11:19:26 +00:00
|
|
|
// Fixes a bug in prosody 0.9.+ https://code.google.com/p/lxmppd/issues/detail?id=373
|
|
|
|
formsubmit.c('field', {'var': 'muc#roomconfig_whois'}).c('value').t('anyone').up().up();
|
2013-12-16 11:22:23 +00:00
|
|
|
// FIXME: is muc#roomconfig_passwordprotectedroom required?
|
|
|
|
this.connection.sendIQ(formsubmit,
|
|
|
|
function (res) {
|
2014-10-30 15:32:03 +00:00
|
|
|
// password is required
|
|
|
|
if (sharedKey)
|
|
|
|
{
|
|
|
|
console.log('set room password');
|
|
|
|
Toolbar.lockLockButton();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log('removed room password');
|
|
|
|
Toolbar.unlockLockButton();
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
console.warn('setting password failed', err);
|
2014-08-14 15:29:28 +00:00
|
|
|
messageHandler.showError('Lock failed',
|
|
|
|
'Failed to lock conference.',
|
|
|
|
err);
|
2014-10-30 15:32:03 +00:00
|
|
|
setSharedKey('');
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.warn('room passwords not supported');
|
2014-08-14 15:29:28 +00:00
|
|
|
messageHandler.showError('Warning',
|
|
|
|
'Room passwords are currently not supported.');
|
2014-10-30 15:32:03 +00:00
|
|
|
setSharedKey('');
|
2014-08-14 15:29:28 +00:00
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
console.warn('setting password failed', err);
|
2014-08-14 15:29:28 +00:00
|
|
|
messageHandler.showError('Lock failed',
|
|
|
|
'Failed to lock conference.',
|
|
|
|
err);
|
2014-10-30 15:32:03 +00:00
|
|
|
setSharedKey('');
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
);
|
2014-01-24 10:24:18 +00:00
|
|
|
},
|
2014-05-11 22:41:58 +00:00
|
|
|
kick: function (jid) {
|
|
|
|
var kickIQ = $iq({to: this.roomjid, type: 'set'})
|
|
|
|
.c('query', {xmlns: 'http://jabber.org/protocol/muc#admin'})
|
|
|
|
.c('item', {nick: Strophe.getResourceFromJid(jid), role: 'none'})
|
|
|
|
.c('reason').t('You have been kicked.').up().up().up();
|
|
|
|
|
|
|
|
this.connection.sendIQ(
|
|
|
|
kickIQ,
|
|
|
|
function (result) {
|
2014-05-11 22:44:05 +00:00
|
|
|
console.log('Kick participant with jid: ', jid, result);
|
2014-05-11 22:41:58 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.log('Kick participant error: ', error);
|
|
|
|
});
|
|
|
|
},
|
2014-01-24 10:24:18 +00:00
|
|
|
sendPresence: function () {
|
|
|
|
var pres = $pres({to: this.presMap['to'] });
|
2014-02-11 14:05:17 +00:00
|
|
|
pres.c('x', {xmlns: this.presMap['xns']});
|
|
|
|
|
|
|
|
if (this.presMap['password']) {
|
|
|
|
pres.c('password').t(this.presMap['password']).up();
|
|
|
|
}
|
|
|
|
|
|
|
|
pres.up();
|
|
|
|
|
2014-09-25 10:17:34 +00:00
|
|
|
// Send XEP-0115 'c' stanza that contains our capabilities info
|
|
|
|
if (connection.caps) {
|
|
|
|
connection.caps.node = config.clientNode;
|
|
|
|
pres.c('c', connection.caps.generateCapsAttrs()).up();
|
|
|
|
}
|
|
|
|
|
2014-08-14 15:29:28 +00:00
|
|
|
if(this.presMap['bridgeIsDown']) {
|
|
|
|
pres.c('bridgeIsDown').up();
|
|
|
|
}
|
|
|
|
|
2014-02-11 14:05:17 +00:00
|
|
|
if (this.presMap['displayName']) {
|
|
|
|
// XEP-0172
|
2014-04-07 10:16:49 +00:00
|
|
|
pres.c('nick', {xmlns: 'http://jabber.org/protocol/nick'})
|
|
|
|
.t(this.presMap['displayName']).up();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.presMap['audions']) {
|
|
|
|
pres.c('audiomuted', {xmlns: this.presMap['audions']})
|
|
|
|
.t(this.presMap['audiomuted']).up();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.presMap['videons']) {
|
|
|
|
pres.c('videomuted', {xmlns: this.presMap['videons']})
|
|
|
|
.t(this.presMap['videomuted']).up();
|
2014-02-11 14:05:17 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 15:11:26 +00:00
|
|
|
if(this.presMap['statsns'])
|
|
|
|
{
|
|
|
|
var stats = pres.c('stats', {xmlns: this.presMap['statsns']});
|
|
|
|
for(var stat in this.presMap["stats"])
|
|
|
|
if(this.presMap["stats"][stat] != null)
|
|
|
|
stats.c("stat",{name: stat, value: this.presMap["stats"][stat]}).up();
|
|
|
|
pres.up();
|
|
|
|
}
|
|
|
|
|
2014-01-24 10:24:18 +00:00
|
|
|
if (this.presMap['prezins']) {
|
2014-04-07 10:16:49 +00:00
|
|
|
pres.c('prezi',
|
|
|
|
{xmlns: this.presMap['prezins'],
|
|
|
|
'url': this.presMap['preziurl']})
|
|
|
|
.c('current').t(this.presMap['prezicurrent']).up().up();
|
2014-01-24 10:24:18 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 22:24:26 +00:00
|
|
|
if (this.presMap['etherpadns']) {
|
2014-04-07 10:16:49 +00:00
|
|
|
pres.c('etherpad', {xmlns: this.presMap['etherpadns']})
|
|
|
|
.t(this.presMap['etherpadname']).up();
|
2014-02-12 22:24:26 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 10:24:18 +00:00
|
|
|
if (this.presMap['medians'])
|
|
|
|
{
|
|
|
|
pres.c('media', {xmlns: this.presMap['medians']});
|
|
|
|
var sourceNumber = 0;
|
|
|
|
Object.keys(this.presMap).forEach(function (key) {
|
|
|
|
if (key.indexOf('source') >= 0) {
|
|
|
|
sourceNumber++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (sourceNumber > 0)
|
2014-02-26 13:43:55 +00:00
|
|
|
for (var i = 1; i <= sourceNumber/3; i ++) {
|
2014-01-24 10:24:18 +00:00
|
|
|
pres.c('source',
|
|
|
|
{type: this.presMap['source' + i + '_type'],
|
2014-02-26 13:43:55 +00:00
|
|
|
ssrc: this.presMap['source' + i + '_ssrc'],
|
2014-04-07 10:16:49 +00:00
|
|
|
direction: this.presMap['source'+ i + '_direction']
|
|
|
|
|| 'sendrecv' }
|
2014-02-26 13:43:55 +00:00
|
|
|
).up();
|
2014-01-24 10:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-14 15:29:28 +00:00
|
|
|
|
2014-01-24 10:24:18 +00:00
|
|
|
pres.up();
|
|
|
|
connection.send(pres);
|
|
|
|
},
|
2014-02-11 14:05:17 +00:00
|
|
|
addDisplayNameToPresence: function (displayName) {
|
|
|
|
this.presMap['displayName'] = displayName;
|
|
|
|
},
|
2014-02-26 13:43:55 +00:00
|
|
|
addMediaToPresence: function (sourceNumber, mtype, ssrcs, direction) {
|
2014-01-24 10:24:18 +00:00
|
|
|
if (!this.presMap['medians'])
|
|
|
|
this.presMap['medians'] = 'http://estos.de/ns/mjs';
|
|
|
|
|
|
|
|
this.presMap['source' + sourceNumber + '_type'] = mtype;
|
|
|
|
this.presMap['source' + sourceNumber + '_ssrc'] = ssrcs;
|
2014-02-26 13:43:55 +00:00
|
|
|
this.presMap['source' + sourceNumber + '_direction'] = direction;
|
2014-01-24 10:24:18 +00:00
|
|
|
},
|
2014-03-13 12:22:54 +00:00
|
|
|
clearPresenceMedia: function () {
|
|
|
|
var self = this;
|
|
|
|
Object.keys(this.presMap).forEach( function(key) {
|
|
|
|
if(key.indexOf('source') != -1) {
|
|
|
|
delete self.presMap[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2014-01-24 10:24:18 +00:00
|
|
|
addPreziToPresence: function (url, currentSlide) {
|
|
|
|
this.presMap['prezins'] = 'http://jitsi.org/jitmeet/prezi';
|
|
|
|
this.presMap['preziurl'] = url;
|
|
|
|
this.presMap['prezicurrent'] = currentSlide;
|
|
|
|
},
|
|
|
|
removePreziFromPresence: function () {
|
|
|
|
delete this.presMap['prezins'];
|
|
|
|
delete this.presMap['preziurl'];
|
|
|
|
delete this.presMap['prezicurrent'];
|
|
|
|
},
|
|
|
|
addCurrentSlideToPresence: function (currentSlide) {
|
|
|
|
this.presMap['prezicurrent'] = currentSlide;
|
|
|
|
},
|
|
|
|
getPrezi: function (roomjid) {
|
|
|
|
return this.preziMap[roomjid];
|
2014-02-12 22:24:26 +00:00
|
|
|
},
|
|
|
|
addEtherpadToPresence: function(etherpadName) {
|
|
|
|
this.presMap['etherpadns'] = 'http://jitsi.org/jitmeet/etherpad';
|
|
|
|
this.presMap['etherpadname'] = etherpadName;
|
2014-04-07 10:16:49 +00:00
|
|
|
},
|
|
|
|
addAudioInfoToPresence: function(isMuted) {
|
|
|
|
this.presMap['audions'] = 'http://jitsi.org/jitmeet/audio';
|
|
|
|
this.presMap['audiomuted'] = isMuted.toString();
|
|
|
|
},
|
|
|
|
addVideoInfoToPresence: function(isMuted) {
|
|
|
|
this.presMap['videons'] = 'http://jitsi.org/jitmeet/video';
|
|
|
|
this.presMap['videomuted'] = isMuted.toString();
|
2014-08-22 15:37:11 +00:00
|
|
|
},
|
2014-10-16 15:11:26 +00:00
|
|
|
addConnectionInfoToPresence: function(stats) {
|
|
|
|
this.presMap['statsns'] = 'http://jitsi.org/jitmeet/stats';
|
|
|
|
this.presMap['stats'] = stats;
|
|
|
|
},
|
2014-08-22 15:37:11 +00:00
|
|
|
findJidFromResource: function(resourceJid) {
|
|
|
|
var peerJid = null;
|
|
|
|
Object.keys(this.members).some(function (jid) {
|
|
|
|
peerJid = jid;
|
|
|
|
return Strophe.getResourceFromJid(jid) === resourceJid;
|
|
|
|
});
|
|
|
|
return peerJid;
|
2014-08-14 15:29:28 +00:00
|
|
|
},
|
|
|
|
addBridgeIsDownToPresence: function() {
|
|
|
|
this.presMap['bridgeIsDown'] = true;
|
2014-11-28 15:05:10 +00:00
|
|
|
},
|
|
|
|
isModerator: function() {
|
|
|
|
return this.role === 'moderator';
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
});
|