Some comment enhancements

master
Daniel Berteaud 10 years ago
parent 51e61e2e7d
commit 76532851f2
  1. 38
      vroom.pl

@ -1,9 +1,8 @@
#!/usr/bin/env perl #!/usr/bin/env perl
# This file is part of the VROOM project # This file is part of the VROOM project
# released under the MIT licence # Released under the MIT licence
# Copyright 2014 Firewall Services # Copyright 2014-2015 Daniel Berteaud <daniel@firewall-services.com>
# Daniel Berteaud <daniel@firewall-services.com>
use lib 'lib'; use lib 'lib';
use Mojolicious::Lite; use Mojolicious::Lite;
@ -25,6 +24,7 @@ use Protocol::SocketIO::Message;
use Data::Dumper; use Data::Dumper;
app->log->level('info'); app->log->level('info');
# Read conf file, and set default values # Read conf file, and set default values
my $cfg = new Config::Simple(); my $cfg = new Config::Simple();
$cfg->read('conf/settings.ini'); $cfg->read('conf/settings.ini');
@ -63,7 +63,7 @@ $config->{'daemon.backend'} ||= 'hypnotoad';
$config->{'daemon.log_level'} ||= 'warn'; $config->{'daemon.log_level'} ||= 'warn';
$config->{'daemon.pid_file'} ||= '/tmp/vroom.pid'; $config->{'daemon.pid_file'} ||= '/tmp/vroom.pid';
# Create etherpad api client if required # Create etherpad api client if enabled
our $ec = undef; our $ec = undef;
if ($config->{'etherpad.uri'} =~ m/https?:\/\/.*/ && $config->{'etherpad.api_key'} ne ''){ if ($config->{'etherpad.uri'} =~ m/https?:\/\/.*/ && $config->{'etherpad.api_key'} ne ''){
$ec = Etherpad::API->new({ $ec = Etherpad::API->new({
@ -79,16 +79,20 @@ if ($config->{'etherpad.uri'} =~ m/https?:\/\/.*/ && $config->{'etherpad.api_key
# Global error check # Global error check
our $error = undef; our $error = undef;
# Global client hash # Global peers hash
our $peers = {}; our $peers = {};
# Load I18N, and declare supported languages # Load I18N, and declare supported languages
plugin I18N => { plugin I18N => {
namespace => 'Vroom::I18N', namespace => 'Vroom::I18N',
}; };
# Supported languages must be declared here
# Used to generate the dropdown menu
our @supported_lang = qw(en fr); our @supported_lang = qw(en fr);
# Connect to the database # Connect to the database
# Only MySQL supported for now
plugin database => { plugin database => {
dsn => $config->{'database.dsn'}, dsn => $config->{'database.dsn'},
username => $config->{'database.user'}, username => $config->{'database.user'},
@ -116,7 +120,7 @@ plugin StaticCompressor => {
# Validation helpers # # Validation helpers #
########################## ##########################
# take a string as argument and check if it's a valid room name # Take a string as argument and check if it's a valid room name
helper valid_room_name => sub { helper valid_room_name => sub {
my $self = shift; my $self = shift;
my ($name) = @_; my ($name) = @_;
@ -131,7 +135,7 @@ helper valid_room_name => sub {
return 1; return 1;
}; };
# Check id arg is a valid ID number # Check arg is a valid ID number
helper valid_id => sub { helper valid_id => sub {
my $self = shift; my $self = shift;
my ($id) = @_; my ($id) = @_;
@ -141,7 +145,7 @@ helper valid_id => sub {
return 1; return 1;
}; };
# Check email address # Check email address format
helper valid_email => sub { helper valid_email => sub {
my $self = shift; my $self = shift;
my ($email) = @_; my ($email) = @_;
@ -168,6 +172,7 @@ helper check_db_version => sub {
}; };
# Create a cookie based session # Create a cookie based session
# And a new API key
helper login => sub { helper login => sub {
my $self = shift; my $self = shift;
if ($self->session('name')){ if ($self->session('name')){
@ -192,7 +197,7 @@ helper login => sub {
return 1; return 1;
}; };
# Expire the cookie # Force the session cookie to expire on logout
helper logout => sub { helper logout => sub {
my $self = shift; my $self = shift;
my ($room) = @_; my ($room) = @_;
@ -250,7 +255,8 @@ helper create_room => sub {
}; };
# Take a string as argument # Take a string as argument
# Return corresponding room data in ->{data} # Return a room object if a room with that name is found
# Else return undef
helper get_room_by_name => sub { helper get_room_by_name => sub {
my $self = shift; my $self = shift;
my ($name) = @_; my ($name) = @_;
@ -267,7 +273,7 @@ helper get_room_by_name => sub {
return $sth->fetchall_hashref('name')->{$name} return $sth->fetchall_hashref('name')->{$name}
}; };
# Same as before, but take a room ID as argument # Same as get_room_by_name, but take a room ID as argument
helper get_room_by_id => sub { helper get_room_by_id => sub {
my $self = shift; my $self = shift;
my ($id) = @_; my ($id) = @_;
@ -283,7 +289,7 @@ helper get_room_by_id => sub {
return $sth->fetchall_hashref('id')->{$id}; return $sth->fetchall_hashref('id')->{$id};
}; };
# Update a room, take a room object as a hashref # Update a room, take a room object as argument (hashref)
# TODO: log modified fields # TODO: log modified fields
helper modify_room => sub { helper modify_room => sub {
my $self = shift; my $self = shift;
@ -344,7 +350,7 @@ helper set_peer_role => sub {
return 1; return 1;
}; };
# Return the role of a peer, from it's signaling ID # Return the role of a peer, take a peer object as arg ($data = { peer_id => XYZ })
helper get_peer_role => sub { helper get_peer_role => sub {
my $self = shift; my $self = shift;
my ($data) = @_; my ($data) = @_;
@ -420,7 +426,7 @@ helper purge_rooms => sub {
return 1; return 1;
}; };
# delete just a specific room # delete just a specific room, by name
helper delete_room => sub { helper delete_room => sub {
my $self = shift; my $self = shift;
my ($room) = @_; my ($room) = @_;
@ -1096,7 +1102,7 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
$self->app->log->debug("Signaling message received from peer " . $id); $self->app->log->debug("Signaling message received from peer " . $id);
$msg->{data}->{args}[0]->{from} = $id; $msg->{data}->{args}[0]->{from} = $id;
my $to = $msg->{data}->{args}[0]->{to}; my $to = $msg->{data}->{args}[0]->{to};
# Unicast message ? Check the dest is in the same room # Unicast message ? Check if the dest is in the same room
# and send # and send
if ($to && if ($to &&
$peers->{$to} && $peers->{$to} &&
@ -1105,7 +1111,7 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
$peers->{$to}->{socket}){ $peers->{$to}->{socket}){
$peers->{$to}->{socket}->send(Protocol::SocketIO::Message->new(%$msg)); $peers->{$to}->{socket}->send(Protocol::SocketIO::Message->new(%$msg));
} }
# No dest, multicast this to every memebrs of the room # No dest, multicast this to every members of the room
else{ else{
$self->signal_broadcast_room({ $self->signal_broadcast_room({
from => $id, from => $id,

Loading…
Cancel
Save