Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Events (start, close) #842

Open
stefanwerfling opened this issue Jan 22, 2025 · 0 comments
Open

Session Events (start, close) #842

stefanwerfling opened this issue Jan 22, 2025 · 0 comments
Labels

Comments

@stefanwerfling
Copy link

stefanwerfling commented Jan 22, 2025

Is your feature request related to a problem? Please describe

I searched the documentation and only found this: https://nginx.org/en/docs/njs/reference.html#s_on
I would like to know when a stream (which would also have to be a session) starts and closes again.

Describe the solution you'd like

It would be nice to have "start" and "close" on the event ".on()" for stream and http.

  • start: A connection from the client is incoming (first connection from the client)
  • close: The client disconnects

And to be able to identify the session using an “ID”.

async(s: NginxStreamRequest): Promise<void> => { 

   r.on('start', () => {
      const id = s.identifer();
      ....
   });

   r.on('close', () => {
      const id = s.identifer();
      // cleanup somthing
   });

}

As an alternative (This is actually a better approach to get “start” as an event.), I could also imagine having to create an event object/function:

stream {
	js_import mainstream from /opt/test.js;

	...

	server {
		listen 80;
		js_access mainstream.accessAddressStream;
		js_session_event mainstream.sessionEvent;
		...
	}
}

test.js:

const accessAddressStream = async(s: NginxStreamRequest): Promise<void> => {
.....
}

const sessionEvent = async(event: SessionEvent, s: NginxStreamRequest|NginxHTTPRequest, ): Promise<void> => {
	const id = s.identifer();

	switch(event) {
		case SessionEvent.start:
			.....
			break;

		case SessionEvent.start:
			.....
			break;
	}

.....
}

export default {accessAddressStream, sessionEvent};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant