Server IP : 162.213.251.212 / Your IP : 18.190.25.139 [ Web Server : LiteSpeed System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : allssztx ( 535) PHP Version : 8.1.31 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/allssztx/www/easybuyer/node_modules/sockjs-client/lib/transport/receiver/ |
Upload File : |
'use strict'; var inherits = require('inherits') , EventEmitter = require('events').EventEmitter ; var debug = function() {}; if (process.env.NODE_ENV !== 'production') { debug = require('debug')('sockjs-client:receiver:xhr'); } function XhrReceiver(url, AjaxObject) { debug(url); EventEmitter.call(this); var self = this; this.bufferPosition = 0; this.xo = new AjaxObject('POST', url, null); this.xo.on('chunk', this._chunkHandler.bind(this)); this.xo.once('finish', function(status, text) { debug('finish', status, text); self._chunkHandler(status, text); self.xo = null; var reason = status === 200 ? 'network' : 'permanent'; debug('close', reason); self.emit('close', null, reason); self._cleanup(); }); } inherits(XhrReceiver, EventEmitter); XhrReceiver.prototype._chunkHandler = function(status, text) { debug('_chunkHandler', status); if (status !== 200 || !text) { return; } for (var idx = -1; ; this.bufferPosition += idx + 1) { var buf = text.slice(this.bufferPosition); idx = buf.indexOf('\n'); if (idx === -1) { break; } var msg = buf.slice(0, idx); if (msg) { debug('message', msg); this.emit('message', msg); } } }; XhrReceiver.prototype._cleanup = function() { debug('_cleanup'); this.removeAllListeners(); }; XhrReceiver.prototype.abort = function() { debug('abort'); if (this.xo) { this.xo.close(); debug('close'); this.emit('close', null, 'user'); this.xo = null; } this._cleanup(); }; module.exports = XhrReceiver;