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

Support for Server-Sent Events (SSE) #87

Open
apla opened this issue Sep 5, 2019 · 3 comments
Open

Support for Server-Sent Events (SSE) #87

apla opened this issue Sep 5, 2019 · 3 comments

Comments

@apla
Copy link
Contributor

apla commented Sep 5, 2019

For our project we would like to use SSE. Currently, code to activate SSE for LiveReload 3.0.0 is quite simple:

if (LiveReload) {
	LiveReload.connector.disconnect();
}

var source = new EventSource(url);

source.addEventListener ('reload', function (evt) {
	var files;
	try { files = JSON.parse (evt.data); } catch (e) { return; }

	if (LiveReload) {
		files.forEach (function (file) {
			LiveReload.performReload ({path: file})
		});
	} else {
		location.reload ();
	}
});

source.addEventListener ('alert', function (evt) {
	console.log ('alert event', evt);
	if (LiveReload) {
		LiveReload.performAlert (evt.data);
	}
});

Unfortunately, this not works with minified version nor version 3.0.1. I would like to make it works without LiveReload.connector.disconnect() if that's fine for you

@smhg
Copy link
Contributor

smhg commented Sep 9, 2019

I'm not very up-to-date with this. This would function as a replacement for websockets, right?
If so, how would you want to signal you want to use SSE instead? Or would livereload 'listen' to both at the same time?

Unfortunately, this not works with minified version nor version 3.0.1.

You mean this doesn't work with something that happened with 3.x (as in: it did work with 2.x)?
Or what is problematic with version 3.0.1 and/or minification?

I would like to make it works without LiveReload.connector.disconnect() if that's fine for you

You mean you currently need the first 3 lines to stop the websocket? In that case, it is connected to my first question I guess?

@apla
Copy link
Contributor Author

apla commented Sep 9, 2019

I'm not very up-to-date with this. This would function as a replacement for websockets, right?

If so, how would you want to signal you want to use SSE instead? Or would livereload 'listen' to both at the same time?

Actually, I'm preparing the pull request for this. As a LiveReload user, you can choose between WebSockets and EventSource (SSE). WebSockets will be default choice.

From my point of view WebSocket is just a transport to send reload and alert commands. SSE will be additional transport to send those events. I'm planning to add transport property to the Options object and in case transport = sse, different connector will start and emit reload or alert events. Options already contains host, port and path, so transport will be enough.

You mean this doesn't work with something that happened with 3.x (as in: it did work with 2.x)?
Or what is problematic with version 3.0.1 and/or minification?

Not sure about problem in minified version, but I've fixed issue with 3.0.1 in #88

You mean you currently need the first 3 lines to stop the websocket? In that case, it is connected to my first question I guess?

With my patch, disconnect() will not be needed anymore, so no problem with minified version.

@smhg
Copy link
Contributor

smhg commented Sep 10, 2019

I'm not fully comprehending what the issues with the minified version are, but if you can/could solve them: awesome.

The idea of multiple transports sounds nice! Looking forward to your PR! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants