girder/web_client/src/utilities/EventStream.js
function EventStream(settings) {
    const defaults = {
        timeout: null,
        streamPath: '/notification/stream'
    };

    // User-provided settings from initialization
    this.settings = _.extend(defaults, settings);
    // Possible states are 'closed', 'stopped', 'started'
    this._state = 'closed';
    // Whether this is started (if so, holds the EventSource instance)
    this._eventSource = null;

    // Create context bindings only once, so they can be referenced when unbinding events
    this._onVisibilityStateChange = _.bind(this._onVisibilityStateChange, this);
    this._onMessage = _.bind(this._onMessage, this);
    this._onError = _.bind(this._onError, this);

    return _.extend(this, Backbone.Events);
}
function EventStream(settings) {
    const defaults = {
        timeout: null,
        streamPath: '/notification/stream'
    };

    // User-provided settings from initialization
    this.settings = _.extend(defaults, settings);
    // Possible states are 'closed', 'stopped', 'started'
    this._state = 'closed';
    // Whether this is started (if so, holds the EventSource instance)
    this._eventSource = null;

    // Create context bindings only once, so they can be referenced when unbinding events
    this._onVisibilityStateChange = _.bind(this._onVisibilityStateChange, this);
    this._onMessage = _.bind(this._onMessage, this);
    this._onError = _.bind(this._onError, this);

    return _.extend(this, Backbone.Events);
}
The EventStream type wraps window.EventSource to listen to the unified
per-user event channel endpoint using the SSE protocol. When events are
received on the SSE channel, this triggers a Backbone event of the form
'g:event.<type>' where <type> is the value of the event type field.
Listeners can bind to specific event types on the channel.