Code Monkey home page Code Monkey logo

expresse's People

Contributors

fklingler avatar toverux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

expresse's Issues

Keep-alive messages, what are they for & compression bug

Let me start by pointing out a bug I found when applying your proposed to solution using this module with expressjs/compression.
You suggest that res.flush() be called after each res.sse.* call, but keep-alive messages also call the problematic res.write function, since this keep-alive logic happens outside of module user's reach we can't call flush after this happens.
This results in the client never receiving heartbeats until connection is closed or at user-level res.sse.* ; res.flush(); is called.

Secondly, what exactly are keep-alive messages for in this module?
Initially I thought they were a mechanism to be aware of a lost connection to a user, but there is no logic in place to notify module users of this.
So really what are they for?

Events aren't sent to the browser when using compression

I'm not able to receive events in the browser.

SERVER
res.sse.event("firstPaint", "10"); //

CLIENT

           `var source = new EventSource('/api/v1/get_SEE/test');

            source.addEventListener('message', function(e) {
                console.log("message"); //  never fired
            }, false);

            source.addEventListener('open', function(e) {
                // this is fired correctly when the page is opened
                console.log("connection opened");
            }, false);

            source.addEventListener('error', function(e) {
                if (e.readyState == EventSource.CLOSED) {
                    // this is fired correctly in the case
                    console.log("connection closed");
                }
            }, false);`

Type error with vite-express on res.sse.x

I am using vite-express and having this issue when making a GET request from my frontend to the route:

      res.sse.data('ok', someEvent)
                ^
TypeError: Cannot read properties of undefined (reading 'data')

I have used Typescript import:

import { ISseResponse, sse } from '@toverux/expresse'
let someEvent = 'foo'
router.get('/check', sse({ flushAfterWrite: true }) ,(res: ISseResponse) => {

    setTimeout(() => {
        res.sse.data('ok', someEvent)

    }, 1000)

})

Need Sample Code

I've been trying to make example code work for the past couple of hours .but couldn't make it work .I dont have much experience with node js .If possible can you provide some more like noob friendly example code .
I'm stuck at
someModule.on('someEvent', (event) => {

Does this someModule needs to be an event emitter ?

hope you reply to this

How to know when the SSE session gets closed?

I'm using the simple form

    this.router.get('/:id/events', sse(), (req,res:ISseResponse) => { 
           someModule.on('someEvent', (event) => 

And what happens is that when I reload my client page a couple of times, the number of event listeners keep adding up (from the someModule.on).

I can't depend on clients properly calling some "unregister" url, so I'm wondering if there's any way to detect clients which are no longer listening for SSE?

Determining the hub to use based on the request

Hi,

I want to use sseHub() with a different hub instance depending on the data in the request. Basically there are distinct sessions based on a token provided by the client, and each session should have its own hub. Since sseHub accepts ISseHubMiddlewareOptions that means I have to hard-code the hub, right? Is there any way to make it dynamic?

Basically, for each call of the API with the sseHub middleware, I need to first examine the request body to determine which hub to use for that client going forward.

I feel like I am going to end up subclassing Hub but I'm not sure of the direction, yet.

Issue with webpack-dev-server compression

As stated in the documentation SSE encounters problem when undergoing compression. The proposed flushAfterWrite: true is not effective for webpack-dev-server compression (which is used in create-react-app). To resolve this, one can set the 'Cache-Control' response header to 'no-cache, no-transform' (at least while not in production). I wasn't sure how to alter response headers using expresse, so I uninstalled.

sse-keep-alive instead of message - Silent Error on Hub.emit() ?

On the browser:
Screen Shot 2019-07-25 at 5 10 11 PM
We can see that it connected successfully (the first event), but I can't get it to send events afterwards?

I'm setting up the hub and middleware in an exclusive file. Which it works because it prints to the console only once.

import { Hub, sseHub } from '@toverux/expresse';

export const hub = (() => {
  const hubInstance = new Hub();
  console.log('INFO - SSE Hub created');
  return hubInstance;
})();

export const hubMiddleware = sseHub({ hub, serializer: String });

Here's the router definition, which it works because we can access the endpoint as the screenshot above.

import hub from './sseHub';

server.get('/v1/companies/events', sseHub({ hub }), (req, res) => {
    res.sse.event('subscribed:company', Date.now());
  });

Here's another file where I subscribe to a Redis channel and want to transmit the data through the hub to others peers connected.

The console.log after the hub.event prints into the console right, so I'm not sure where I'm getting things wrong.

import { hub } from './sseHub';

export default function () {
  const { port, host, db } = configRedis;
  const client = redis.createClient({ host, port, db });

  client.on('pmessage', (pattern, channel, message) => {
    if (channel.includes('company:new:')) {
      hub.event('eventname', { data: message }); // tried hub.event('eventname', 'event') too
      console.log(`INFO - Nova Empresa (${channel.slice(-14)}) | TxID: ${message}`);
    }
  });

  client.psubscribe('company:new:*');
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.