diff --git a/types/express-socket.io-session/express-socket.io-session-tests.ts b/types/express-socket.io-session/express-socket.io-session-tests.ts index 46dd000882..6937952dd6 100644 --- a/types/express-socket.io-session/express-socket.io-session-tests.ts +++ b/types/express-socket.io-session/express-socket.io-session-tests.ts @@ -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(() => {}); +}); diff --git a/types/express-socket.io-session/index.d.ts b/types/express-socket.io-session/index.d.ts index 39a1fb4ff6..07acac556a 100644 --- a/types/express-socket.io-session/index.d.ts +++ b/types/express-socket.io-session/index.d.ts @@ -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, diff --git a/types/socket.io/index.d.ts b/types/socket.io/index.d.ts index 6f7c0ef321..4d6adc529c 100644 --- a/types/socket.io/index.d.ts +++ b/types/socket.io/index.d.ts @@ -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 */