Sha256: 527247cb1cca04a63bc44c0fe664fc21cdf6e9435fc067d31f35c6083288367a

Contents?: true

Size: 1.29 KB

Versions: 34

Compression:

Stored size: 1.29 KB

Contents

'use strict';

var inherits = require('inherits')
  , EventEmitter = require('events').EventEmitter
  ;

var debug = function() {};
if (process.env.NODE_ENV !== 'production') {
  debug = require('debug')('sockjs-client:polling');
}

function Polling(Receiver, receiveUrl, AjaxObject) {
  debug(receiveUrl);
  EventEmitter.call(this);
  this.Receiver = Receiver;
  this.receiveUrl = receiveUrl;
  this.AjaxObject = AjaxObject;
  this._scheduleReceiver();
}

inherits(Polling, EventEmitter);

Polling.prototype._scheduleReceiver = function() {
  debug('_scheduleReceiver');
  var self = this;
  var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject);

  poll.on('message', function(msg) {
    debug('message', msg);
    self.emit('message', msg);
  });

  poll.once('close', function(code, reason) {
    debug('close', code, reason, self.pollIsClosing);
    self.poll = poll = null;

    if (!self.pollIsClosing) {
      if (reason === 'network') {
        self._scheduleReceiver();
      } else {
        self.emit('close', code || 1006, reason);
        self.removeAllListeners();
      }
    }
  });
};

Polling.prototype.abort = function() {
  debug('abort');
  this.removeAllListeners();
  this.pollIsClosing = true;
  if (this.poll) {
    this.poll.abort();
  }
};

module.exports = Polling;

Version data entries

34 entries across 33 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.18.0 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.18.2 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.16.1 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.15.2 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.18.4 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.18.1 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.14.0 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
tang-0.2.1 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/polling.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/sockjs-client/lib/transport/lib/polling.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/sockjs-client/lib/transport/lib/polling.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/sockjs-client/lib/transport/lib/polling.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/sockjs-client/lib/transport/lib/polling.js
tang-0.2.0 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/polling.js
tang-0.1.0 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/polling.js
tang-0.0.9 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/polling.js
enju_library-0.3.8 spec/dummy/node_modules/sockjs-client/lib/transport/lib/polling.js
ilog-0.4.1 node_modules/sockjs-client/lib/transport/lib/polling.js