1 line
2.6 KiB
JSON
1 line
2.6 KiB
JSON
{"ast":null,"code":"'use strict';\n\nvar EventEmitter = require('events').EventEmitter,\n inherits = require('inherits'),\n eventUtils = require('../../utils/event'),\n browser = require('../../utils/browser'),\n urlUtils = require('../../utils/url');\n\nvar debug = function debug() {};\n\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:sender:xdr');\n} // References:\n// http://ajaxian.com/archives/100-line-ajax-wrapper\n// http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx\n\n\nfunction XDRObject(method, url, payload) {\n debug(method, url);\n var self = this;\n EventEmitter.call(this);\n setTimeout(function () {\n self._start(method, url, payload);\n }, 0);\n}\n\ninherits(XDRObject, EventEmitter);\n\nXDRObject.prototype._start = function (method, url, payload) {\n debug('_start');\n var self = this;\n var xdr = new global.XDomainRequest(); // IE caches even POSTs\n\n url = urlUtils.addQuery(url, 't=' + +new Date());\n\n xdr.onerror = function () {\n debug('onerror');\n\n self._error();\n };\n\n xdr.ontimeout = function () {\n debug('ontimeout');\n\n self._error();\n };\n\n xdr.onprogress = function () {\n debug('progress', xdr.responseText);\n self.emit('chunk', 200, xdr.responseText);\n };\n\n xdr.onload = function () {\n debug('load');\n self.emit('finish', 200, xdr.responseText);\n\n self._cleanup(false);\n };\n\n this.xdr = xdr;\n this.unloadRef = eventUtils.unloadAdd(function () {\n self._cleanup(true);\n });\n\n try {\n // Fails with AccessDenied if port number is bogus\n this.xdr.open(method, url);\n\n if (this.timeout) {\n this.xdr.timeout = this.timeout;\n }\n\n this.xdr.send(payload);\n } catch (x) {\n this._error();\n }\n};\n\nXDRObject.prototype._error = function () {\n this.emit('finish', 0, '');\n\n this._cleanup(false);\n};\n\nXDRObject.prototype._cleanup = function (abort) {\n debug('cleanup', abort);\n\n if (!this.xdr) {\n return;\n }\n\n this.removeAllListeners();\n eventUtils.unloadDel(this.unloadRef);\n this.xdr.ontimeout = this.xdr.onerror = this.xdr.onprogress = this.xdr.onload = null;\n\n if (abort) {\n try {\n this.xdr.abort();\n } catch (x) {// intentionally empty\n }\n }\n\n this.unloadRef = this.xdr = null;\n};\n\nXDRObject.prototype.close = function () {\n debug('close');\n\n this._cleanup(true);\n}; // IE 8/9 if the request target uses the same scheme - #79\n\n\nXDRObject.enabled = !!(global.XDomainRequest && browser.hasDomain());\nmodule.exports = XDRObject;","map":null,"metadata":{},"sourceType":"script"} |