2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-07-21 09:38:31 +02:00
socketio-jwt/example/index.js
Alberto Güerere 31b4c450e0 Introduced a new example
This introduces a new example project that build on top of socket.io’s
own tutorial. Fixes https://github.com/auth0/socketio-jwt/issues/59
2015-10-15 17:12:11 -04:30

26 lines
692 B
JavaScript

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var socketioJwt = require('socketio-jwt');
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io
.on('connection', socketioJwt.authorize({
secret: Buffer('YOUR_CLIENT_SECRET', 'base64'),
timeout: 15000 // 15 seconds to send the authentication message
}))
.on('authenticated', function(socket){
console.log('connected & authenticated: ' + socket.decoded_token.toString());
socket.on('chat message', function(msg){
debugger;
io.emit('chat message', msg);
});
});
http.listen(3001, function(){
console.log('listening on *:3001');
});