Merge pull request #26530 from lukaszluczak/master

[express-socket.io-session] Added "session" and "sessionID" to SocketIO.Socket.handshake
This commit is contained in:
Mine Starks
2018-06-15 11:14:28 -07:00
committed by GitHub
3 changed files with 68 additions and 44 deletions
@@ -26,3 +26,19 @@ io.use(sharedsession(session));
io.use(sharedsession(session, { autoSave: true, saveUninitialized: true }));
io.use(sharedsession(session, cookieParser));
io.use(sharedsession(session, cookieParser, { autoSave: true, saveUninitialized: true }));
io.on('connection', (socket) => {
const sessionID = [
socket.handshake.sessionID,
socket.handshake.session!.id
];
const sessionData = [
socket.handshake.session!['sessionEntry'],
socket.handshake.session!.anotherSessionEntry
];
socket.handshake.session!.touch(() => {});
socket.handshake.session!.regenerate(() => {});
socket.handshake.session!.save(() => {});
socket.handshake.session!.reload(() => {});
socket.handshake.session!.destroy(() => {});
});
+7
View File
@@ -7,6 +7,13 @@
import socketio = require('socket.io');
import express = require('express');
declare module "socket.io" {
interface Handshake {
session?: Express.Session;
sessionID?: string;
}
}
declare function sharedsession(
expressSessionMiddleware: express.RequestHandler,
cookieParserMiddleware: express.RequestHandler,
+45 -44
View File
@@ -553,49 +553,7 @@ declare namespace SocketIO {
/**
* The object used when negociating the handshake
*/
handshake: {
/**
* The headers passed along with the request. e.g. 'host',
* 'connection', 'accept', 'referer', 'cookie'
*/
headers: any;
/**
* The current time, as a string
*/
time: string;
/**
* The remote address of the connection request
*/
address: string;
/**
* Is this a cross-domain request?
*/
xdomain: boolean;
/**
* Is this a secure request?
*/
secure: boolean;
/**
* The timestamp for when this was issued
*/
issued: number;
/**
* The request url
*/
url: string;
/**
* Any query string parameters in the request url
*/
query: any;
};
handshake: Handshake;
/**
* Sets the 'json' flag when emitting an event
*/
@@ -629,7 +587,7 @@ declare namespace SocketIO {
/**
* Registers a middleware, which is a function that gets executed for every incoming Packet and receives as parameter the packet and a function to optionally defer execution to the next registered middleware.
*
*
* Errors passed to middleware callbacks are sent as special error packets to clients.
*/
use( fn: ( packet: Packet, next: (err?: any) => void ) => void ): Socket;
@@ -690,6 +648,49 @@ declare namespace SocketIO {
compress( compress: boolean ): Socket;
}
interface Handshake {
/**
* The headers passed along with the request. e.g. 'host',
* 'connection', 'accept', 'referer', 'cookie'
*/
headers: any;
/**
* The current time, as a string
*/
time: string;
/**
* The remote address of the connection request
*/
address: string;
/**
* Is this a cross-domain request?
*/
xdomain: boolean;
/**
* Is this a secure request?
*/
secure: boolean;
/**
* The timestamp for when this was issued
*/
issued: number;
/**
* The request url
*/
url: string;
/**
* Any query string parameters in the request url
*/
query: any;
}
/**
* The interface used when dealing with rooms etc
*/