How to use the faye-websocket.EventSource function in faye-websocket

To help you get started, we’ve selected a few faye-websocket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github popeindustries / dvlp / lib / reloader / index.js View on Github external
this.server = http.createServer(async (req, res) => {
        if (req.url !== ENDPOINT || !EventSource.isEventSource(req)) {
          res.writeHead(404);
          res.end();
          return;
        }

        const client = new EventSource(req, res, DEFAULT_CLIENT_CONFIG);

        this.clients.add(client);
        debug('added reload connection', this.clients.size);

        client.on('close', () => {
          this.clients.delete(client);
          debug('removed reload connection', this.clients.size);
        });
      });
github Schoonology / teleprompter / lib / router.js View on Github external
router.get('/:script/events', function (req, res, next) {
    if (!EventSource.isEventSource(req)) {
      res.writeHead(400);
      res.end();
      return;
    }

    var source = new EventSource(req, res);
    var bus = buses[req.params.script] || (buses[req.params.script] = createBus());
    var watcher;

    function onEvent(event) {
      source.send(JSON.stringify(event), { event: event.type });
    }

    bus.addListener(onEvent);

    source.on('close', function () {
      bus.removeListener(onEvent);
      watcher && watcher.close();
    });

    resolvePath(req.params.script)
      .then(function (filename) {

faye-websocket

Standards-compliant WebSocket server and client

Apache-2.0
Latest version published 4 years ago

Package Health Score

73 / 100
Full package analysis