https://github.com/co2-git/web-rockets-cookie
Use HTTP(s) cookies to identify your socket.io clients.
https://github.com/co2-git/web-rockets-cookie
Last synced: 8 months ago
JSON representation
Use HTTP(s) cookies to identify your socket.io clients.
- Host: GitHub
- URL: https://github.com/co2-git/web-rockets-cookie
- Owner: co2-git
- Created: 2016-02-09T04:57:52.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-27T02:58:35.000Z (about 10 years ago)
- Last Synced: 2025-03-27T11:44:44.930Z (about 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
web-rockets-cookie
===
Use HTTP(s) cookies to identify your socket.io clients.
# Install
```bash
npm install -s web-rockets-cookie
```
# Usage
```js
identifyByCookie(String cookieName, Boolean secureCookie, Function next);
```
## With SocketIO
```js
import SocketIO from 'socket.io';
import identifyByCookie from 'web-rockets-cookie';
const server = /* create a HTTP server */
const io = SocketIO.listen(server); /* create Web Sockets server */
io.use(identifyByCookie(
cookieName, // the name of the cookie we want to get value from
true, // if true, cookie is a secure cookie
(cookie, socket, next) => { // the callback function
// cookie is the cookie value of cookie name
// socket is the current socket
// next goes to next middleware
}));
```
## With Web-Rockets
```js
import WebRockets from 'web-rockets';
import identifyByCookie from 'web-rockets-cookie';
new WebRockets()
.use(identifyByCookie(cookieName, true, (cookie, socket, next) => {}));
```