An event stream to the server can be closed using the EventSource.close()
method
var eventSource = new EventSource("api/my-events");
// do things ...
eventSource.close(); // you will not receive anymore events from this object
The .close()
method does nothing is the stream is already closed.