1.1.18 Pre release lint
This commit is contained in:
parent
5015caf55a
commit
6775b427a5
|
@ -0,0 +1,3 @@
|
||||||
|
public/js/vendor
|
||||||
|
public/js/cryptalk.min.js
|
||||||
|
requirejs.build.js
|
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
<link rel="stylesheet" type="text/css" href="css/default.css">
|
<link rel="stylesheet" type="text/css" href="css/default.css">
|
||||||
<link rel="icon" type="image/png" href="gfx/icon_32x32.png">
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,9 +1,9 @@
|
||||||
define(['$.utils', '$.proto'], function (utils, proto) {
|
define(['$.utils', '$.proto'], function (utils, proto) {
|
||||||
|
|
||||||
// Create a custom edition of Array, extended with $.proto
|
// Create a custom edition of Array, extended with $.proto
|
||||||
function ElementArray () {};
|
function ElementArray () {}
|
||||||
ElementArray.prototype = new Array;
|
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
|
// Create to actual dollar function
|
||||||
function Dollar (selector) {
|
function Dollar (selector) {
|
||||||
|
@ -30,7 +30,7 @@ define(['$.utils', '$.proto'], function (utils, proto) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add utils to Dollar
|
// Add utils to Dollar
|
||||||
for(var key in utils) Dollar[key] = utils[key];
|
for(var l in utils) Dollar[l] = utils[l];
|
||||||
|
|
||||||
return Dollar;
|
return Dollar;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ define(['websocket','crypto-js/aes', 'crypto-js/sha1', 'crypto-js/enc-utf8'],fun
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.activeElement = function () {
|
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) {
|
exports.getJSON = function (path, onSuccess, onError) {
|
||||||
var data, request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open('GET', path, true);
|
request.open('GET', path, true);
|
||||||
|
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
|
@ -91,7 +91,7 @@ define(['websocket','crypto-js/aes', 'crypto-js/sha1', 'crypto-js/enc-utf8'],fun
|
||||||
'<': '<',
|
'<': '<',
|
||||||
'>': '>',
|
'>': '>',
|
||||||
'"': '"',
|
'"': '"',
|
||||||
"'": ''',
|
'\'': ''',
|
||||||
'/': '/'
|
'/': '/'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ define(['queue','castrato','templates'], function (queue,mediator,templates) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add tones to execution queue
|
// Add tones to execution queue
|
||||||
var current_tones = tones[i],
|
var current_tones = tones[i],
|
||||||
freqs = current_tones[0],
|
freqs = current_tones[0],
|
||||||
start = current_tones[1],
|
start = current_tones[1],
|
||||||
duration = current_tones[2];
|
duration = current_tones[2];
|
||||||
|
|
||||||
var o = ac.createOscillator();
|
var o = ac.createOscillator();
|
||||||
var g = ac.createGain();
|
var g = ac.createGain();
|
||||||
|
@ -73,12 +73,12 @@ define(['queue','castrato','templates'], function (queue,mediator,templates) {
|
||||||
mediator.emit('console:info',templates.messages.unmuted);
|
mediator.emit('console:info',templates.messages.unmuted);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find audio context
|
// Find audio context
|
||||||
if (window.AudioContext || window.webkitAudioContext) {
|
if (window.AudioContext || window.webkitAudioContext) {
|
||||||
ac = new (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:play', function(tones) {playTones(tones); } );
|
||||||
mediator.on('audio:on', on );
|
mediator.on('audio:on', on );
|
||||||
mediator.on('audio:off', off );
|
mediator.on('audio:off', off );
|
||||||
|
|
|
@ -52,7 +52,7 @@ define(['$','castrato','settings','templates'], function ($, mediator, settings,
|
||||||
|
|
||||||
setTorch = function (payload) { mediator.emit('console:torch',payload); },
|
setTorch = function (payload) { mediator.emit('console:torch',payload); },
|
||||||
|
|
||||||
nick = function (payload) {
|
setNick = function (payload) {
|
||||||
|
|
||||||
// Make sure the nick meets the length requirements
|
// Make sure the nick meets the length requirements
|
||||||
if (payload.length > settings.nick.maxLen) {
|
if (payload.length > settings.nick.maxLen) {
|
||||||
|
@ -65,7 +65,7 @@ define(['$','castrato','settings','templates'], function ($, mediator, settings,
|
||||||
nick = payload;
|
nick = payload;
|
||||||
|
|
||||||
// Keep other modules informed
|
// Keep other modules informed
|
||||||
mediator.emit('nick:changed',nick);
|
mediator.emit('nick:changed', nick);
|
||||||
|
|
||||||
// Inform that the nick has been set
|
// Inform that the nick has been set
|
||||||
mediator.emit('console:info', $.template(templates.messages.nick_set, { nick: $.escapeHtml(nick)}));
|
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:help', help);
|
||||||
mediator.on('command:clear', clear);
|
mediator.on('command:clear', clear);
|
||||||
mediator.on('command:nick', nick);
|
mediator.on('command:nick', setNick);
|
||||||
mediator.on('command:key', setKey);
|
mediator.on('command:key', setKey);
|
||||||
mediator.on('command:torch', setTorch);
|
mediator.on('command:torch', setTorch);
|
||||||
mediator.on('command:title', title);
|
mediator.on('command:title', title);
|
||||||
|
|
|
@ -59,7 +59,7 @@ define(['$', 'castrato', 'settings', 'templates', 'sounds', 'room', 'notificatio
|
||||||
},
|
},
|
||||||
|
|
||||||
torch: function (ttl) {
|
torch: function (ttl) {
|
||||||
var ttl = parseInt(ttl);
|
ttl = parseInt(ttl);
|
||||||
if( ttl > 0 && ttl < 3600) {
|
if( ttl > 0 && ttl < 3600) {
|
||||||
mediator.emit('console:info', $.template(templates.messages.torch_is_now, { ttl: ttl }) );
|
mediator.emit('console:info', $.template(templates.messages.torch_is_now, { ttl: ttl }) );
|
||||||
settings.ttl = ttl*1000;
|
settings.ttl = ttl*1000;
|
||||||
|
@ -73,8 +73,8 @@ define(['$', 'castrato', 'settings', 'templates', 'sounds', 'room', 'notificatio
|
||||||
},
|
},
|
||||||
|
|
||||||
showNotification: function (type, nick, text) {
|
showNotification: function (type, nick, text) {
|
||||||
var title = type !== 'message' ? 'Cryptalk' : nick,
|
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');
|
icon = (type === 'message' ? 'gfx/icon_128x128.png' : (type === 'error' ? 'gfx/icon_128x128_error.png' : 'gfx/icon_128x128_info.png'));
|
||||||
|
|
||||||
// Emit notification
|
// Emit notification
|
||||||
mediator.emit('notification:send', {
|
mediator.emit('notification:send', {
|
||||||
|
@ -148,8 +148,7 @@ define(['$', 'castrato', 'settings', 'templates', 'sounds', 'room', 'notificatio
|
||||||
var buffer,
|
var buffer,
|
||||||
parts,
|
parts,
|
||||||
payload,
|
payload,
|
||||||
command,
|
command;
|
||||||
save;
|
|
||||||
|
|
||||||
// The Document object is bound to this element.
|
// The Document object is bound to this element.
|
||||||
// If the active element is not the input, focus on it and exit the function.
|
// If the active element is not the input, focus on it and exit the function.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Main cryptalk module
|
// Main cryptalk module
|
||||||
define(['castrato','host','client','console'], function (mediator, host, client) {
|
define(['castrato','host','client','console'], function (mediator) {
|
||||||
|
|
||||||
// Route mediator messages
|
// Route mediator messages
|
||||||
mediator
|
mediator
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
Emits:
|
Emits:
|
||||||
mediator.on('socket:emit', emit);
|
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
|
var
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
|
||||||
if(socket) socket.emit(payload.data,payload.payload);
|
if(socket) socket.emit(payload.data,payload.payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
host = function () {
|
hostInfo = function () {
|
||||||
mediator.emit('info', JSON.stringify(host || {}));
|
mediator.emit('info', JSON.stringify(host || {}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -76,10 +76,10 @@ define(['$', 'castrato','settings','templates','hosts','window'], function ($, m
|
||||||
mediator.emit('console:lockInput');
|
mediator.emit('console:lockInput');
|
||||||
|
|
||||||
var
|
var
|
||||||
request,
|
request;
|
||||||
|
|
||||||
// Use hostconfig.autoconnect as default host
|
// Use hostconfig.autoconnect as default host
|
||||||
toHost = (toHost == undefined) ? hostconfig.autoconnect : toHost;
|
toHost = (toHost === undefined) ? hostconfig.autoconnect : toHost;
|
||||||
|
|
||||||
if (host && host.connected) {
|
if (host && host.connected) {
|
||||||
mediator.emit('console:error', $.template(templates.messages.already_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
|
// Bind socket events
|
||||||
socket
|
socket
|
||||||
.on('room:joined', function (data) {
|
.on('room:joined', function () {
|
||||||
|
|
||||||
mediator.emit('console:info', $.template(templates.messages.joined_room, { roomName: $.escapeHtml(parameters.room) } ));
|
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 () {
|
.on('disconnect', function () {
|
||||||
|
|
||||||
room = 0;
|
|
||||||
key = 0;
|
|
||||||
host.connected = 0;
|
host.connected = 0;
|
||||||
|
|
||||||
// Tell the user that the chat is ready to interact with
|
// 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 () {
|
.on('connect_error', function () {
|
||||||
|
|
||||||
room = 0;
|
|
||||||
key = 0;
|
|
||||||
host.connected = 0;
|
host.connected = 0;
|
||||||
mediator.emit('console:error', templates.messages.socket_error);
|
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 );
|
parameters = Object.assign({}, parameters, p );
|
||||||
};
|
};
|
||||||
|
|
||||||
mediator.on('command:host', host);
|
mediator.on('command:host', hostInfo);
|
||||||
mediator.on('command:hosts', hosts);
|
mediator.on('command:hosts', hosts);
|
||||||
mediator.on('command:connect', connect);
|
mediator.on('command:connect', connect);
|
||||||
mediator.on('command:disconnect', disconnect);
|
mediator.on('command:disconnect', disconnect);
|
||||||
mediator.on('command:reconnect', disconnect);
|
mediator.on('command:reconnect', reconnect);
|
||||||
|
|
||||||
mediator.on('socket:emit', emit);
|
mediator.on('socket:emit', emit);
|
||||||
mediator.on('host:param', param);
|
mediator.on('host:param', param);
|
||||||
|
|
|
@ -12,9 +12,9 @@ define({
|
||||||
path: '/js/lib/settings.js'
|
path: '/js/lib/settings.js'
|
||||||
}/*,
|
}/*,
|
||||||
{
|
{
|
||||||
name: 'Example',
|
name: 'Official host - cryptalk.56k.guru',
|
||||||
host: 'http://www.example.com',
|
host: 'https://cryptalk.56k.guru',
|
||||||
path: 'http://www.example.com/js/cryptalk_modules/settings.js'
|
path: 'https://cryptalk.56k.guru/js/cryptalk_modules/settings.js'
|
||||||
}*/
|
}*/
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
require.config({
|
require.config({
|
||||||
baseUrl: "js/lib/",
|
baseUrl: 'js/lib/',
|
||||||
paths: {
|
paths: {
|
||||||
websocket: '/socket.io/socket.io'
|
websocket: '/socket.io/socket.io'
|
||||||
},
|
},
|
||||||
packages: [
|
packages: [
|
||||||
{
|
{
|
||||||
name: 'crypto-js',
|
name: 'crypto-js',
|
||||||
location: '../vendor/crypto-js-3.1.9',
|
location: '../vendor/crypto-js-3.1.9',
|
||||||
main: 'index'
|
main: 'index'
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
name: 'castrato',
|
||||||
|
location: '../vendor/castrato',
|
||||||
|
main: 'castrato'
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
require(['cryptalk']);
|
require(['cryptalk']);
|
|
@ -45,12 +45,11 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
|
||||||
if (original_title !== undefined) win.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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
doBlink = function() {
|
doBlink = function() {
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
if( win.getTitle() == original_title )
|
if( win.getTitle() === original_title )
|
||||||
win.setTitle( new_title );
|
win.setTitle( new_title );
|
||||||
else
|
else
|
||||||
win.setTitle( original_title);
|
win.setTitle( original_title);
|
||||||
|
@ -70,7 +69,7 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
|
||||||
},
|
},
|
||||||
|
|
||||||
blinkTitleUntilFocus = function(t,i) {
|
blinkTitleUntilFocus = function(t,i) {
|
||||||
interval = (i == undefined) ? 1000 : i;
|
interval = (i === undefined) ? 1000 : i;
|
||||||
if ( enabled && original_title === undefined ) {
|
if ( enabled && original_title === undefined ) {
|
||||||
new_title = t;
|
new_title = t;
|
||||||
original_title = win.getTitle();
|
original_title = win.getTitle();
|
||||||
|
@ -86,7 +85,7 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
|
||||||
// Set default value for fallback parameter
|
// Set default value for fallback parameter
|
||||||
if ( fallback === undefined) fallback = false;
|
if ( fallback === undefined) fallback = false;
|
||||||
|
|
||||||
if ( native_supported && Notification.permission === "granted") {
|
if ( native_supported && Notification.permission === 'granted') {
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
var n = new Notification(title, {body: body, icon:icon});
|
var n = new Notification(title, {body: body, icon:icon});
|
||||||
|
@ -95,12 +94,12 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
|
||||||
n.onshow = function () {
|
n.onshow = function () {
|
||||||
// Automatically close the notification after 5000ms
|
// Automatically close the notification after 5000ms
|
||||||
setTimeout(function(){n.close();},3000);
|
setTimeout(function(){n.close();},3000);
|
||||||
}
|
};
|
||||||
|
|
||||||
last = now();
|
last = now();
|
||||||
|
|
||||||
} else if ( fallback ) {
|
} else if ( fallback ) {
|
||||||
blinkTitleUntilFocus("Attention",1000);
|
blinkTitleUntilFocus('Attention', 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,12 +112,12 @@ define(['castrato','window','settings'], function (mediator, win, settings) {
|
||||||
mediator.on('notification:off',function() { off(); });
|
mediator.on('notification:off',function() { off(); });
|
||||||
|
|
||||||
// Always enable native notifications
|
// Always enable native notifications
|
||||||
enableNative();
|
enableNative();
|
||||||
|
|
||||||
// Start with notifications disabled
|
// Start with notifications disabled
|
||||||
off();
|
off();
|
||||||
|
|
||||||
// If this is undefined, notifications will fail to show
|
// If this is undefined, notifications will fail to show
|
||||||
last = now();
|
last = now();
|
||||||
|
|
||||||
// Make sure we are at square one
|
// Make sure we are at square one
|
||||||
|
|
|
@ -1,44 +1,45 @@
|
||||||
define(function (){
|
define(function (){
|
||||||
var exports = {},
|
|
||||||
queue = [],
|
|
||||||
now = function () {
|
|
||||||
return performance.now() || Date.now();
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.add_function_delayed = function(delay, callback, data) {
|
var exports = {},
|
||||||
queue.push({
|
queue = [],
|
||||||
func: callback,
|
now = function () {
|
||||||
pushed: now(),
|
return performance.now() || Date.now();
|
||||||
delay: delay,
|
};
|
||||||
data: data
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.get = function () {
|
exports.add_function_delayed = function(delay, callback, data) {
|
||||||
return queue;
|
queue.push({
|
||||||
}
|
func: callback,
|
||||||
|
pushed: now(),
|
||||||
|
delay: delay,
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.run = function () {
|
exports.get = function () {
|
||||||
var i = 0,
|
return queue;
|
||||||
current,
|
};
|
||||||
lrt_inner;
|
|
||||||
|
|
||||||
while (current = queue[i++]) {
|
exports.run = function () {
|
||||||
if (now() - current.pushed > current.delay) {
|
var i = 0,
|
||||||
current.func();
|
current,
|
||||||
queue.splice(i - 1, 1);
|
lrt_inner;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queue.length) {
|
while ((current = queue[i++])) {
|
||||||
// Waste a ms to prevent callstack overflow
|
if (now() - current.pushed > current.delay) {
|
||||||
lrt_inner = now();
|
current.func();
|
||||||
|
queue.splice(i - 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (now() - lrt_inner < 1) { void 0; };
|
if (queue.length) {
|
||||||
|
// Waste a ms to prevent callstack overflow
|
||||||
|
lrt_inner = now();
|
||||||
|
|
||||||
exports.run();
|
while (now() - lrt_inner < 1) { void 0; }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return exports;
|
exports.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports;
|
||||||
});
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
define({
|
define({
|
||||||
|
|
||||||
title: "Cryptalk - Online",
|
title: 'Cryptalk - Online',
|
||||||
|
|
||||||
ttl: 600000,
|
ttl: 600000,
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ define(['castrato'],function (mediator){
|
||||||
// Keep track of document focus/blur
|
// Keep track of document focus/blur
|
||||||
if (window.addEventListener){
|
if (window.addEventListener){
|
||||||
// Normal browsers
|
// Normal browsers
|
||||||
window.addEventListener("focus", focusCallback, true);
|
window.addEventListener('focus', focusCallback, true);
|
||||||
window.addEventListener("blur", blurCallback, true);
|
window.addEventListener('blur', blurCallback, true);
|
||||||
} else {
|
} else {
|
||||||
// IE
|
// IE
|
||||||
window.observe("focusin", focusCallback);
|
window.observe('focusin', focusCallback);
|
||||||
window.observe("focusout", blurCallback);
|
window.observe('focusout', blurCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
mediator.on('window:title',exports.setTitle);
|
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
|
@ -8,6 +8,11 @@
|
||||||
name: 'crypto-js',
|
name: 'crypto-js',
|
||||||
location: '../vendor/crypto-js-3.1.9',
|
location: '../vendor/crypto-js-3.1.9',
|
||||||
main: 'index'
|
main: 'index'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'castrato',
|
||||||
|
location: '../vendor/castrato',
|
||||||
|
main: 'castrato'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
name: "main",
|
name: "main",
|
||||||
|
|
124
server.js
124
server.js
|
@ -1,21 +1,21 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const
|
const
|
||||||
files = require('node-static'),
|
files = require('node-static'),
|
||||||
port = process.env.PORT || 8080,
|
port = process.env.PORT || 8080,
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
var
|
var
|
||||||
file,
|
file,
|
||||||
server,
|
server,
|
||||||
io;
|
io;
|
||||||
|
|
||||||
// Set up files.file location
|
// Set up files.file location
|
||||||
file = new files.Server(path.resolve(__dirname, 'public'));
|
file = new files.Server(path.resolve(__dirname, 'public'));
|
||||||
|
|
||||||
// Create http server, handle files.assets
|
// Create http server, handle files.assets
|
||||||
server = require('http').createServer(function (req, res) {
|
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
|
// Append socket.io to http server
|
||||||
|
@ -23,80 +23,80 @@ io = require('socket.io')(server),
|
||||||
|
|
||||||
// Listen to port env:PORT or 8080
|
// Listen to port env:PORT or 8080
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
console.log('listening on *:'+port);
|
console.log('listening on *:' + port);
|
||||||
});
|
});
|
||||||
|
|
||||||
io.on('connection', function(socket) {
|
io.on('connection', function(socket) {
|
||||||
|
|
||||||
socket.on('room:join', function(req) {
|
socket.on('room:join', function(req) {
|
||||||
if( req ) {
|
if( req ) {
|
||||||
socket.emit('room:joined',req);
|
socket.emit('room:joined',req);
|
||||||
socket.join(req);
|
socket.join(req);
|
||||||
socket.broadcast.to(req).emit('message:server', {msg:'person_joined'} );
|
socket.broadcast.to(req).emit('message:server', {msg:'person_joined'} );
|
||||||
socket.current_room = req;
|
socket.current_room = req;
|
||||||
} else {
|
} else {
|
||||||
socket.emit('message:server', {msg:'command_failed'} );
|
socket.emit('message:server', {msg:'command_failed'} );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('room:leave', function(req) {
|
socket.on('room:leave', function(req) {
|
||||||
if( req ) {
|
if( req ) {
|
||||||
socket.emit('room:left');
|
socket.emit('room:left');
|
||||||
socket.leave(req);
|
socket.leave(req);
|
||||||
socket.broadcast.to(req).emit('message:server', {msg:'person_left'} );
|
socket.broadcast.to(req).emit('message:server', {msg:'person_left'} );
|
||||||
socket.current_room = undefined;
|
socket.current_room = undefined;
|
||||||
} else {
|
} else {
|
||||||
socket.emit('message:server', {msg:'command_failed'} );
|
socket.emit('message:server', {msg:'command_failed'} );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('room:count', function (req) {
|
socket.on('room:count', function () {
|
||||||
if( socket.current_room !== undefined ) {
|
if( socket.current_room !== undefined ) {
|
||||||
var clientsList = io.sockets.adapter.rooms[socket.current_room];
|
var clientsList = io.sockets.adapter.rooms[socket.current_room];
|
||||||
socket.emit('message:server', {msg:'person_count', payload: clientsList.length } );
|
socket.emit('message:server', {msg:'person_count', payload: clientsList.length } );
|
||||||
} else {
|
} else {
|
||||||
socket.emit('message:server', {msg:'command_failed'} );
|
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
|
// Check that the user is in a room
|
||||||
if(req && req.room) {
|
if(req && req.room) {
|
||||||
|
|
||||||
// Check that the message size is within bounds
|
// Check that the message size is within bounds
|
||||||
var total_msg_size = (req.msg) ? req.msg.length : 0 + (req.nick) ? req.nick.length : 0;
|
var total_msg_size = (req.msg) ? req.msg.length : 0 + (req.nick) ? req.nick.length : 0;
|
||||||
if( total_msg_size <= 4096) {
|
if( total_msg_size <= 4096) {
|
||||||
|
|
||||||
// Check that at least 100ms has passed since last message
|
// Check that at least 100ms has passed since last message
|
||||||
if( socket.last_message === undefined || new Date().getTime() - socket.last_message > 100 ) {
|
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.broadcast.to(req.room).emit('message:send', { msg: req.msg, nick: req.nick} );
|
||||||
socket.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
|
// Message size is out of bounds, complain
|
||||||
socket.emit('message:server', {msg:'command_failed'} );
|
socket.emit('message:server', {msg:'command_failed'} );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', function() {
|
socket.on('disconnect', function() {
|
||||||
// Notify other users of the room
|
// Notify other users of the room
|
||||||
if( socket.current_room !== undefined ) {
|
if( socket.current_room !== undefined ) {
|
||||||
socket.broadcast.to(socket.current_room).emit('message:server', {msg:'person_left'} );
|
socket.broadcast.to(socket.current_room).emit('message:server', {msg:'person_left'} );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue