|
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.JSONP = void 0; |
|
const polling_1 = require("./polling"); |
|
const qs = require("querystring"); |
|
const rDoubleSlashes = /\\\\n/g; |
|
const rSlashes = /(\\)?\\n/g; |
|
class JSONP extends polling_1.Polling { |
|
|
|
|
|
|
|
|
|
|
|
constructor(req) { |
|
super(req); |
|
this.head = "___eio[" + (req._query.j || "").replace(/[^0-9]/g, "") + "]("; |
|
this.foot = ");"; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
onData(data) { |
|
|
|
|
|
data = qs.parse(data).d; |
|
if ("string" === typeof data) { |
|
|
|
|
|
data = data.replace(rSlashes, function (match, slashes) { |
|
return slashes ? match : "\n"; |
|
}); |
|
super.onData(data.replace(rDoubleSlashes, "\\n")); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
doWrite(data, options, callback) { |
|
|
|
|
|
const js = JSON.stringify(data) |
|
.replace(/\u2028/g, "\\u2028") |
|
.replace(/\u2029/g, "\\u2029"); |
|
|
|
data = this.head + js + this.foot; |
|
super.doWrite(data, options, callback); |
|
} |
|
} |
|
exports.JSONP = JSONP; |
|
|