update example
This commit is contained in:
parent
e9b8ea4302
commit
870a274be9
@ -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 () {
|
||||
|
@ -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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user