socket.io-cookies-parser

Socket.IO Cookies Parser help us handle cookie for Socket.IO

Usage no npm install needed!

<script type="module">
  import socketIoCookiesParser from 'https://cdn.skypack.dev/socket.io-cookies-parser';
</script>

README

Socket.IO Cookies Parser Build Status

Socket.IO Cookies Parser help us handle cookie for Socket.IO

Note: After setup success, socket.request.cookies was parsed to JSON object.

Functions:

/**
 * @method namespaceCookieParser setup socket midleware for namespace instance
 * @param socket Socket
 */
function namespaceCookieParser(socket: Socket): void;
/**
 * @method ioCookieParser setup socket midleware for io instance
 * @param socket Socket
 * @param next (err?: ExtendedError | undefined) => void
 */
function ioCookieParser(socket: Socket, next: (err?: ExtendedError | undefined) => void): void;

Example:

//ES6
import socketio from "socket.io";
import { namespaceCookieParser, ioCookieParser } from "socket.io-cookies-parser";
...
const io = new socketio.Server();
io.use(ioCookieParser);
...
const client = io.of("/client", namespaceCookieParser);
...