update example

This commit is contained in:
José F. Romaniello 2014-06-14 19:01:34 -03:00
parent e9b8ea4302
commit 870a274be9
2 changed files with 7 additions and 8 deletions

View File

@ -5,9 +5,9 @@
</head>
<body>
<form id="login">
<input type="text" id="username" />
<input type="password" id="password" />
<input type="submit">
<input type="text" id="username" value="john" />
<input type="password" id="password" value="aaa" />
<input type="submit" value="login">
</form>
<div>
@ -21,9 +21,8 @@
var token, socket;
function connect () {
socket = io.connect('', {
'force new connection': true,
query: token ? 'token=' + token : undefined
socket = io.connect(token ? ('?token=' + token) : '', {
'forceNew': true
});
socket.on('pong', function () {

View File

@ -31,14 +31,14 @@ app.post('/login', function (req, res) {
var server = http.createServer(app);
var sio = socketIo.listen(server);
sio.set('authorization', socketio_jwt.authorize({
sio.use(socketio_jwt.authorize({
secret: jwt_secret,
handshake: true
}));
sio.sockets
.on('connection', function (socket) {
console.log(socket.handshake.decoded_token.email, 'connected');
console.log(socket.decoded_token.email, 'connected');
socket.on('ping', function (m) {
socket.emit('pong', m);
});