1.1.1 • Published 3 years ago

setup-socket.io v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Setup Socket.IO Build Status

Functions:

/**
 * @method initIO Initiate io instance
 * @param server Server
 * @param origin string
 * @returns socketio.Server
 */
function initIO(server: Server, origin: string): socketio.Server;
/**
 * @method createNamespace Create namespace of io
 * @param nsp string
 * @returns Namespace
 */
function createNamespace(nsp: string): Namespace;

Example:

// ES6
import dotenv from "dotenv";
import { createServer } from "http";
import express from "express";
import { Socket } from "socket.io";
import io, { createNamespace, initIO } from "setup-socket.io";

dotenv.config();

const ORIGIN = process.env.ORIGIN || "*";

const app = express();
const server = createServer(app);

// Init io
initIO(server, ORIGIN);

// Create client namespace
const client = createNamespace("/client");

io.on("connection", (socket: Socket) => {
    socket.on("your-event", (message) => {
        console.log(message);
        console.log("Cookies:", socket.request.cookies);
    });
});

client.on("connection", (socket: Socket) => {
    socket.on("your-event", (message) => {
        console.log(message);
        console.log("Cookies:", socket.request.cookies);
    });
});
1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.2

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago