mirror of
https://github.com/Thream/socketio-jwt.git
synced 2024-07-21 09:38:31 +02:00
update example
This commit is contained in:
parent
e9b8ea4302
commit
870a274be9
@ -5,9 +5,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form id="login">
|
<form id="login">
|
||||||
<input type="text" id="username" />
|
<input type="text" id="username" value="john" />
|
||||||
<input type="password" id="password" />
|
<input type="password" id="password" value="aaa" />
|
||||||
<input type="submit">
|
<input type="submit" value="login">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@ -21,9 +21,8 @@
|
|||||||
var token, socket;
|
var token, socket;
|
||||||
|
|
||||||
function connect () {
|
function connect () {
|
||||||
socket = io.connect('', {
|
socket = io.connect(token ? ('?token=' + token) : '', {
|
||||||
'force new connection': true,
|
'forceNew': true
|
||||||
query: token ? 'token=' + token : undefined
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('pong', function () {
|
socket.on('pong', function () {
|
||||||
|
@ -31,14 +31,14 @@ app.post('/login', function (req, res) {
|
|||||||
var server = http.createServer(app);
|
var server = http.createServer(app);
|
||||||
var sio = socketIo.listen(server);
|
var sio = socketIo.listen(server);
|
||||||
|
|
||||||
sio.set('authorization', socketio_jwt.authorize({
|
sio.use(socketio_jwt.authorize({
|
||||||
secret: jwt_secret,
|
secret: jwt_secret,
|
||||||
handshake: true
|
handshake: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
sio.sockets
|
sio.sockets
|
||||||
.on('connection', function (socket) {
|
.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.on('ping', function (m) {
|
||||||
socket.emit('pong', m);
|
socket.emit('pong', m);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user