Various fixes
Configurable mininum delay between notifications added Grouped settings Configurable default + host specific title win -> window removed /generate-command deprecated dependency on node-uuid
This commit is contained in:
parent
1216332270
commit
fb38738d2f
|
@ -27,7 +27,6 @@
|
||||||
},
|
},
|
||||||
"bin" : "./server.js",
|
"bin" : "./server.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-uuid": ">= 1.4.1",
|
|
||||||
"express.io": ">= 1.1.13"
|
"express.io": ">= 1.1.13"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
// Main cryptalk module
|
// Main cryptalk module
|
||||||
define({
|
define({
|
||||||
compiles: ['$'],
|
compiles: ['$'],
|
||||||
requires: ['mediator', 'hosts', 'templates', 'audio', 'fandango','notifications', 'sounds', 'win']
|
requires: ['mediator', 'hosts', 'templates', 'audio', 'fandango','notifications', 'sounds', 'window']
|
||||||
}, function ($, requires, data) {
|
}, function ($, requires, data) {
|
||||||
|
|
||||||
var socket,
|
var socket,
|
||||||
key,
|
key,
|
||||||
host,
|
host,
|
||||||
room,
|
room,
|
||||||
|
room_raw,
|
||||||
hash,
|
hash,
|
||||||
nick,
|
nick,
|
||||||
mute = false,
|
mute = false,
|
||||||
|
@ -31,7 +33,7 @@ define({
|
||||||
mediator = requires.mediator,
|
mediator = requires.mediator,
|
||||||
templates = requires.templates,
|
templates = requires.templates,
|
||||||
sounds = requires.sounds,
|
sounds = requires.sounds,
|
||||||
win = requires.win,
|
win = requires.window,
|
||||||
|
|
||||||
lockInput = function () {
|
lockInput = function () {
|
||||||
components.input[0].setAttribute('disabled', 'disabled');
|
components.input[0].setAttribute('disabled', 'disabled');
|
||||||
|
@ -187,29 +189,29 @@ define({
|
||||||
'force new connection': true
|
'force new connection': true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Set window title
|
||||||
|
win.setTitle(settings.client.title);
|
||||||
|
|
||||||
// Bind socket events
|
// Bind socket events
|
||||||
socket
|
socket
|
||||||
.on('room:generated', function (data) {
|
|
||||||
var sanitized = $.escapeHtml(data);
|
|
||||||
post('server', $.template(templates.server.room_generated, { payload: sanitized }));
|
|
||||||
socket.emit('room:join', sanitized);
|
|
||||||
})
|
|
||||||
|
|
||||||
.on('room:joined', function (data) {
|
.on('room:joined', function (data) {
|
||||||
room = $.escapeHtml(data);
|
room = $.escapeHtml(data);
|
||||||
post('info', $.template(templates.messages.joined_room, { roomName: room }));
|
|
||||||
|
post('info', $.template(templates.messages.joined_room, { roomName: $.escapeHtml(room_raw) }));
|
||||||
|
|
||||||
// Automatically count persons on join
|
// Automatically count persons on join
|
||||||
socket.emit('room:count');
|
socket.emit('room:count');
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('room:left', function () {
|
.on('room:left', function () {
|
||||||
post('info', $.template(templates.messages.left_room, { roomName: room }));
|
post('info', $.template(templates.messages.left_room, { roomName: $.escapeHtml(room_raw) }));
|
||||||
|
|
||||||
// Clear history on leaving room
|
// Clear history on leaving room
|
||||||
clearHistory();
|
clearHistory();
|
||||||
|
|
||||||
room = false;
|
room = false;
|
||||||
|
room_raw = "";
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('message:send', function (data) {
|
.on('message:send', function (data) {
|
||||||
|
@ -262,6 +264,9 @@ define({
|
||||||
post('info', $.template(templates.messages.disconnected, {
|
post('info', $.template(templates.messages.disconnected, {
|
||||||
host: host.name || 'localhost'
|
host: host.name || 'localhost'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Revert title
|
||||||
|
win.setTitle(templates.client.title);
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('error', function () {
|
.on('error', function () {
|
||||||
|
@ -320,10 +325,10 @@ define({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the key meets the length requirements
|
// Make sure the key meets the length requirements
|
||||||
if (payload.length > settings.key_maxLen) {
|
if (payload.length > settings.key.maxLen) {
|
||||||
return post('error', templates.messages.key_to_long);
|
return post('error', $.template(templates.messages.key_to_long, { key_maxLen: settings.key_maxLen } ));
|
||||||
} else if (payload.length < settings.key_minLen) {
|
} else if (payload.length < settings.key.minLen) {
|
||||||
return post('error', templates.messages.key_to_short);
|
return post('error', $.template(templates.messages.key_to_short, { key_maxLen: settings.key_minLen } ));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set key
|
// Set key
|
||||||
|
@ -335,10 +340,10 @@ define({
|
||||||
|
|
||||||
nick: function (payload) {
|
nick: function (payload) {
|
||||||
// Make sure the key meets the length requirements
|
// Make sure the key meets the length requirements
|
||||||
if (payload.length > settings.nick_maxLen) {
|
if (payload.length > settings.nick.maxLen) {
|
||||||
return post('error', templates.messages.nick_to_long);
|
return post('error', $.template(templates.messages.nick_to_long, { nick_maxLen: settings.nick.maxLen } ));
|
||||||
} else if (payload.length < settings.nick_minLen) {
|
} else if (payload.length < settings.nick.minLen) {
|
||||||
return post('error', templates.messages.nick_to_short);
|
return post('error', $.template(templates.messages.nick_to_short, {nick_minLen: settings.nick.minLen } ));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set nick
|
// Set nick
|
||||||
|
@ -368,20 +373,14 @@ define({
|
||||||
return post('error', templates.messages.join_no_host);
|
return post('error', templates.messages.join_no_host);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
if (room) {
|
||||||
room
|
return post('error', templates.messages.already_in_room);
|
||||||
? post('error', templates.messages.already_in_room)
|
} else {
|
||||||
: socket.emit('room:join', $.SHA1(payload))
|
room_raw = payload;
|
||||||
);
|
return socket.emit('room:join', $.SHA1(payload))
|
||||||
},
|
|
||||||
|
|
||||||
generate: function (payload) {
|
|
||||||
return (
|
|
||||||
room
|
|
||||||
? post('error', templates.messages.already_in_room)
|
|
||||||
: socket.emit('room:generate')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Push input buffer to history
|
// Push input buffer to history
|
||||||
|
@ -537,6 +536,9 @@ define({
|
||||||
|
|
||||||
unlockInput();
|
unlockInput();
|
||||||
|
|
||||||
|
// Revert title
|
||||||
|
win.setTitle(templates.client.title);
|
||||||
|
|
||||||
// It's possible to provide room and key using the hashtag.
|
// It's possible to provide room and key using the hashtag.
|
||||||
// The room and key is then seperated by semicolon (room:key).
|
// The room and key is then seperated by semicolon (room:key).
|
||||||
// If there is no semicolon present, the complete hash will be treated as the room name and the key has to be set manually.
|
// If there is no semicolon present, the complete hash will be treated as the room name and the key has to be set manually.
|
||||||
|
|
|
@ -15,7 +15,8 @@ Usage
|
||||||
mediator.emit('notification:off');
|
mediator.emit('notification:off');
|
||||||
|
|
||||||
*/
|
*/
|
||||||
define(['mediator','win'], function (mediator, win) {
|
define(['mediator','window','settings'], function (mediator, win, settings) {
|
||||||
|
|
||||||
var enabled = true,
|
var enabled = true,
|
||||||
|
|
||||||
native_supported = false,
|
native_supported = false,
|
||||||
|
@ -25,6 +26,8 @@ define(['mediator','win'], function (mediator, win) {
|
||||||
blink_timer,
|
blink_timer,
|
||||||
interval,
|
interval,
|
||||||
|
|
||||||
|
last,
|
||||||
|
|
||||||
now = function () {
|
now = function () {
|
||||||
return performance.now() || Date.now();
|
return performance.now() || Date.now();
|
||||||
},
|
},
|
||||||
|
@ -39,7 +42,7 @@ define(['mediator','win'], function (mediator, win) {
|
||||||
|
|
||||||
resetState = function() {
|
resetState = function() {
|
||||||
clearTimeout(blink_timer);
|
clearTimeout(blink_timer);
|
||||||
if (original_title !== undefined) setTitle(original_title);
|
if (original_title !== undefined) win.setTitle(original_title);
|
||||||
original_title = undefined;
|
original_title = undefined;
|
||||||
new_title = undefined;
|
new_title = undefined;
|
||||||
window_active = true;
|
window_active = true;
|
||||||
|
@ -68,16 +71,17 @@ define(['mediator','win'], function (mediator, win) {
|
||||||
|
|
||||||
blinkTitleUntilFocus = function(t,i) {
|
blinkTitleUntilFocus = function(t,i) {
|
||||||
interval = (i == undefined) ? 1000 : i;
|
interval = (i == undefined) ? 1000 : i;
|
||||||
if ( enabled ) {
|
if ( enabled && original_title === undefined ) {
|
||||||
new_title = t;
|
new_title = t;
|
||||||
original_title = getTitle();
|
original_title = win.getTitle();
|
||||||
doBlink();
|
doBlink();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
notify = function(title,body,icon,fallback) {
|
notify = function(title,body,icon,fallback) {
|
||||||
// Only notify while in background
|
|
||||||
if( enabled) {
|
// Only notify while in background, and if sufficient time has passed
|
||||||
|
if( enabled && (now() - last) > settings.notifications.maxOnePerMs ) {
|
||||||
|
|
||||||
// Set default value for fallback parameter
|
// Set default value for fallback parameter
|
||||||
if ( fallback === undefined) fallback = false;
|
if ( fallback === undefined) fallback = false;
|
||||||
|
@ -93,8 +97,11 @@ define(['mediator','win'], function (mediator, win) {
|
||||||
setTimeout(function(){n.close();},3000);
|
setTimeout(function(){n.close();},3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last = now();
|
||||||
|
|
||||||
} else if ( fallback ) {
|
} else if ( fallback ) {
|
||||||
exports.blinkTitleUntilFocus("Attention",1000);
|
blinkTitleUntilFocus("Attention",1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -105,10 +112,15 @@ define(['mediator','win'], function (mediator, win) {
|
||||||
mediator.on('notification:on',function() { on(); });
|
mediator.on('notification:on',function() { on(); });
|
||||||
mediator.on('notification:off',function() { off(); });
|
mediator.on('notification:off',function() { off(); });
|
||||||
|
|
||||||
|
// Always enable native notifications
|
||||||
enableNative();
|
enableNative();
|
||||||
|
|
||||||
|
// Start with notifications disabled
|
||||||
off();
|
off();
|
||||||
|
|
||||||
|
// If this is undefined, notifications will fail to show
|
||||||
|
last = now();
|
||||||
|
|
||||||
// Make sure we are at square one
|
// Make sure we are at square one
|
||||||
resetState();
|
resetState();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
define({
|
define({
|
||||||
nick_maxLen: 20,
|
|
||||||
nick_minLen: 3,
|
|
||||||
|
|
||||||
key_maxLen: Infinity,
|
client: {
|
||||||
key_minLen: 8
|
title: "Cryptalk - Online"
|
||||||
|
},
|
||||||
|
|
||||||
|
nick: {
|
||||||
|
maxLen: 20,
|
||||||
|
minLen: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
key: {
|
||||||
|
maxLen: Infinity,
|
||||||
|
minLen: 8,
|
||||||
|
},
|
||||||
|
|
||||||
|
notifications: {
|
||||||
|
maxOnePerMs: 3000
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
|
@ -33,7 +33,6 @@ define({
|
||||||
' /title Set your local page title \n' +
|
' /title Set your local page title \n' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'Room: \n' +
|
'Room: \n' +
|
||||||
' /generate Generate random room \n' +
|
|
||||||
' /join RoomId Join a room \n' +
|
' /join RoomId Join a room \n' +
|
||||||
' /leave Leave the room \n' +
|
' /leave Leave the room \n' +
|
||||||
' /count Count participants \n' +
|
' /count Count participants \n' +
|
||||||
|
@ -93,8 +92,8 @@ define({
|
||||||
|
|
||||||
unrecognized_command: 'Unrecognized command: "{commandName}"',
|
unrecognized_command: 'Unrecognized command: "{commandName}"',
|
||||||
|
|
||||||
joined_room: 'Joined room {room}',
|
joined_room: 'Joined room {roomName}.',
|
||||||
left_room: 'Left room {room}',
|
left_room: 'Left room {roomName}.',
|
||||||
already_in_room: 'You are already in a room ({room}), stoopid.',
|
already_in_room: 'You are already in a room ({room}), stoopid.',
|
||||||
|
|
||||||
unable_to_decrypt: 'Unabled to decrypt received message, keys does not match.',
|
unable_to_decrypt: 'Unabled to decrypt received message, keys does not match.',
|
||||||
|
@ -113,9 +112,12 @@ define({
|
||||||
server: {
|
server: {
|
||||||
person_joined: 'A person joined this room.',
|
person_joined: 'A person joined this room.',
|
||||||
person_left: 'A person left this room.',
|
person_left: 'A person left this room.',
|
||||||
room_generated: 'Room {payload} generated.',
|
|
||||||
person_count: 'There is {payload} person(s) in this room, including you.',
|
person_count: 'There is {payload} person(s) in this room, including you.',
|
||||||
command_failed: 'Server command failed, you\'re probably trying to du something bogus.',
|
command_failed: 'Server command failed, you\'re probably trying to du something bogus.',
|
||||||
bogus: 'Received a bogus message from server.'
|
bogus: 'Received a bogus message from server.'
|
||||||
|
},
|
||||||
|
|
||||||
|
client: {
|
||||||
|
title: 'Cryptalk - Offline'
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -1,17 +1,12 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var express = require('express.io'),
|
var express = require('express.io'),
|
||||||
uuid = require('node-uuid'),
|
|
||||||
|
|
||||||
app = express();app.http().io();
|
app = express();app.http().io();
|
||||||
|
|
||||||
app.use(express.static(__dirname + '/public'));
|
app.use(express.static(__dirname + '/public'));
|
||||||
|
|
||||||
app.io.route('room', {
|
app.io.route('room', {
|
||||||
generate: function(req) {
|
|
||||||
var room = uuid.v4();
|
|
||||||
req.socket.emit('room:generated',room);
|
|
||||||
},
|
|
||||||
join: function(req) {
|
join: function(req) {
|
||||||
if( req.data ) {
|
if( req.data ) {
|
||||||
req.socket.emit('room:joined',req.data);
|
req.socket.emit('room:joined',req.data);
|
||||||
|
|
Loading…
Reference in New Issue