1.1.18 Pre release lint

This commit is contained in:
Hexagon 2017-02-22 23:09:50 +01:00
parent 5015caf55a
commit 6775b427a5
22 changed files with 214 additions and 166 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
public/js/vendor
public/js/cryptalk.min.js
requirejs.build.js

40
.eslintrc.json Normal file
View File

@ -0,0 +1,40 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"eqeqeq": [
"error",
"always"
],
"no-undef": [
"warn"
],
"no-console": [
"warn"
]
}
}

View File

@ -7,7 +7,7 @@
<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="icon" type="image/png" href="gfx/icon_32x32.png">
<script src="js/vendor/requirejs-2.3.2/require.js"></script>
<script src="js/vendor/requirejs-2.3.3/require.js"></script>
</head>
<body>

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,9 @@
define(['$.utils', '$.proto'], function (utils, proto) {
// Create a custom edition of Array, extended with $.proto
function ElementArray () {};
function ElementArray () {}
ElementArray.prototype = new Array;
for(var key in proto) ElementArray.prototype[key] = proto[key];
for(var k in proto) ElementArray.prototype[k] = proto[k];
// Create to actual dollar function
function Dollar (selector) {
@ -30,7 +30,7 @@ define(['$.utils', '$.proto'], function (utils, proto) {
}
// Add utils to Dollar
for(var key in utils) Dollar[key] = utils[key];
for(var l in utils) Dollar[l] = utils[l];
return Dollar;

View File

@ -30,7 +30,7 @@ define(['websocket','crypto-js/aes', 'crypto-js/sha1', 'crypto-js/enc-utf8'],fun
};
exports.activeElement = function () {
try { return document.activeElement; } catch (e) {}
try { return document.activeElement; } catch (e) { return; }
};
/**
@ -60,7 +60,7 @@ define(['websocket','crypto-js/aes', 'crypto-js/sha1', 'crypto-js/enc-utf8'],fun
};
exports.getJSON = function (path, onSuccess, onError) {
var data, request = new XMLHttpRequest();
var request = new XMLHttpRequest();
request.open('GET', path, true);
request.onreadystatechange = function() {
@ -91,7 +91,7 @@ define(['websocket','crypto-js/aes', 'crypto-js/sha1', 'crypto-js/enc-utf8'],fun
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'\'': '&#39;',
'/': '&#x2F;'
};

View File

@ -30,11 +30,11 @@ define(['queue','castrato','templates'], function (queue,mediator,templates) {
}
// Add tones to execution queue
var current_tones = tones[i],
freqs = current_tones[0],
start = current_tones[1],
duration = current_tones[2];
var current_tones = tones[i],
freqs = current_tones[0],
start = current_tones[1],
duration = current_tones[2];
var o = ac.createOscillator();
var g = ac.createGain();
o.frequency.value = freqs;
@ -73,12 +73,12 @@ define(['queue','castrato','templates'], function (queue,mediator,templates) {
mediator.emit('console:info',templates.messages.unmuted);
};
// Find audio context
// Find audio context
if (window.AudioContext || window.webkitAudioContext) {
ac = new (window.AudioContext || window.webkitAudioContext);
}
// Connect events
// Connect events
mediator.on('audio:play', function(tones) {playTones(tones); } );
mediator.on('audio:on', on );
mediator.on('audio:off', off );

View File

@ -52,7 +52,7 @@ define(['$','castrato','settings','templates'], function ($, mediator, settings,
setTorch = function (payload) { mediator.emit('console:torch',payload); },
nick = function (payload) {
setNick = function (payload) {
// Make sure the nick meets the length requirements
if (payload.length > settings.nick.maxLen) {
@ -65,7 +65,7 @@ define(['$','castrato','settings','templates'], function ($, mediator, settings,
nick = payload;
// Keep other modules informed
mediator.emit('nick:changed',nick);
mediator.emit('nick:changed', nick);
// Inform that the nick has been set
mediator.emit('console:info', $.template(templates.messages.nick_set, { nick: $.escapeHtml(nick)}));
@ -79,7 +79,7 @@ define(['$','castrato','settings','templates'], function ($, mediator, settings,
mediator.on('command:help', help);
mediator.on('command:clear', clear);
mediator.on('command:nick', nick);
mediator.on('command:nick', setNick);
mediator.on('command:key', setKey);
mediator.on('command:torch', setTorch);
mediator.on('command:title', title);

View File

@ -59,7 +59,7 @@ define(['$', 'castrato', 'settings', 'templates', 'sounds', 'room', 'notificatio
},
torch: function (ttl) {
var ttl = parseInt(ttl);
ttl = parseInt(ttl);
if( ttl > 0 && ttl < 3600) {
mediator.emit('console:info', $.template(templates.messages.torch_is_now, { ttl: ttl }) );
settings.ttl = ttl*1000;
@ -73,8 +73,8 @@ define(['$', 'castrato', 'settings', 'templates', 'sounds', 'room', 'notificatio
},
showNotification: function (type, nick, text) {
var title = type !== 'message' ? 'Cryptalk' : nick,
icon = type === 'message'? 'gfx/icon_128x128.png' : (type == 'error' ? 'gfx/icon_128x128_error.png' : 'gfx/icon_128x128_info.png');
var title = (type !== 'message' ? 'Cryptalk' : nick),
icon = (type === 'message' ? 'gfx/icon_128x128.png' : (type === 'error' ? 'gfx/icon_128x128_error.png' : 'gfx/icon_128x128_info.png'));
// Emit notification
mediator.emit('notification:send', {
@ -148,8 +148,7 @@ define(['$', 'castrato', 'settings', 'templates', 'sounds', 'room', 'notificatio
var buffer,
parts,
payload,
command,
save;
command;
// The Document object is bound to this element.
// If the active element is not the input, focus on it and exit the function.

View File

@ -1,5 +1,5 @@
// Main cryptalk module
define(['castrato','host','client','console'], function (mediator, host, client) {
define(['castrato','host','client','console'], function (mediator) {
// Route mediator messages
mediator

View File

@ -10,7 +10,7 @@
Emits:
mediator.on('socket:emit', emit);
*/
define(['$', 'castrato','settings','templates','hosts','window'], function ($, mediator, settings, templates, hostconfig, window) {
define(['$', 'castrato','settings','templates','hosts','window'], function ($, mediator, settings, templates, hostconfig) {
var
@ -26,7 +26,7 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
if(socket) socket.emit(payload.data,payload.payload);
},
host = function () {
hostInfo = function () {
mediator.emit('info', JSON.stringify(host || {}));
},
@ -76,10 +76,10 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
mediator.emit('console:lockInput');
var
request,
request;
// Use hostconfig.autoconnect as default host
toHost = (toHost == undefined) ? hostconfig.autoconnect : toHost;
// Use hostconfig.autoconnect as default host
toHost = (toHost === undefined) ? hostconfig.autoconnect : toHost;
if (host && host.connected) {
mediator.emit('console:error', $.template(templates.messages.already_connected, {
@ -133,7 +133,7 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
// Bind socket events
socket
.on('room:joined', function (data) {
.on('room:joined', function () {
mediator.emit('console:info', $.template(templates.messages.joined_room, { roomName: $.escapeHtml(parameters.room) } ));
@ -195,8 +195,6 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
.on('disconnect', function () {
room = 0;
key = 0;
host.connected = 0;
// Tell the user that the chat is ready to interact with
@ -211,8 +209,6 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
.on('connect_error', function () {
room = 0;
key = 0;
host.connected = 0;
mediator.emit('console:error', templates.messages.socket_error);
@ -245,11 +241,11 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
parameters = Object.assign({}, parameters, p );
};
mediator.on('command:host', host);
mediator.on('command:host', hostInfo);
mediator.on('command:hosts', hosts);
mediator.on('command:connect', connect);
mediator.on('command:disconnect', disconnect);
mediator.on('command:reconnect', disconnect);
mediator.on('command:reconnect', reconnect);
mediator.on('socket:emit', emit);
mediator.on('host:param', param);

View File

@ -12,9 +12,9 @@ define({
path: '/js/lib/settings.js'
}/*,
{
name: 'Example',
host: 'http://www.example.com',
path: 'http://www.example.com/js/cryptalk_modules/settings.js'
name: 'Official host - cryptalk.56k.guru',
host: 'https://cryptalk.56k.guru',
path: 'https://cryptalk.56k.guru/js/cryptalk_modules/settings.js'
}*/
]
});

View File

@ -1,15 +1,20 @@
require.config({
baseUrl: "js/lib/",
baseUrl: 'js/lib/',
paths: {
websocket: '/socket.io/socket.io'
},
packages: [
{
name: 'crypto-js',
location: '../vendor/crypto-js-3.1.9',
main: 'index'
}
]
packages: [
{
name: 'crypto-js',
location: '../vendor/crypto-js-3.1.9',
main: 'index'
},
{
name: 'castrato',
location: '../vendor/castrato',
main: 'castrato'
}
]
});
require(['cryptalk']);

View File

@ -45,12 +45,11 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
if (original_title !== undefined) win.setTitle(original_title);
original_title = undefined;
new_title = undefined;
window_active = true;
},
doBlink = function() {
if(enabled) {
if( win.getTitle() == original_title )
if( win.getTitle() === original_title )
win.setTitle( new_title );
else
win.setTitle( original_title);
@ -70,7 +69,7 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
},
blinkTitleUntilFocus = function(t,i) {
interval = (i == undefined) ? 1000 : i;
interval = (i === undefined) ? 1000 : i;
if ( enabled && original_title === undefined ) {
new_title = t;
original_title = win.getTitle();
@ -86,7 +85,7 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
// Set default value for fallback parameter
if ( fallback === undefined) fallback = false;
if ( native_supported && Notification.permission === "granted") {
if ( native_supported && Notification.permission === 'granted') {
// Create notification
var n = new Notification(title, {body: body, icon:icon});
@ -95,17 +94,17 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
n.onshow = function () {
// Automatically close the notification after 5000ms
setTimeout(function(){n.close();},3000);
}
};
last = now();
} else if ( fallback ) {
blinkTitleUntilFocus("Attention",1000);
blinkTitleUntilFocus('Attention', 1000);
}
}
};
native_supported = (window.Notification !== undefined);
mediator.on('notification:send',function(data) { notify(data.title,data.body,data.icon,true); });
@ -113,12 +112,12 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
mediator.on('notification:off',function() { off(); });
// Always enable native notifications
enableNative();
enableNative();
// Start with notifications disabled
off();
// Start with notifications disabled
off();
// If this is undefined, notifications will fail to show
// If this is undefined, notifications will fail to show
last = now();
// Make sure we are at square one

View File

@ -1,44 +1,45 @@
define(function (){
var exports = {},
queue = [],
now = function () {
return performance.now() || Date.now();
};
var exports = {},
queue = [],
now = function () {
return performance.now() || Date.now();
};
exports.add_function_delayed = function(delay, callback, data) {
queue.push({
func: callback,
pushed: now(),
delay: delay,
data: data
});
}
exports.add_function_delayed = function(delay, callback, data) {
queue.push({
func: callback,
pushed: now(),
delay: delay,
data: data
});
};
exports.get = function () {
return queue;
}
exports.get = function () {
return queue;
};
exports.run = function () {
var i = 0,
current,
lrt_inner;
exports.run = function () {
var i = 0,
current,
lrt_inner;
while (current = queue[i++]) {
if (now() - current.pushed > current.delay) {
current.func();
queue.splice(i - 1, 1);
}
}
while ((current = queue[i++])) {
if (now() - current.pushed > current.delay) {
current.func();
queue.splice(i - 1, 1);
}
}
if (queue.length) {
// Waste a ms to prevent callstack overflow
lrt_inner = now();
if (queue.length) {
// Waste a ms to prevent callstack overflow
lrt_inner = now();
while (now() - lrt_inner < 1) { void 0; };
while (now() - lrt_inner < 1) { void 0; }
exports.run();
}
}
exports.run();
}
};
return exports;
return exports;
});

View File

@ -1,6 +1,6 @@
define({
title: "Cryptalk - Online",
title: 'Cryptalk - Online',
ttl: 600000,

View File

@ -30,12 +30,12 @@ define(['castrato'],function (mediator){
// Keep track of document focus/blur
if (window.addEventListener){
// Normal browsers
window.addEventListener("focus", focusCallback, true);
window.addEventListener("blur", blurCallback, true);
window.addEventListener('focus', focusCallback, true);
window.addEventListener('blur', blurCallback, true);
} else {
// IE
window.observe("focusin", focusCallback);
window.observe("focusout", blurCallback);
window.observe('focusin', focusCallback);
window.observe('focusout', blurCallback);
}
mediator.on('window:title',exports.setTitle);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,11 @@
name: 'crypto-js',
location: '../vendor/crypto-js-3.1.9',
main: 'index'
},
{
name: 'castrato',
location: '../vendor/castrato',
main: 'castrato'
}
],
name: "main",

126
server.js
View File

@ -1,21 +1,21 @@
#!/usr/bin/env node
const
files = require('node-static'),
port = process.env.PORT || 8080,
path = require('path');
files = require('node-static'),
port = process.env.PORT || 8080,
path = require('path');
var
file,
server,
io;
file,
server,
io;
// Set up files.file location
file = new files.Server(path.resolve(__dirname, 'public'));
// Create http server, handle files.assets
server = require('http').createServer(function (req, res) {
req.addListener('end', function () { file.serve(req, res); }).resume();
req.addListener('end', function () { file.serve(req, res); }).resume();
});
// Append socket.io to http server
@ -23,80 +23,80 @@ io = require('socket.io')(server),
// Listen to port env:PORT or 8080
server.listen(port, function(){
console.log('listening on *:'+port);
console.log('listening on *:' + port);
});
io.on('connection', function(socket) {
socket.on('room:join', function(req) {
if( req ) {
socket.emit('room:joined',req);
socket.join(req);
socket.broadcast.to(req).emit('message:server', {msg:'person_joined'} );
socket.current_room = req;
} else {
socket.emit('message:server', {msg:'command_failed'} );
}
});
socket.on('room:join', function(req) {
if( req ) {
socket.emit('room:joined',req);
socket.join(req);
socket.broadcast.to(req).emit('message:server', {msg:'person_joined'} );
socket.current_room = req;
} else {
socket.emit('message:server', {msg:'command_failed'} );
}
});
socket.on('room:leave', function(req) {
if( req ) {
socket.emit('room:left');
socket.leave(req);
socket.broadcast.to(req).emit('message:server', {msg:'person_left'} );
socket.current_room = undefined;
} else {
socket.emit('message:server', {msg:'command_failed'} );
}
});
socket.on('room:leave', function(req) {
if( req ) {
socket.emit('room:left');
socket.leave(req);
socket.broadcast.to(req).emit('message:server', {msg:'person_left'} );
socket.current_room = undefined;
} else {
socket.emit('message:server', {msg:'command_failed'} );
}
});
socket.on('room:count', function (req) {
if( socket.current_room !== undefined ) {
var clientsList = io.sockets.adapter.rooms[socket.current_room];
socket.emit('message:server', {msg:'person_count', payload: clientsList.length } );
} else {
socket.emit('message:server', {msg:'command_failed'} );
}
});
socket.on('room:count', function () {
if( socket.current_room !== undefined ) {
var clientsList = io.sockets.adapter.rooms[socket.current_room];
socket.emit('message:server', {msg:'person_count', payload: clientsList.length } );
} else {
socket.emit('message:server', {msg:'command_failed'} );
}
});
socket.on('message:send', function(req) {
socket.on('message:send', function(req) {
// Check that the user is in a room
if(req && req.room) {
// Check that the user is in a room
if(req && req.room) {
// Check that the message size is within bounds
var total_msg_size = (req.msg) ? req.msg.length : 0 + (req.nick) ? req.nick.length : 0;
if( total_msg_size <= 4096) {
// Check that the message size is within bounds
var total_msg_size = (req.msg) ? req.msg.length : 0 + (req.nick) ? req.nick.length : 0;
if( total_msg_size <= 4096) {
// Check that at least 100ms has passed since last message
if( socket.last_message === undefined || new Date().getTime() - socket.last_message > 100 ) {
// Check that at least 100ms has passed since last message
if( socket.last_message === undefined || new Date().getTime() - socket.last_message > 100 ) {
socket.broadcast.to(req.room).emit('message:send', { msg: req.msg, nick: req.nick} );
socket.emit('message:send', { msg: req.msg, nick: req.nick} );
socket.broadcast.to(req.room).emit('message:send', { msg: req.msg, nick: req.nick} );
socket.emit('message:send', { msg: req.msg, nick: req.nick} );
socket.last_message = new Date().getTime();
socket.last_message = new Date().getTime();
} else {
} else {
// Do not complain if message rate is too fast, that would only generate more traffic
// Do not complain if message rate is too fast, that would only generate more traffic
}
}
} else {
} else {
// Message size is out of bounds, complain
socket.emit('message:server', {msg:'command_failed'} );
}
// Message size is out of bounds, complain
socket.emit('message:server', {msg:'command_failed'} );
}
}
}
});
});
socket.on('disconnect', function() {
// Notify other users of the room
if( socket.current_room !== undefined ) {
socket.broadcast.to(socket.current_room).emit('message:server', {msg:'person_left'} );
}
});
socket.on('disconnect', function() {
// Notify other users of the room
if( socket.current_room !== undefined ) {
socket.broadcast.to(socket.current_room).emit('message:server', {msg:'person_left'} );
}
});
});
});