src/StreamClient.js
function StreamClient(options) {
    EventEmitter.call(this);
    SockJS = options.SockJS || SockJS; // Facilitate testing
    this.options = extend({}, options); // Clone
    this.options.debug = this.options.debug || false;
    this.options.retry = this.options.retry || 10; // Try to (re)connect 10 times before giving up
    this.options.retryTimeout = this.options.retryTimeout !== undefined ? this.options.retryTimeout : 500;
    this.options.protocol = this.options.protocol || window.location.protocol;
    if (this.options.protocol.slice(-1) !== ':') {
        this.options.protocol += ':';
    }
    this.options.port = Number(this.options.port);
    if (!this.options.port) {
        if (this.options.protocol === "http:") {
            this.options.port = 80
        } else if (this.options.protocol === "https:") {
            this.options.port = 443
        } else {
            throw new Error("Invalid protocol and port");
        }
    }
    this.options.endpoint = this.options.endpoint || '/stream';
    if (!this.options.hostname && options.environment) {
        this.options.hostname = environments[options.environment];
    }
    if (!this.options.hostname) {
        throw new Error("Stream Hostname is required");
    }

    // SockJS - Stream Connection
    this.lfToken = null;
    this.conn = null;
    this.lastError = null;
    this.retryCount = 0;
    this.rebalancedTo = null;
    this.allProtocols = Object.keys(SockJS.getUtils().probeProtocols());
    this.allProtocolsWithoutWS = this.allProtocols.slice();
    this.allProtocolsWithoutWS.splice(this.allProtocols.indexOf("websocket"),1);
    this.streams = {};
    // Stream State
    this.States = States; // Make accessible for testing
    this.state = new State(States.DISCONNECTED);
    this.state.on("change", this._stateChangeHandler.bind(this));
}
function StreamClient(options) {
    EventEmitter.call(this);
    SockJS = options.SockJS || SockJS; // Facilitate testing
    this.options = extend({}, options); // Clone
    this.options.debug = this.options.debug || false;
    this.options.retry = this.options.retry || 10; // Try to (re)connect 10 times before giving up
    this.options.retryTimeout = this.options.retryTimeout !== undefined ? this.options.retryTimeout : 500;
    this.options.protocol = this.options.protocol || window.location.protocol;
    if (this.options.protocol.slice(-1) !== ':') {
        this.options.protocol += ':';
    }
    this.options.port = Number(this.options.port);
    if (!this.options.port) {
        if (this.options.protocol === "http:") {
            this.options.port = 80
        } else if (this.options.protocol === "https:") {
            this.options.port = 443
        } else {
            throw new Error("Invalid protocol and port");
        }
    }
    this.options.endpoint = this.options.endpoint || '/stream';
    if (!this.options.hostname && options.environment) {
        this.options.hostname = environments[options.environment];
    }
    if (!this.options.hostname) {
        throw new Error("Stream Hostname is required");
    }

    // SockJS - Stream Connection
    this.lfToken = null;
    this.conn = null;
    this.lastError = null;
    this.retryCount = 0;
    this.rebalancedTo = null;
    this.allProtocols = Object.keys(SockJS.getUtils().probeProtocols());
    this.allProtocolsWithoutWS = this.allProtocols.slice();
    this.allProtocolsWithoutWS.splice(this.allProtocols.indexOf("websocket"),1);
    this.streams = {};
    // Stream State
    this.States = States; // Make accessible for testing
    this.state = new State(States.DISCONNECTED);
    this.state.on("change", this._stateChangeHandler.bind(this));
}
function StreamClient ( options ) { EventEmitter . call ( this ) ; SockJS = options . SockJS || SockJS ; // Facilitate testing this . options = extend ( { } , options ) ; // Clone this . options . debug = this . options . debug || false ; this . options . retry = this . options . retry || 10 ; // Try to (re)connect 10 times before giving up this . options . retryTimeout = this . options . retryTimeout !== undefined ? this . options . retryTimeout : 500 ; this . options . protocol = this . options . protocol || window . location . protocol ; if ( this . options . protocol . slice ( - 1 ) !== ':' ) { this . options . protocol += ':' ; } this . options . port = Number ( this . options . port ) ; if ( ! this . options . port ) { if ( this . options . protocol === "http:" ) { this . options . port = 80 } else if ( this . options . protocol === "https:" ) { this . options . port = 443 } else { throw new Error ( "Invalid protocol and port" ) ; } } this . options . endpoint = this . options . endpoint || '/stream' ; if ( ! this . options . hostname && options . environment ) { this . options . hostname = environments [ options . environment ] ; } if ( ! this . options . hostname ) { throw new Error ( "Stream Hostname is required" ) ; } // SockJS - Stream Connection this . lfToken = null ; this . conn = null ; this . lastError = null ; this . retryCount = 0 ; this . rebalancedTo = null ; this . allProtocols = Object . keys ( SockJS . getUtils ( ) . probeProtocols ( ) ) ; this . allProtocolsWithoutWS = this . allProtocols . slice ( ) ; this . allProtocolsWithoutWS . splice ( this . allProtocols . indexOf ( "websocket" ) , 1 ) ; this . streams = { } ; // Stream State this . States = States ; // Make accessible for testing this . state = new State ( States . DISCONNECTED ) ; this . state . on ( "change" , this . _stateChangeHandler . bind ( this ) ) ; }
Instantiates a Stream v4 client that is responsible for service discovery, login, connecting
and streaming events for a given stream. The client will emit messages 'start', 'data', 'end', 'close', 'error'.
@param options - Map containing hostname and optionally protocol, port and endpoint; retry and retryTimeout; debug
@constructor
Instantiates a Stream v4 client that is responsible for service discovery login connecting and streaming events for a given stream . The client will emit messages start data end close error .