Fixed travis

- Tests against Node 4, 8, 10, 12 and newest

Modernized:
- Use arrow functions
- Use string templates in examples and some code
- Use single quote for strings
This commit is contained in:
Fabian Arndt
2019-10-14 01:46:30 +02:00
parent 93e6b59710
commit 8f2b55a7aa
12 changed files with 159 additions and 166 deletions

View File

@ -11,9 +11,9 @@ const enableDestroy = require('server-destroy');
let sio;
exports.start = function (options, callback) {
exports.start = (options, callback) => {
if(typeof options == 'function'){
if (typeof options == 'function') {
callback = options;
options = {};
}
@ -29,7 +29,7 @@ exports.start = function (options, callback) {
sio = socketIo.listen(server);
app.use(bodyParser.json());
app.post('/login', function (req, res) {
app.post('/login', (req, res) => {
const profile = {
first_name: 'John',
last_name: 'Doe',
@ -46,28 +46,28 @@ exports.start = function (options, callback) {
if (options.handshake) {
sio.use(socketio_jwt.authorize(options));
sio.sockets.on('echo', function (m) {
sio.sockets.on('echo', (m) => {
sio.sockets.emit('echo-response', m);
});
} else {
sio.sockets
.on('connection', socketio_jwt.authorize(options))
.on('authenticated', function (socket) {
socket.on('echo', function (m) {
.on('authenticated', (socket) => {
socket.on('echo', (m) => {
socket.emit('echo-response', m);
});
});
}
server.__sockets = [];
server.on('connection', function (c) {
server.on('connection', (c) => {
server.__sockets.push(c);
});
server.listen(9000, callback);
enableDestroy(server);
};
exports.stop = function (callback) {
exports.stop = (callback) => {
sio.close();
try {
server.destroy();

View File

@ -15,7 +15,7 @@ let sio;
*
* The /admin namespace is protected by JWTs while the global namespace is public.
*/
exports.start = function (callback) {
exports.start = (callback) => {
const options = {
secret: 'aaafoo super sercret',
@ -28,7 +28,7 @@ exports.start = function (callback) {
sio = socketIo.listen(server);
app.use(bodyParser.json());
app.post('/login', function (req, res) {
app.post('/login', (req, res) => {
const profile = {
first_name: 'John',
last_name: 'Doe',
@ -43,14 +43,14 @@ exports.start = function (callback) {
sio.on('connection', function (socket) {
sio.on('connection', (socket) => {
socket.emit('hi');
});
const admin_nsp = sio.of('/admin');
admin_nsp.on('connection', socketio_jwt.authorize(options))
.on('authenticated', function (socket) {
.on('authenticated', (socket) => {
socket.emit('hi admin');
});
@ -59,7 +59,7 @@ exports.start = function (callback) {
enableDestroy(server);
};
exports.stop = function (callback) {
exports.stop = (callback) => {
sio.close();
try {
server.destroy();

View File

@ -11,19 +11,19 @@ const enableDestroy = require('server-destroy');
let sio;
exports.start = function (options, callback) {
exports.start = (options, callback) => {
const SECRETS = {
123: 'aaafoo super sercret',
555: 'other'
};
if(typeof options == 'function'){
if (typeof options == 'function') {
callback = options;
options = {};
}
options = xtend({
secret: function(request, decodedToken, callback) {
secret: (request, decodedToken, callback) => {
callback(null, SECRETS[decodedToken.id]);
},
timeout: 1000,
@ -35,7 +35,7 @@ exports.start = function (options, callback) {
sio = socketIo.listen(server);
app.use(bodyParser.json());
app.post('/login', function (req, res) {
app.post('/login', (req, res) => {
const profile = {
first_name: 'John',
last_name: 'Doe',
@ -51,21 +51,21 @@ exports.start = function (options, callback) {
if (options.handshake) {
sio.use(socketio_jwt.authorize(options));
sio.sockets.on('echo', function (m) {
sio.sockets.on('echo', (m) => {
sio.sockets.emit('echo-response', m);
});
} else {
sio.sockets
.on('connection', socketio_jwt.authorize(options))
.on('authenticated', function (socket) {
socket.on('echo', function (m) {
.on('authenticated', (socket) => {
socket.on('echo', (m) => {
socket.emit('echo-response', m);
});
});
}
server.__sockets = [];
server.on('connection', function (c) {
server.on('connection', (c) => {
server.__sockets.push(c);
});
@ -73,7 +73,7 @@ exports.start = function (options, callback) {
enableDestroy(server);
};
exports.stop = function (callback) {
exports.stop = (callback) => {
sio.close();
try {
server.destroy();