Make the member limit configurable per room

And fix #96
master
Daniel Berteaud 10 years ago
parent 175edfd276
commit 0d0b6afbf1
  1. 3
      conf/settings.ini.dist
  2. 1
      docs/database/schema.mysql
  3. 2
      lib/Vroom/Constants.pm
  4. 3
      lib/Vroom/I18N/en.pm
  5. 3
      lib/Vroom/I18N/fr.pm
  6. 4
      public/js/vroom.js
  7. 17
      scripts/db_upgrade.pl
  8. 17
      templates/default/configure_modal.html.ep
  9. 34
      vroom.pl

@ -55,7 +55,8 @@
; A comma separated list of room names you don't want to be reservable
;common_names = 'test,test1,test123,0,1,2,3,4,5,6,7,8,9,123,1234,12345,a,aa,abc,azerty,qwerty,vroom,foo,bar,baz'
; A limit of member in any room. As trafic is really p2p, a high number of peers can make things slow
; or even crash browsers. You can set a limit to garantee a good user experience. Default is unlimited
; or even crash browsers. You can set a limit to garantee a good user experience. 0 (default value) means unlimited
; This is the upper limit, you can set a different limit per room
;max_members = 0
[log]

@ -22,6 +22,7 @@ CREATE TABLE `rooms` (
`token` VARCHAR(160) NOT NULL,
`realm` VARCHAR(160) DEFAULT NULL,
`persistent` TINYINT UNSIGNED DEFAULT '0',
`max_members` TINYINT UNSIGNED DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE (`name`),
INDEX (`last_activity`)

@ -7,7 +7,7 @@ use base 'Exporter';
our @EXPORT = qw/DB_VERSION COMPONENTS MOH JS_STRINGS API_ACTIONS/;
# Database version
use constant DB_VERSION => 3;
use constant DB_VERSION => 4;
# Components used to generate the credits part
use constant COMPONENTS => {

@ -143,6 +143,7 @@ our %Lexicon = (
"JOIN_PASSWORD" => "Password to join the room",
"OWNER_PASSWORD" => "Password to manage the room",
"PERSISTENT" => "Persistent",
"MAX_MEMBERS" => "Participants limit",
"TOOLTIP_LOCK_ROOM" => "Once this option is enabled, no one else can join the room. " .
"Only enable it after every participant is here. This way, nobody will be able to disturb " .
"your meeting",
@ -151,6 +152,8 @@ our %Lexicon = (
"TOOLTIP_RESERVE_THIS_ROOM" => "If this password is set, you'll be able to access the configuration menus ".
"next time you connect",
"TOOLTIP_PERSISTENT" => "The room will be persistent (kept forever)",
"TOOLTIP_MAX_MEMBERS" => "Define the upper limit of connected peer in the room. A value of 0 means no limit. " .
"(Note that an admin might define a limit anyway)",
"TOOLTIP_NOTIFICATION_ON_JOIN" => "One or more email addresse(s) which will be notified when someone joins the room",
"ROOM_NOW_PERSISTENT" => "This room is now persistent",
"ROOM_NO_MORE_PERSISTENT" => "This rooms isn't persistent anymore",

@ -149,6 +149,7 @@ our %Lexicon = (
"JOIN_PASSWORD" => "Mot de passe d'accès au salon",
"OWNER_PASSWORD" => "Mot de passe de gestionnaire",
"PERSISTENT" => "Persistant",
"MAX_MEMBERS" => "Limite de participants",
"TOOLTIP_LOCK_ROOM" => "Une fois cette option activée, plus personne ne peut rejoindre le salon. " .
"À n'activer qu'une fois que tout les participants vous ont rejoint, pour éviter " .
"que d'autres personnes viennent troubler la réunion",
@ -157,6 +158,8 @@ our %Lexicon = (
"TOOLTIP_RESERVE_THIS_ROOM" => "Ce mot de passe vous permettra de récuperer l'accès aux " .
"menus de gestion la prochaine fois que vous vous connecterez",
"TOOLTIP_PERSISTENT" => "Rend le salon persistant (sera conservé indéfiniement)",
"TOOLTIP_MAX_MEMBERS" => "Défini le nombre maximal de participants pouvant rejoindre le salon en même temps. Une valeur de 0" .
"supprime toute limite. (Notez qu'une valeur maximale peut être définie par un administrateur)",
"TOOLTIP_NOTIFICATION_ON_JOIN" => "Une ou plusieurs adresses email qui recevront une notification dès que quulqu'un rejoint ce salon",
"ROOM_NOW_PERSISTENT" => "Ce salon est maintenant persistant",
"ROOM_NO_MORE_PERSISTENT" => "Ce salon n'est plus persistant",

@ -300,6 +300,8 @@ $('#configureRoomForm').submit(function(e){
$('#ownerPass').val() : false,
persist = ($('#persistentSet').length > 0) ?
$('#persistentSet').bootstrapSwitch('state') : '',
members = ($('#maxMembers').length > 0) ?
$('#maxMembers').val() : 0,
emails = [];
$('input[name="emails[]"]').each(function(){
emails.push($(this).val());
@ -315,6 +317,7 @@ $('#configureRoomForm').submit(function(e){
join_password: joinPass,
owner_password: ownerPass,
persistent: persist,
max_members: members,
emails: emails
}
})
@ -528,6 +531,7 @@ function initAdminRooms(){
$('#joinPassSet').bootstrapSwitch('state', data.join_auth == 'yes');
$('#ownerPassSet').bootstrapSwitch('state', data.owner_auth == 'yes');
$('#persistentSet').bootstrapSwitch('state', data.persistent == 'yes');
$('#maxMembers').val(data.max_members);
// Hide the password inputs
$('#joinPassFields,#ownerPassFields').hide();
// And display the config modal dialog

@ -91,3 +91,20 @@ if ($cur_ver < 3){
};
print "Successfully upgraded to schema version 3\n";
}
if ($cur_ver < 4){
print "Upgrading the schema to version 4\n";
eval {
$dbh->begin_work;
$dbh->do(qq{ ALTER TABLE `rooms` ADD COLUMN `max_members` TINYINT UNSIGNED DEFAULT '0' AFTER `persistent` });
$dbh->do(qq{ UPDATE `config` SET `value`='4' WHERE `key`='schema_version' });
$dbh->commit;
};
if ($@){
print "An error occurred: " . $dbh->errstr . "\n";
local $dbh->{RaiseError} = 0;
$dbh->rollback;
exit 255;
};
print "Successfully upgraded to schema version 4\n";
}

@ -105,6 +105,23 @@
<input type="checkbox" class="bs-switch" id="persistentSet">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="maxMembers">
<%=l 'MAX_MEMBERS' %>
<a href="#" class="popup" data-container="body" data-toggle="popover" data-content="<%=l 'TOOLTIP_MAX_MEMBERS' %>">
&nbsp;&nbsp
<span class="glyphicon glyphicon-question-sign">
</span>
</a>
</label>
<div class="col-sm-2">
<input type="number"
class="form-control"
id="maxMembers"
min="0"
max="<%= $config->{'rooms.max_members'} > 0 ? $config->{'rooms.max_members'} : 255 %>">
</div>
</div>
<% } %>
<div class="form-group">
<label class="col-sm-4 control-label" for="emailNotifications">

@ -294,9 +294,14 @@ helper modify_room => sub {
if (!$self->valid_room_name($room->{name})){
return 0;
}
if (!$room->{max_members} ||
($room->{max_members} > $config->{'rooms.max_members'} && $config->{'rooms.max_members'} > 0)){
$room->{max_members} = 0;
}
if (($room->{locked} && $room->{locked} !~ m/^0|1$/) ||
($room->{ask_for_name} && $room->{ask_for_name} !~ m/^0|1$/) ||
($room->{persistent} && $room->{persistent} !~ m/^0|1$/)){
($room->{persistent} && $room->{persistent} !~ m/^0|1$/) ||
$room->{max_members} !~ m/^\d+$/){
return 0;
}
my $sth = eval {
@ -306,7 +311,8 @@ helper modify_room => sub {
`ask_for_name`=?,
`join_password`=?,
`owner_password`=?,
`persistent`=?
`persistent`=?,
`max_members`=?
WHERE `id`=?');
};
$sth->execute(
@ -316,6 +322,7 @@ helper modify_room => sub {
$room->{join_password},
$room->{owner_password},
$room->{persistent},
$room->{max_members},
$room->{id}
);
$self->app->log->info("Room " . $room->{name} ." modified by " . $self->session('name'));
@ -928,6 +935,20 @@ helper signal_broadcast_room => sub {
return 1;
};
# Get the member limit for a room
helper get_member_limit => sub {
my $self = shift;
my $name = shift;
my $room = $self->get_room_by_name($name);
if ($room->{max_members} > 0 && $room->{max_members} < $config->{'rooms.max_members'}){
return $room->{max_members};
}
elsif ($config->{'rooms.max_members'} > 0){
return $config->{'rooms.max_members'};
}
return 0;
};
# Socket.IO handshake
get '/socket.io/:ver' => sub {
my $self = shift;
@ -980,7 +1001,8 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
return;
}
# Are we under the limit of members ?
elsif ($config->{'rooms.max_members'} > 0 && $self->get_room_members($room) >= $config->{'rooms.max_members'}){
my $limit = $self->get_member_limit($room);
if ($limit > 0 && $self->get_room_members($room) >= $limit){
$self->app->log->debug("Failed to connect to the signaling channel, members limit (" . $config->{'rooms.max_members'} .
") is reached");
$self->send( Protocol::SocketIO::Message->new( type => 'disconnect' ) );
@ -1495,6 +1517,7 @@ any '/api' => sub {
elsif ($req->{action} eq 'update_room_conf'){
$room->{locked} = ($req->{param}->{locked}) ? '1' : '0';
$room->{ask_for_name} = ($req->{param}->{ask_for_name}) ? '1' : '0';
$room->{max_members} = $req->{param}->{max_members};
# Room persistence can only be set by admins
if ($self->key_can_do_this(token => $token, action => 'set_persistent') && $req->{param}->{persistent} ne ''){
$room->{persistent} = ($req->{param}->{persistent} eq Mojo::JSON->true) ? '1' : '0';
@ -1736,6 +1759,7 @@ any '/api' => sub {
locked => ($room->{locked}) ? 'yes' : 'no',
ask_for_name => ($room->{ask_for_name}) ? 'yes' : 'no',
persistent => ($room->{persistent}) ? 'yes' : 'no',
max_members => $room->{max_members},
notif => $self->get_notification($room->{name}),
}
);
@ -1777,6 +1801,7 @@ any '/api' => sub {
join_auth => ($room->{join_password}) ? 'yes' : 'no',
locked => ($room->{locked}) ? 'yes' : 'no',
ask_for_name => ($room->{ask_for_name}) ? 'yes' : 'no',
max_members => $room->{max_members},
notif => $self->get_notification($room->{name}),
},
);
@ -1982,7 +2007,8 @@ get '/:room' => sub {
);
}
# If we've reached the members' limit
if ($config->{'rooms.max_members'} > 0 && $self->get_room_members($room) >= $config->{'rooms.max_members'}){
my $limit = $self->get_member_limit($room);
if ($limit > 0 && $self->get_room_members($room) >= $limit){
return $self->render('error',
msg => $self->l("ERROR_TOO_MANY_MEMBERS"),
err => 'ERROR_TOO_MANY_MEMBERS',

Loading…
Cancel
Save