Improves password required interface and disables the padlock for participants.

This commit is contained in:
Yana Stamcheva 2013-12-23 17:10:07 +01:00
parent d7be5c0667
commit 9c0e924b13
2 changed files with 96 additions and 46 deletions

130
app.js
View File

@ -188,6 +188,9 @@ $(document).bind('entered.muc', function (event, jid, info) {
focus.addNewParticipant(jid); focus.addNewParticipant(jid);
} }
} }
else if (sharedKey) {
updateLockButton();
}
}); });
$(document).bind('left.muc', function (event, jid) { $(document).bind('left.muc', function (event, jid) {
@ -208,6 +211,33 @@ $(document).bind('left.muc', function (event, jid) {
} }
}); });
$(document).bind('passwordrequired.muc', function (event, jid) {
console.log('on password required', jid);
$.prompt('<h2>Password required</h2>' +
'<input id="lockKey" type="text" placeholder="shared key" autofocus>',
{
persistent: true,
buttons: { "Ok": true , "Cancel": false},
defaultButton: 1,
loaded: function(event) {
document.getElementById('lockKey').focus();
},
submit: function(e,v,m,f){
if(v)
{
var lockKey = document.getElementById('lockKey');
if (lockKey.value != null)
{
setSharedKey(lockKey);
connection.emuc.doJoin(jid, lockKey.value);
}
}
}
});
});
function toggleVideo() { function toggleVideo() {
if (!(connection && connection.jingle.localStream)) return; if (!(connection && connection.jingle.localStream)) return;
for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) { for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) {
@ -357,44 +387,62 @@ function buttonClick(id, classname) {
* Opens the lock room dialog. * Opens the lock room dialog.
*/ */
function openLockDialog() { function openLockDialog() {
if (sharedKey) // Only the focus is able to set a shared key.
$.prompt("Are you sure you would like to remove your secret key?", if (focus == null) {
{ if (sharedKey)
title: "Remove secrect key", $.prompt("This conversation is currently protected by a shared secret key.",
persistent: false, {
buttons: { "Remove": true, "Cancel": false}, title: "Secrect key",
defaultButton: 1, persistent: false
submit: function(e,v,m,f){ });
if(v) else
{ $.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.",
sharedKey = ''; {
lockRoom(); title: "Secrect key",
} persistent: false
} });
}); }
else else {
$.prompt('<h2>Set a secrect key to lock your room</h2>' + if (sharedKey)
'<input id="lockKey" type="text" placeholder="your shared key" autofocus>', $.prompt("Are you sure you would like to remove your secret key?",
{ {
persistent: false, title: "Remove secrect key",
buttons: { "Save": true , "Cancel": false}, persistent: false,
defaultButton: 1, buttons: { "Remove": true, "Cancel": false},
loaded: function(event) { defaultButton: 1,
document.getElementById('lockKey').focus(); submit: function(e,v,m,f){
}, if(v)
submit: function(e,v,m,f){ {
if(v) setSharedKey('');
{ lockRoom();
var lockKey = document.getElementById('lockKey'); }
}
if (lockKey.value != null) });
{ else
sharedKey = lockKey.value; $.prompt('<h2>Set a secrect key to lock your room</h2>' +
'<input id="lockKey" type="text" placeholder="your shared key" autofocus>',
{
persistent: false,
buttons: { "Save": true , "Cancel": false},
defaultButton: 1,
loaded: function(event) {
document.getElementById('lockKey').focus();
},
submit: function(e,v,m,f){
if(v)
{
var lockKey = document.getElementById('lockKey');
if (lockKey.value)
{
console.log("LOCK KEY", lockKey.value);
setSharedKey(lockKey.value);
lockRoom(true); lockRoom(true);
} }
} }
} }
}); });
}
} }
/* /*
@ -418,6 +466,20 @@ function openLinkDialog() {
function lockRoom(lock) { function lockRoom(lock) {
connection.emuc.lockRoom(sharedKey); connection.emuc.lockRoom(sharedKey);
updateLockButton();
}
/*
* Sets the shared key.
*/
function setSharedKey(sKey) {
sharedKey = sKey;
}
/*
* Updates the lock button state.
*/
function updateLockButton() {
buttonClick("#lockIcon", "fa fa-unlock fa-lg fa fa-lock fa-lg"); buttonClick("#lockIcon", "fa fa-unlock fa-lg fa fa-lock fa-lg");
} }

12
muc.js
View File

@ -75,18 +75,6 @@ Strophe.addConnectionPlugin('emuc', {
var from = pres.getAttribute('from'); var from = pres.getAttribute('from');
if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) { if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
$(document).trigger('passwordrequired.muc', [from]); $(document).trigger('passwordrequired.muc', [from]);
// FIXME: remove once moved to passwordrequired which should reuse dojoin
var ob = this;
window.setTimeout(function () {
var given = window.prompt('Password required');
if (given != null) {
// FIXME: reuse doJoin?
ob.connection.send($pres({to: ob.myroomjid }).c('x', {xmlns: 'http://jabber.org/protocol/muc'}).c('password').t(given));
} else {
// user aborted
}
}, 50);
} else { } else {
console.warn('onPresError ', pres); console.warn('onPresError ', pres);
} }