Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createEventStream = (options) => {
const { path, server, asMiddleWare } = options;
const eventStream = Emitter({ lastEventId: 0 });
let responses = [];
let onRequest;
const requestHandler = (request, response) => {
if (!isValidRequestForServerSentEvents(request)) {
return false;
}
const { socket } = request;
socket.setTimeout(0);
socket.setKeepAlive(true);
socket.setNoDelay(true);
response.writeHead(200, {
[`Content-Type`]: MIME
httpServer,
ws,
path,
highClients,
maxClients,
maxLength,
maxChannels,
maxChannelLength,
lowEnough,
packData = defaultPackData,
unpackData = defaultUnpackData,
} = options;
const wss = new ws.Server({ server: httpServer, path });
const facade = EventEmitter({});
const connectionsPool = new Set();
facade.connectionsPool = connectionsPool;
const formatSend = (data, channel) => {
const toSend = { channel, data };
return packData(toSend);
};
facade.send = (socket, data, channel = DEFAULT_CHANNEL) => {
if (isSocketInChannel(socket, channel)) {
socket.send(formatSend(data, channel));
socket[LAST_CONNECTION_CHECK] = Date.now();
}
};