Sha256: f5eb4eacd1b0ca75060f58b66ab67b714f7af0b32714c0f8724de6f77f4dea77

Contents?: true

Size: 1.28 KB

Versions: 34

Compression:

Stored size: 1.28 KB

Contents

'use strict';

var inherits = require('inherits')
  , urlUtils = require('../../utils/url')
  , SenderReceiver = require('./sender-receiver')
  ;

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

function createAjaxSender(AjaxObject) {
  return function(url, payload, callback) {
    debug('create ajax sender', url, payload);
    var opt = {};
    if (typeof payload === 'string') {
      opt.headers = {'Content-type': 'text/plain'};
    }
    var ajaxUrl = urlUtils.addPath(url, '/xhr_send');
    var xo = new AjaxObject('POST', ajaxUrl, payload, opt);
    xo.once('finish', function(status) {
      debug('finish', status);
      xo = null;

      if (status !== 200 && status !== 204) {
        return callback(new Error('http status ' + status));
      }
      callback();
    });
    return function() {
      debug('abort');
      xo.close();
      xo = null;

      var err = new Error('Aborted');
      err.code = 1000;
      callback(err);
    };
  };
}

function AjaxBasedTransport(transUrl, urlSuffix, Receiver, AjaxObject) {
  SenderReceiver.call(this, transUrl, urlSuffix, createAjaxSender(AjaxObject), Receiver, AjaxObject);
}

inherits(AjaxBasedTransport, SenderReceiver);

module.exports = AjaxBasedTransport;

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/ajax-based.js
disco_app-0.18.0 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.18.2 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.16.1 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.15.2 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.18.4 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.18.1 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.14.0 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
tang-0.2.1 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
tang-0.2.0 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
tang-0.1.0 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
tang-0.0.9 spec/tang_app/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
enju_library-0.3.8 spec/dummy/node_modules/sockjs-client/lib/transport/lib/ajax-based.js
ilog-0.4.1 node_modules/sockjs-client/lib/transport/lib/ajax-based.js