1 line
2.3 KiB
JSON
1 line
2.3 KiB
JSON
{"ast":null,"code":"'use strict';\n\nvar inherits = require('inherits'),\n iframeUtils = require('../../utils/iframe'),\n urlUtils = require('../../utils/url'),\n EventEmitter = require('events').EventEmitter,\n random = require('../../utils/random');\n\nvar debug = function debug() {};\n\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:receiver:htmlfile');\n}\n\nfunction HtmlfileReceiver(url) {\n debug(url);\n EventEmitter.call(this);\n var self = this;\n iframeUtils.polluteGlobalNamespace();\n this.id = 'a' + random.string(6);\n url = urlUtils.addQuery(url, 'c=' + decodeURIComponent(iframeUtils.WPrefix + '.' + this.id));\n debug('using htmlfile', HtmlfileReceiver.htmlfileEnabled);\n var constructFunc = HtmlfileReceiver.htmlfileEnabled ? iframeUtils.createHtmlfile : iframeUtils.createIframe;\n global[iframeUtils.WPrefix][this.id] = {\n start: function start() {\n debug('start');\n self.iframeObj.loaded();\n },\n message: function message(data) {\n debug('message', data);\n self.emit('message', data);\n },\n stop: function stop() {\n debug('stop');\n\n self._cleanup();\n\n self._close('network');\n }\n };\n this.iframeObj = constructFunc(url, function () {\n debug('callback');\n\n self._cleanup();\n\n self._close('permanent');\n });\n}\n\ninherits(HtmlfileReceiver, EventEmitter);\n\nHtmlfileReceiver.prototype.abort = function () {\n debug('abort');\n\n this._cleanup();\n\n this._close('user');\n};\n\nHtmlfileReceiver.prototype._cleanup = function () {\n debug('_cleanup');\n\n if (this.iframeObj) {\n this.iframeObj.cleanup();\n this.iframeObj = null;\n }\n\n delete global[iframeUtils.WPrefix][this.id];\n};\n\nHtmlfileReceiver.prototype._close = function (reason) {\n debug('_close', reason);\n this.emit('close', null, reason);\n this.removeAllListeners();\n};\n\nHtmlfileReceiver.htmlfileEnabled = false; // obfuscate to avoid firewalls\n\nvar axo = ['Active'].concat('Object').join('X');\n\nif (axo in global) {\n try {\n HtmlfileReceiver.htmlfileEnabled = !!new global[axo]('htmlfile');\n } catch (x) {// intentionally empty\n }\n}\n\nHtmlfileReceiver.enabled = HtmlfileReceiver.htmlfileEnabled || iframeUtils.iframeEnabled;\nmodule.exports = HtmlfileReceiver;","map":null,"metadata":{},"sourceType":"script"} |