UNPKG

ws2801-webserver

Version:

A ready-to-use webserver for the WS2801-Pi package.

28 lines (27 loc) 954 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SocketIoServer = void 0; const socket_io_1 = require("socket.io"); const uuid_1 = __importDefault(require("uuid")); class SocketIoServer { constructor(httpServer) { this.listeners = {}; this.socketIo = new socket_io_1.Server(httpServer); } // tslint:disable-next-line: no-any send(event, data) { this.socketIo.emit(event, data); } listen(event, callback) { this.listeners[uuid_1.default.v4()] = { event: event, callback: callback }; this.socketIo.on(event, callback); } removeListener(id) { const listener = this.listeners[id]; this.socketIo.removeListener(listener.event, listener.callback); } } exports.SocketIoServer = SocketIoServer;