Various
* Socket.io 0.9.16 -> 1.3.7 * Ditched express.io * Fixed non prominent bugs in client * Socket.io connect errors is now showing * Minor code cleanups * Bumped minor version * Added additional keywords to package.json
This commit is contained in:
parent
0c28ef6a65
commit
fdd57e3f11
10
app.json
10
app.json
|
@ -3,9 +3,13 @@
|
||||||
"description": "Client side (E2EE) encrypted instant chat",
|
"description": "Client side (E2EE) encrypted instant chat",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cryptalk",
|
"cryptalk",
|
||||||
"encrypted",
|
"fandango",
|
||||||
"chat",
|
"crypto-js",
|
||||||
"e2ee"
|
"AES",
|
||||||
|
"secure",
|
||||||
|
"html5",
|
||||||
|
"encryption",
|
||||||
|
"privacy"
|
||||||
],
|
],
|
||||||
"repository": "https://github.com/Hexagon/cryptalk"
|
"repository": "https://github.com/Hexagon/cryptalk"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name" : "cryptalk",
|
"name" : "cryptalk",
|
||||||
"version" : "1.0.7",
|
"version" : "1.1.0",
|
||||||
"description" : "Encrypted HTML5/Node.JS instant chat",
|
"description" : "Encrypted HTML5/Node.JS instant chat",
|
||||||
"main" : "server.js",
|
"main" : "server.js",
|
||||||
"subdomain": "cryptalk",
|
"subdomain": "cryptalk",
|
||||||
|
@ -13,7 +13,9 @@
|
||||||
"crypto-js",
|
"crypto-js",
|
||||||
"AES",
|
"AES",
|
||||||
"secure",
|
"secure",
|
||||||
"html5"
|
"html5",
|
||||||
|
"encryption",
|
||||||
|
"privacy"
|
||||||
],
|
],
|
||||||
"author": "Hexagon <Hexagon@GitHub>",
|
"author": "Hexagon <Hexagon@GitHub>",
|
||||||
"contributors": [{
|
"contributors": [{
|
||||||
|
@ -27,7 +29,8 @@
|
||||||
},
|
},
|
||||||
"bin" : "./server.js",
|
"bin" : "./server.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express.io": ">= 1.1.13"
|
"express": "4.13.3",
|
||||||
|
"socket.io": "1.3.7"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"darwin",
|
"darwin",
|
||||||
|
|
|
@ -2,15 +2,13 @@
|
||||||
|
|
||||||
// Setup fandango
|
// Setup fandango
|
||||||
fandango.defaults({
|
fandango.defaults({
|
||||||
|
|
||||||
baseUrl: 'js/cryptalk_modules/',
|
baseUrl: 'js/cryptalk_modules/',
|
||||||
|
|
||||||
paths: {
|
paths: {
|
||||||
websocket: 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js',
|
websocket: '/socket.io/socket.io.js',
|
||||||
// Newer version:
|
|
||||||
// We'll have to fix the Access Control issue first though (https://github.com/Automattic/socket.io-client/issues/641).
|
|
||||||
// websocket: 'https://cdn.socket.io/socket.io-1.1.0.js',
|
|
||||||
aes: 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js',
|
aes: 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js',
|
||||||
SHA1: 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/sha1.js',
|
SHA1: 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/sha1.js'
|
||||||
domReady: 'https://cdnjs.cloudflare.com/ajax/libs/require-domReady/2.0.1/domReady.min.js'
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// CryptoJs AES does not support AMD modules. We'll have to create a shim.
|
// CryptoJs AES does not support AMD modules. We'll have to create a shim.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
define(['fandango', 'websocket', 'aes', 'SHA1'], function (fandango, websocket, aes, SHA1) {
|
define(['fandango', 'websocket', 'aes', 'SHA1'], function (fandango, websocket, aes, SHA1) {
|
||||||
|
|
||||||
var exports = {
|
var exports = {
|
||||||
selector: 0,
|
selector: 0,
|
||||||
utilities: {},
|
utilities: {},
|
||||||
|
@ -56,10 +57,7 @@ define(['fandango', 'websocket', 'aes', 'SHA1'], function (fandango, websocket,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Namespace websocket
|
// Namespace websocket
|
||||||
utils.Websocket = {
|
utils.io = websocket;
|
||||||
connect: websocket.connect,
|
|
||||||
on: websocket.on
|
|
||||||
};
|
|
||||||
|
|
||||||
utils.ssplit = function (string, seperator) {
|
utils.ssplit = function (string, seperator) {
|
||||||
var components = string.split(seperator);
|
var components = string.split(seperator);
|
||||||
|
@ -144,14 +142,13 @@ define(['fandango', 'websocket', 'aes', 'SHA1'], function (fandango, websocket,
|
||||||
each(this, function (element) {
|
each(this, function (element) {
|
||||||
element.innerHTML = string;
|
element.innerHTML = string;
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.append = function (string) {
|
proto.append = function (string) {
|
||||||
for (var i = 0, len = this.length; i < len; i++) {
|
each(this, function (element) {
|
||||||
this[0].innerHTML += string;
|
element.innerHTML += string;
|
||||||
}
|
});
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,20 +158,21 @@ define(['fandango', 'websocket', 'aes', 'SHA1'], function (fandango, websocket,
|
||||||
|
|
||||||
// Naive implementations of .on()
|
// Naive implementations of .on()
|
||||||
proto.on = function (eventName, callback) {
|
proto.on = function (eventName, callback) {
|
||||||
for (var i = 0, len = this.length; i < len; i++) {
|
each(this, function (element) {
|
||||||
if (this[0].addEventListener) {
|
if (element.addEventListener) {
|
||||||
this[0].addEventListener(eventName, callback, false);
|
element.addEventListener(eventName, callback, false);
|
||||||
} else if (this[0].attachEvent) {
|
} else if (element.attachEvent) {
|
||||||
this[0].attachEvent('on' + eventName, callback);
|
element.attachEvent('on' + eventName, callback);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.focus = function () {
|
proto.focus = function () {
|
||||||
this[0].focus();
|
// It doesn't make sense to focus all matched elements. So we settle for the first one
|
||||||
|
if(this[0]) {
|
||||||
|
this[0].focus();
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ define(
|
||||||
} else if (fandango.is(toHost, 'untyped')) {
|
} else if (fandango.is(toHost, 'untyped')) {
|
||||||
settings = toHost.settings;
|
settings = toHost.settings;
|
||||||
} else { // Assume string
|
} else { // Assume string
|
||||||
request = toHost;
|
request = toHost.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request) {
|
if (request) {
|
||||||
|
@ -137,7 +137,7 @@ define(
|
||||||
mediator.emit('console:motd', host.settings.motd);
|
mediator.emit('console:motd', host.settings.motd);
|
||||||
|
|
||||||
// The one and only socket
|
// The one and only socket
|
||||||
socket = $.Websocket.connect(host.host, {
|
socket = $.io(host.host, {
|
||||||
forceNew: true,
|
forceNew: true,
|
||||||
'force new connection': true
|
'force new connection': true
|
||||||
});
|
});
|
||||||
|
@ -187,6 +187,7 @@ define(
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('connect', function () {
|
.on('connect', function () {
|
||||||
|
|
||||||
// Tell the user that the chat is ready to interact with
|
// Tell the user that the chat is ready to interact with
|
||||||
mediator.emit('console:info', $.template(templates.messages.connected, {
|
mediator.emit('console:info', $.template(templates.messages.connected, {
|
||||||
host: host.name || 'localhost'
|
host: host.name || 'localhost'
|
||||||
|
@ -204,6 +205,7 @@ define(
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('disconnect', function () {
|
.on('disconnect', function () {
|
||||||
|
|
||||||
room = 0;
|
room = 0;
|
||||||
key = 0;
|
key = 0;
|
||||||
host.connected = 0;
|
host.connected = 0;
|
||||||
|
@ -218,7 +220,8 @@ define(
|
||||||
mediator.emit('window:title',templates.client.title);
|
mediator.emit('window:title',templates.client.title);
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('error', function () {
|
.on('connect_error', function () {
|
||||||
|
|
||||||
room = 0;
|
room = 0;
|
||||||
key = 0;
|
key = 0;
|
||||||
host.connected = 0;
|
host.connected = 0;
|
||||||
|
|
|
@ -8,7 +8,7 @@ define({
|
||||||
hosts: [
|
hosts: [
|
||||||
{
|
{
|
||||||
name: 'default',
|
name: 'default',
|
||||||
host: '',
|
host: 'localhost:8080',
|
||||||
path: '/js/cryptalk_modules/settings.js'
|
path: '/js/cryptalk_modules/settings.js'
|
||||||
}/*,
|
}/*,
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
define(['castrato'],function (mediator){
|
define(['castrato'],function (mediator){
|
||||||
|
|
||||||
var exports = {},
|
var exports = {},
|
||||||
|
|
||||||
focusCallback = function() {
|
focusCallback = function() {
|
||||||
|
@ -26,6 +26,7 @@ define(['castrato'],function (mediator){
|
||||||
exports.setTitle = function(t) { document.title = t; },
|
exports.setTitle = function(t) { document.title = t; },
|
||||||
exports.getTitle = function() { return document.title; };
|
exports.getTitle = function() { return document.title; };
|
||||||
|
|
||||||
|
|
||||||
// Keep track of document focus/blur
|
// Keep track of document focus/blur
|
||||||
if (window.addEventListener){
|
if (window.addEventListener){
|
||||||
// Normal browsers
|
// Normal browsers
|
||||||
|
|
139
server.js
139
server.js
|
@ -1,89 +1,88 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
var express = require('express'),
|
||||||
|
app = express(),
|
||||||
|
server = require('http').createServer(app),
|
||||||
|
io = require('socket.io')(server),
|
||||||
|
port = process.env.PORT || 8080;
|
||||||
|
|
||||||
var express = require('express.io'),
|
server.listen(port, function(){
|
||||||
app = express();app.http().io();
|
console.log('listening on *:'+port);
|
||||||
|
|
||||||
app.use(express.static(__dirname + '/public'));
|
|
||||||
|
|
||||||
app.io.route('room', {
|
|
||||||
join: function(req) {
|
|
||||||
if( req.data ) {
|
|
||||||
req.socket.emit('room:joined',req.data);
|
|
||||||
req.socket.join(req.data);
|
|
||||||
req.socket.broadcast.to(req.data).emit('message:server', {msg:'person_joined'} );
|
|
||||||
req.socket.current_room = req.data;
|
|
||||||
} else {
|
|
||||||
req.socket.emit('message:server', {msg:'command_failed'} );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
leave: function(req) {
|
|
||||||
if( req.data ) {
|
|
||||||
req.socket.emit('room:left');
|
|
||||||
req.socket.leave(req.data);
|
|
||||||
req.socket.broadcast.to(req.data).emit('message:server', {msg:'person_left'} );
|
|
||||||
req.socket.current_room = undefined;
|
|
||||||
} else {
|
|
||||||
req.socket.emit('message:server', {msg:'command_failed'} );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
count: function(req) {
|
|
||||||
if( req.socket.current_room !== undefined ) {
|
|
||||||
// This will fail on socket.io >= 1.0
|
|
||||||
var client_count = app.io.sockets.clients(req.socket.current_room).length;
|
|
||||||
req.socket.emit('message:server', {msg:'person_count', payload: client_count } );
|
|
||||||
} else {
|
|
||||||
req.socket.emit('message:server', {msg:'command_failed'} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.io.route('message', {
|
// Serve /public/* as /
|
||||||
send: function(req) {
|
app.use(express.static(__dirname + '/public'));
|
||||||
|
|
||||||
// Check that the user is in a room
|
io.on('connection', function(socket) {
|
||||||
if(req.data && req.data.room) {
|
|
||||||
|
|
||||||
// Check that the message size is within bounds
|
socket.on('room:join', function(req) {
|
||||||
var total_msg_size = (req.data.msg) ? req.data.msg.length : 0 + (req.data.nick) ? req.data.nick.length : 0;
|
if( req ) {
|
||||||
if( total_msg_size <= 4096) {
|
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'} );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Check that at least 100ms has passed since last message
|
socket.on('room:leave', function(req) {
|
||||||
if( req.socket.last_message === undefined || new Date().getTime() - req.socket.last_message > 100 ) {
|
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'} );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
req.socket.broadcast.to(req.data.room).emit('message:send', { msg: req.data.msg, nick: req.data.nick} );
|
socket.on('room:count', function (req) {
|
||||||
req.socket.emit('message:send', { msg: req.data.msg, nick: req.data.nick} );
|
if( socket.current_room !== undefined ) {
|
||||||
|
var clientsList = io.sockets.adapter.rooms[socket.current_room];
|
||||||
|
socket.emit('message:server', {msg:'person_count', payload: Object.keys(clientsList).length } );
|
||||||
|
} else {
|
||||||
|
socket.emit('message:server', {msg:'command_failed'} );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
req.socket.last_message = new Date().getTime();
|
socket.on('message:send', function(req) {
|
||||||
|
|
||||||
|
// 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 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.last_message = new Date().getTime();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Do not complain if message rate is too fast, that would only generate more traffic
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Do not complain if message rate is too fast, that would only generate more traffic
|
// Message size is out of bounds, complain
|
||||||
|
socket.emit('message:server', {msg:'command_failed'} );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Message size is out of bounds, complain
|
});
|
||||||
req.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'} );
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.io.sockets.on('connection', function(socket) {
|
|
||||||
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'} );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var port = process.env.PORT || 8080;
|
|
||||||
|
|
||||||
app.listen(port, function(){
|
|
||||||
console.log('listening on *:'+port);
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue