UNPKG

n8n

Version:

n8n Workflow Automation Tool

47 lines 2.14 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SSEPush = void 0; const sse_channel_1 = __importDefault(require("sse-channel")); const typedi_1 = require("typedi"); const Logger_1 = require("../Logger"); const abstract_push_1 = require("./abstract.push"); let SSEPush = class SSEPush extends abstract_push_1.AbstractPush { constructor(logger) { super(logger); this.channel = new sse_channel_1.default(); this.connections = {}; this.channel.on('disconnect', (_, { req }) => { var _a; this.remove((_a = req === null || req === void 0 ? void 0 : req.query) === null || _a === void 0 ? void 0 : _a.pushRef); }); } add(pushRef, connection) { super.add(pushRef, connection); this.channel.addClient(connection.req, connection.res); } close({ res }) { res.end(); this.channel.removeClient(res); } sendToOneConnection(connection, data) { this.channel.send(data, [connection.res]); } }; exports.SSEPush = SSEPush; exports.SSEPush = SSEPush = __decorate([ (0, typedi_1.Service)(), __metadata("design:paramtypes", [Logger_1.Logger]) ], SSEPush); //# sourceMappingURL=sse.push.js.map