@base44-preview/cli 0.1.24-pr.646.09ee9f4 → 0.1.25-pr.643.2112831
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +3294 -152
- package/dist/cli/index.js.map +30 -15
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -171420,6 +171420,2889 @@ var require_tmp = __commonJS(function(exports, module) {
|
|
|
171420
171420
|
exports.setGracefulCleanup = setGracefulCleanup;
|
|
171421
171421
|
});
|
|
171422
171422
|
|
|
171423
|
+
// ../../node_modules/ws/lib/constants.js
|
|
171424
|
+
var require_constants6 = __commonJS(function(exports, module) {
|
|
171425
|
+
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
171426
|
+
var hasBlob = typeof Blob !== "undefined";
|
|
171427
|
+
if (hasBlob)
|
|
171428
|
+
BINARY_TYPES.push("blob");
|
|
171429
|
+
module.exports = {
|
|
171430
|
+
BINARY_TYPES,
|
|
171431
|
+
CLOSE_TIMEOUT: 30000,
|
|
171432
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
171433
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
171434
|
+
hasBlob,
|
|
171435
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
171436
|
+
kListener: Symbol("kListener"),
|
|
171437
|
+
kStatusCode: Symbol("status-code"),
|
|
171438
|
+
kWebSocket: Symbol("websocket"),
|
|
171439
|
+
NOOP: () => {}
|
|
171440
|
+
};
|
|
171441
|
+
});
|
|
171442
|
+
|
|
171443
|
+
// ../../node_modules/ws/lib/buffer-util.js
|
|
171444
|
+
var require_buffer_util = __commonJS(function(exports, module) {
|
|
171445
|
+
var { EMPTY_BUFFER } = require_constants6();
|
|
171446
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
171447
|
+
function concat(list, totalLength) {
|
|
171448
|
+
if (list.length === 0)
|
|
171449
|
+
return EMPTY_BUFFER;
|
|
171450
|
+
if (list.length === 1)
|
|
171451
|
+
return list[0];
|
|
171452
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
171453
|
+
let offset = 0;
|
|
171454
|
+
for (let i = 0;i < list.length; i++) {
|
|
171455
|
+
const buf = list[i];
|
|
171456
|
+
target.set(buf, offset);
|
|
171457
|
+
offset += buf.length;
|
|
171458
|
+
}
|
|
171459
|
+
if (offset < totalLength) {
|
|
171460
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
171461
|
+
}
|
|
171462
|
+
return target;
|
|
171463
|
+
}
|
|
171464
|
+
function _mask(source, mask, output, offset, length) {
|
|
171465
|
+
for (let i = 0;i < length; i++) {
|
|
171466
|
+
output[offset + i] = source[i] ^ mask[i & 3];
|
|
171467
|
+
}
|
|
171468
|
+
}
|
|
171469
|
+
function _unmask(buffer, mask) {
|
|
171470
|
+
for (let i = 0;i < buffer.length; i++) {
|
|
171471
|
+
buffer[i] ^= mask[i & 3];
|
|
171472
|
+
}
|
|
171473
|
+
}
|
|
171474
|
+
function toArrayBuffer(buf) {
|
|
171475
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
171476
|
+
return buf.buffer;
|
|
171477
|
+
}
|
|
171478
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
171479
|
+
}
|
|
171480
|
+
function toBuffer(data) {
|
|
171481
|
+
toBuffer.readOnly = true;
|
|
171482
|
+
if (Buffer.isBuffer(data))
|
|
171483
|
+
return data;
|
|
171484
|
+
let buf;
|
|
171485
|
+
if (data instanceof ArrayBuffer) {
|
|
171486
|
+
buf = new FastBuffer(data);
|
|
171487
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
171488
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
171489
|
+
} else {
|
|
171490
|
+
buf = Buffer.from(data);
|
|
171491
|
+
toBuffer.readOnly = false;
|
|
171492
|
+
}
|
|
171493
|
+
return buf;
|
|
171494
|
+
}
|
|
171495
|
+
module.exports = {
|
|
171496
|
+
concat,
|
|
171497
|
+
mask: _mask,
|
|
171498
|
+
toArrayBuffer,
|
|
171499
|
+
toBuffer,
|
|
171500
|
+
unmask: _unmask
|
|
171501
|
+
};
|
|
171502
|
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
171503
|
+
try {
|
|
171504
|
+
const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
|
|
171505
|
+
module.exports.mask = function(source, mask2, output, offset, length) {
|
|
171506
|
+
if (length < 48)
|
|
171507
|
+
_mask(source, mask2, output, offset, length);
|
|
171508
|
+
else
|
|
171509
|
+
bufferUtil.mask(source, mask2, output, offset, length);
|
|
171510
|
+
};
|
|
171511
|
+
module.exports.unmask = function(buffer, mask) {
|
|
171512
|
+
if (buffer.length < 32)
|
|
171513
|
+
_unmask(buffer, mask);
|
|
171514
|
+
else
|
|
171515
|
+
bufferUtil.unmask(buffer, mask);
|
|
171516
|
+
};
|
|
171517
|
+
} catch (e) {}
|
|
171518
|
+
}
|
|
171519
|
+
});
|
|
171520
|
+
|
|
171521
|
+
// ../../node_modules/ws/lib/limiter.js
|
|
171522
|
+
var require_limiter = __commonJS(function(exports, module) {
|
|
171523
|
+
var kDone = Symbol("kDone");
|
|
171524
|
+
var kRun = Symbol("kRun");
|
|
171525
|
+
|
|
171526
|
+
class Limiter {
|
|
171527
|
+
constructor(concurrency) {
|
|
171528
|
+
this[kDone] = () => {
|
|
171529
|
+
this.pending--;
|
|
171530
|
+
this[kRun]();
|
|
171531
|
+
};
|
|
171532
|
+
this.concurrency = concurrency || Infinity;
|
|
171533
|
+
this.jobs = [];
|
|
171534
|
+
this.pending = 0;
|
|
171535
|
+
}
|
|
171536
|
+
add(job) {
|
|
171537
|
+
this.jobs.push(job);
|
|
171538
|
+
this[kRun]();
|
|
171539
|
+
}
|
|
171540
|
+
[kRun]() {
|
|
171541
|
+
if (this.pending === this.concurrency)
|
|
171542
|
+
return;
|
|
171543
|
+
if (this.jobs.length) {
|
|
171544
|
+
const job = this.jobs.shift();
|
|
171545
|
+
this.pending++;
|
|
171546
|
+
job(this[kDone]);
|
|
171547
|
+
}
|
|
171548
|
+
}
|
|
171549
|
+
}
|
|
171550
|
+
module.exports = Limiter;
|
|
171551
|
+
});
|
|
171552
|
+
|
|
171553
|
+
// ../../node_modules/ws/lib/permessage-deflate.js
|
|
171554
|
+
var require_permessage_deflate = __commonJS(function(exports, module) {
|
|
171555
|
+
var zlib = __require("zlib");
|
|
171556
|
+
var bufferUtil = require_buffer_util();
|
|
171557
|
+
var Limiter = require_limiter();
|
|
171558
|
+
var { kStatusCode } = require_constants6();
|
|
171559
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
171560
|
+
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
171561
|
+
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
171562
|
+
var kTotalLength = Symbol("total-length");
|
|
171563
|
+
var kCallback = Symbol("callback");
|
|
171564
|
+
var kBuffers = Symbol("buffers");
|
|
171565
|
+
var kError = Symbol("error");
|
|
171566
|
+
var zlibLimiter;
|
|
171567
|
+
|
|
171568
|
+
class PerMessageDeflate {
|
|
171569
|
+
constructor(options) {
|
|
171570
|
+
this._options = options || {};
|
|
171571
|
+
this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
171572
|
+
this._maxPayload = this._options.maxPayload | 0;
|
|
171573
|
+
this._isServer = !!this._options.isServer;
|
|
171574
|
+
this._deflate = null;
|
|
171575
|
+
this._inflate = null;
|
|
171576
|
+
this.params = null;
|
|
171577
|
+
if (!zlibLimiter) {
|
|
171578
|
+
const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
|
|
171579
|
+
zlibLimiter = new Limiter(concurrency);
|
|
171580
|
+
}
|
|
171581
|
+
}
|
|
171582
|
+
static get extensionName() {
|
|
171583
|
+
return "permessage-deflate";
|
|
171584
|
+
}
|
|
171585
|
+
offer() {
|
|
171586
|
+
const params = {};
|
|
171587
|
+
if (this._options.serverNoContextTakeover) {
|
|
171588
|
+
params.server_no_context_takeover = true;
|
|
171589
|
+
}
|
|
171590
|
+
if (this._options.clientNoContextTakeover) {
|
|
171591
|
+
params.client_no_context_takeover = true;
|
|
171592
|
+
}
|
|
171593
|
+
if (this._options.serverMaxWindowBits) {
|
|
171594
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
171595
|
+
}
|
|
171596
|
+
if (this._options.clientMaxWindowBits) {
|
|
171597
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
171598
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
171599
|
+
params.client_max_window_bits = true;
|
|
171600
|
+
}
|
|
171601
|
+
return params;
|
|
171602
|
+
}
|
|
171603
|
+
accept(configurations) {
|
|
171604
|
+
configurations = this.normalizeParams(configurations);
|
|
171605
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
171606
|
+
return this.params;
|
|
171607
|
+
}
|
|
171608
|
+
cleanup() {
|
|
171609
|
+
if (this._inflate) {
|
|
171610
|
+
this._inflate.close();
|
|
171611
|
+
this._inflate = null;
|
|
171612
|
+
}
|
|
171613
|
+
if (this._deflate) {
|
|
171614
|
+
const callback = this._deflate[kCallback];
|
|
171615
|
+
this._deflate.close();
|
|
171616
|
+
this._deflate = null;
|
|
171617
|
+
if (callback) {
|
|
171618
|
+
callback(new Error("The deflate stream was closed while data was being processed"));
|
|
171619
|
+
}
|
|
171620
|
+
}
|
|
171621
|
+
}
|
|
171622
|
+
acceptAsServer(offers) {
|
|
171623
|
+
const opts = this._options;
|
|
171624
|
+
const accepted = offers.find((params) => {
|
|
171625
|
+
if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
|
|
171626
|
+
return false;
|
|
171627
|
+
}
|
|
171628
|
+
return true;
|
|
171629
|
+
});
|
|
171630
|
+
if (!accepted) {
|
|
171631
|
+
throw new Error("None of the extension offers can be accepted");
|
|
171632
|
+
}
|
|
171633
|
+
if (opts.serverNoContextTakeover) {
|
|
171634
|
+
accepted.server_no_context_takeover = true;
|
|
171635
|
+
}
|
|
171636
|
+
if (opts.clientNoContextTakeover) {
|
|
171637
|
+
accepted.client_no_context_takeover = true;
|
|
171638
|
+
}
|
|
171639
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
171640
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
171641
|
+
}
|
|
171642
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
171643
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
171644
|
+
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
171645
|
+
delete accepted.client_max_window_bits;
|
|
171646
|
+
}
|
|
171647
|
+
return accepted;
|
|
171648
|
+
}
|
|
171649
|
+
acceptAsClient(response) {
|
|
171650
|
+
const params = response[0];
|
|
171651
|
+
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
171652
|
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
171653
|
+
}
|
|
171654
|
+
if (!params.client_max_window_bits) {
|
|
171655
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
171656
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
171657
|
+
}
|
|
171658
|
+
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
171659
|
+
throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
171660
|
+
}
|
|
171661
|
+
return params;
|
|
171662
|
+
}
|
|
171663
|
+
normalizeParams(configurations) {
|
|
171664
|
+
configurations.forEach((params) => {
|
|
171665
|
+
Object.keys(params).forEach((key) => {
|
|
171666
|
+
let value = params[key];
|
|
171667
|
+
if (value.length > 1) {
|
|
171668
|
+
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
171669
|
+
}
|
|
171670
|
+
value = value[0];
|
|
171671
|
+
if (key === "client_max_window_bits") {
|
|
171672
|
+
if (value !== true) {
|
|
171673
|
+
const num = +value;
|
|
171674
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
171675
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171676
|
+
}
|
|
171677
|
+
value = num;
|
|
171678
|
+
} else if (!this._isServer) {
|
|
171679
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171680
|
+
}
|
|
171681
|
+
} else if (key === "server_max_window_bits") {
|
|
171682
|
+
const num = +value;
|
|
171683
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
171684
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171685
|
+
}
|
|
171686
|
+
value = num;
|
|
171687
|
+
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
171688
|
+
if (value !== true) {
|
|
171689
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171690
|
+
}
|
|
171691
|
+
} else {
|
|
171692
|
+
throw new Error(`Unknown parameter "${key}"`);
|
|
171693
|
+
}
|
|
171694
|
+
params[key] = value;
|
|
171695
|
+
});
|
|
171696
|
+
});
|
|
171697
|
+
return configurations;
|
|
171698
|
+
}
|
|
171699
|
+
decompress(data, fin, callback) {
|
|
171700
|
+
zlibLimiter.add((done) => {
|
|
171701
|
+
this._decompress(data, fin, (err, result) => {
|
|
171702
|
+
done();
|
|
171703
|
+
callback(err, result);
|
|
171704
|
+
});
|
|
171705
|
+
});
|
|
171706
|
+
}
|
|
171707
|
+
compress(data, fin, callback) {
|
|
171708
|
+
zlibLimiter.add((done) => {
|
|
171709
|
+
this._compress(data, fin, (err, result) => {
|
|
171710
|
+
done();
|
|
171711
|
+
callback(err, result);
|
|
171712
|
+
});
|
|
171713
|
+
});
|
|
171714
|
+
}
|
|
171715
|
+
_decompress(data, fin, callback) {
|
|
171716
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
171717
|
+
if (!this._inflate) {
|
|
171718
|
+
const key = `${endpoint}_max_window_bits`;
|
|
171719
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
171720
|
+
this._inflate = zlib.createInflateRaw({
|
|
171721
|
+
...this._options.zlibInflateOptions,
|
|
171722
|
+
windowBits
|
|
171723
|
+
});
|
|
171724
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
171725
|
+
this._inflate[kTotalLength] = 0;
|
|
171726
|
+
this._inflate[kBuffers] = [];
|
|
171727
|
+
this._inflate.on("error", inflateOnError);
|
|
171728
|
+
this._inflate.on("data", inflateOnData);
|
|
171729
|
+
}
|
|
171730
|
+
this._inflate[kCallback] = callback;
|
|
171731
|
+
this._inflate.write(data);
|
|
171732
|
+
if (fin)
|
|
171733
|
+
this._inflate.write(TRAILER);
|
|
171734
|
+
this._inflate.flush(() => {
|
|
171735
|
+
const err = this._inflate[kError];
|
|
171736
|
+
if (err) {
|
|
171737
|
+
this._inflate.close();
|
|
171738
|
+
this._inflate = null;
|
|
171739
|
+
callback(err);
|
|
171740
|
+
return;
|
|
171741
|
+
}
|
|
171742
|
+
const data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
171743
|
+
if (this._inflate._readableState.endEmitted) {
|
|
171744
|
+
this._inflate.close();
|
|
171745
|
+
this._inflate = null;
|
|
171746
|
+
} else {
|
|
171747
|
+
this._inflate[kTotalLength] = 0;
|
|
171748
|
+
this._inflate[kBuffers] = [];
|
|
171749
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
171750
|
+
this._inflate.reset();
|
|
171751
|
+
}
|
|
171752
|
+
}
|
|
171753
|
+
callback(null, data);
|
|
171754
|
+
});
|
|
171755
|
+
}
|
|
171756
|
+
_compress(data, fin, callback) {
|
|
171757
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
171758
|
+
if (!this._deflate) {
|
|
171759
|
+
const key = `${endpoint}_max_window_bits`;
|
|
171760
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
171761
|
+
this._deflate = zlib.createDeflateRaw({
|
|
171762
|
+
...this._options.zlibDeflateOptions,
|
|
171763
|
+
windowBits
|
|
171764
|
+
});
|
|
171765
|
+
this._deflate[kTotalLength] = 0;
|
|
171766
|
+
this._deflate[kBuffers] = [];
|
|
171767
|
+
this._deflate.on("data", deflateOnData);
|
|
171768
|
+
}
|
|
171769
|
+
this._deflate[kCallback] = callback;
|
|
171770
|
+
this._deflate.write(data);
|
|
171771
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
171772
|
+
if (!this._deflate) {
|
|
171773
|
+
return;
|
|
171774
|
+
}
|
|
171775
|
+
let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
171776
|
+
if (fin) {
|
|
171777
|
+
data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
|
|
171778
|
+
}
|
|
171779
|
+
this._deflate[kCallback] = null;
|
|
171780
|
+
this._deflate[kTotalLength] = 0;
|
|
171781
|
+
this._deflate[kBuffers] = [];
|
|
171782
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
171783
|
+
this._deflate.reset();
|
|
171784
|
+
}
|
|
171785
|
+
callback(null, data);
|
|
171786
|
+
});
|
|
171787
|
+
}
|
|
171788
|
+
}
|
|
171789
|
+
module.exports = PerMessageDeflate;
|
|
171790
|
+
function deflateOnData(chunk) {
|
|
171791
|
+
this[kBuffers].push(chunk);
|
|
171792
|
+
this[kTotalLength] += chunk.length;
|
|
171793
|
+
}
|
|
171794
|
+
function inflateOnData(chunk) {
|
|
171795
|
+
this[kTotalLength] += chunk.length;
|
|
171796
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
171797
|
+
this[kBuffers].push(chunk);
|
|
171798
|
+
return;
|
|
171799
|
+
}
|
|
171800
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
171801
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
171802
|
+
this[kError][kStatusCode] = 1009;
|
|
171803
|
+
this.removeListener("data", inflateOnData);
|
|
171804
|
+
this.reset();
|
|
171805
|
+
}
|
|
171806
|
+
function inflateOnError(err) {
|
|
171807
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
171808
|
+
if (this[kError]) {
|
|
171809
|
+
this[kCallback](this[kError]);
|
|
171810
|
+
return;
|
|
171811
|
+
}
|
|
171812
|
+
err[kStatusCode] = 1007;
|
|
171813
|
+
this[kCallback](err);
|
|
171814
|
+
}
|
|
171815
|
+
});
|
|
171816
|
+
|
|
171817
|
+
// ../../node_modules/ws/lib/validation.js
|
|
171818
|
+
var require_validation = __commonJS(function(exports, module) {
|
|
171819
|
+
var { isUtf8 } = __require("buffer");
|
|
171820
|
+
var { hasBlob } = require_constants6();
|
|
171821
|
+
var tokenChars = [
|
|
171822
|
+
0,
|
|
171823
|
+
0,
|
|
171824
|
+
0,
|
|
171825
|
+
0,
|
|
171826
|
+
0,
|
|
171827
|
+
0,
|
|
171828
|
+
0,
|
|
171829
|
+
0,
|
|
171830
|
+
0,
|
|
171831
|
+
0,
|
|
171832
|
+
0,
|
|
171833
|
+
0,
|
|
171834
|
+
0,
|
|
171835
|
+
0,
|
|
171836
|
+
0,
|
|
171837
|
+
0,
|
|
171838
|
+
0,
|
|
171839
|
+
0,
|
|
171840
|
+
0,
|
|
171841
|
+
0,
|
|
171842
|
+
0,
|
|
171843
|
+
0,
|
|
171844
|
+
0,
|
|
171845
|
+
0,
|
|
171846
|
+
0,
|
|
171847
|
+
0,
|
|
171848
|
+
0,
|
|
171849
|
+
0,
|
|
171850
|
+
0,
|
|
171851
|
+
0,
|
|
171852
|
+
0,
|
|
171853
|
+
0,
|
|
171854
|
+
0,
|
|
171855
|
+
1,
|
|
171856
|
+
0,
|
|
171857
|
+
1,
|
|
171858
|
+
1,
|
|
171859
|
+
1,
|
|
171860
|
+
1,
|
|
171861
|
+
1,
|
|
171862
|
+
0,
|
|
171863
|
+
0,
|
|
171864
|
+
1,
|
|
171865
|
+
1,
|
|
171866
|
+
0,
|
|
171867
|
+
1,
|
|
171868
|
+
1,
|
|
171869
|
+
0,
|
|
171870
|
+
1,
|
|
171871
|
+
1,
|
|
171872
|
+
1,
|
|
171873
|
+
1,
|
|
171874
|
+
1,
|
|
171875
|
+
1,
|
|
171876
|
+
1,
|
|
171877
|
+
1,
|
|
171878
|
+
1,
|
|
171879
|
+
1,
|
|
171880
|
+
0,
|
|
171881
|
+
0,
|
|
171882
|
+
0,
|
|
171883
|
+
0,
|
|
171884
|
+
0,
|
|
171885
|
+
0,
|
|
171886
|
+
0,
|
|
171887
|
+
1,
|
|
171888
|
+
1,
|
|
171889
|
+
1,
|
|
171890
|
+
1,
|
|
171891
|
+
1,
|
|
171892
|
+
1,
|
|
171893
|
+
1,
|
|
171894
|
+
1,
|
|
171895
|
+
1,
|
|
171896
|
+
1,
|
|
171897
|
+
1,
|
|
171898
|
+
1,
|
|
171899
|
+
1,
|
|
171900
|
+
1,
|
|
171901
|
+
1,
|
|
171902
|
+
1,
|
|
171903
|
+
1,
|
|
171904
|
+
1,
|
|
171905
|
+
1,
|
|
171906
|
+
1,
|
|
171907
|
+
1,
|
|
171908
|
+
1,
|
|
171909
|
+
1,
|
|
171910
|
+
1,
|
|
171911
|
+
1,
|
|
171912
|
+
1,
|
|
171913
|
+
0,
|
|
171914
|
+
0,
|
|
171915
|
+
0,
|
|
171916
|
+
1,
|
|
171917
|
+
1,
|
|
171918
|
+
1,
|
|
171919
|
+
1,
|
|
171920
|
+
1,
|
|
171921
|
+
1,
|
|
171922
|
+
1,
|
|
171923
|
+
1,
|
|
171924
|
+
1,
|
|
171925
|
+
1,
|
|
171926
|
+
1,
|
|
171927
|
+
1,
|
|
171928
|
+
1,
|
|
171929
|
+
1,
|
|
171930
|
+
1,
|
|
171931
|
+
1,
|
|
171932
|
+
1,
|
|
171933
|
+
1,
|
|
171934
|
+
1,
|
|
171935
|
+
1,
|
|
171936
|
+
1,
|
|
171937
|
+
1,
|
|
171938
|
+
1,
|
|
171939
|
+
1,
|
|
171940
|
+
1,
|
|
171941
|
+
1,
|
|
171942
|
+
1,
|
|
171943
|
+
1,
|
|
171944
|
+
1,
|
|
171945
|
+
0,
|
|
171946
|
+
1,
|
|
171947
|
+
0,
|
|
171948
|
+
1,
|
|
171949
|
+
0
|
|
171950
|
+
];
|
|
171951
|
+
function isValidStatusCode(code) {
|
|
171952
|
+
return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
171953
|
+
}
|
|
171954
|
+
function _isValidUTF8(buf) {
|
|
171955
|
+
const len = buf.length;
|
|
171956
|
+
let i = 0;
|
|
171957
|
+
while (i < len) {
|
|
171958
|
+
if ((buf[i] & 128) === 0) {
|
|
171959
|
+
i++;
|
|
171960
|
+
} else if ((buf[i] & 224) === 192) {
|
|
171961
|
+
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
171962
|
+
return false;
|
|
171963
|
+
}
|
|
171964
|
+
i += 2;
|
|
171965
|
+
} else if ((buf[i] & 240) === 224) {
|
|
171966
|
+
if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) {
|
|
171967
|
+
return false;
|
|
171968
|
+
}
|
|
171969
|
+
i += 3;
|
|
171970
|
+
} else if ((buf[i] & 248) === 240) {
|
|
171971
|
+
if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
|
|
171972
|
+
return false;
|
|
171973
|
+
}
|
|
171974
|
+
i += 4;
|
|
171975
|
+
} else {
|
|
171976
|
+
return false;
|
|
171977
|
+
}
|
|
171978
|
+
}
|
|
171979
|
+
return true;
|
|
171980
|
+
}
|
|
171981
|
+
function isBlob(value) {
|
|
171982
|
+
return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
|
|
171983
|
+
}
|
|
171984
|
+
module.exports = {
|
|
171985
|
+
isBlob,
|
|
171986
|
+
isValidStatusCode,
|
|
171987
|
+
isValidUTF8: _isValidUTF8,
|
|
171988
|
+
tokenChars
|
|
171989
|
+
};
|
|
171990
|
+
if (isUtf8) {
|
|
171991
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
171992
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
171993
|
+
};
|
|
171994
|
+
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
171995
|
+
try {
|
|
171996
|
+
const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
|
|
171997
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
171998
|
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
171999
|
+
};
|
|
172000
|
+
} catch (e) {}
|
|
172001
|
+
}
|
|
172002
|
+
});
|
|
172003
|
+
|
|
172004
|
+
// ../../node_modules/ws/lib/receiver.js
|
|
172005
|
+
var require_receiver = __commonJS(function(exports, module) {
|
|
172006
|
+
var { Writable } = __require("stream");
|
|
172007
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
172008
|
+
var {
|
|
172009
|
+
BINARY_TYPES,
|
|
172010
|
+
EMPTY_BUFFER,
|
|
172011
|
+
kStatusCode,
|
|
172012
|
+
kWebSocket
|
|
172013
|
+
} = require_constants6();
|
|
172014
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
172015
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
172016
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
172017
|
+
var GET_INFO = 0;
|
|
172018
|
+
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
172019
|
+
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
172020
|
+
var GET_MASK = 3;
|
|
172021
|
+
var GET_DATA = 4;
|
|
172022
|
+
var INFLATING = 5;
|
|
172023
|
+
var DEFER_EVENT = 6;
|
|
172024
|
+
|
|
172025
|
+
class Receiver extends Writable {
|
|
172026
|
+
constructor(options = {}) {
|
|
172027
|
+
super();
|
|
172028
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
|
|
172029
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
172030
|
+
this._extensions = options.extensions || {};
|
|
172031
|
+
this._isServer = !!options.isServer;
|
|
172032
|
+
this._maxBufferedChunks = options.maxBufferedChunks | 0;
|
|
172033
|
+
this._maxFragments = options.maxFragments | 0;
|
|
172034
|
+
this._maxPayload = options.maxPayload | 0;
|
|
172035
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
172036
|
+
this[kWebSocket] = undefined;
|
|
172037
|
+
this._bufferedBytes = 0;
|
|
172038
|
+
this._buffers = [];
|
|
172039
|
+
this._compressed = false;
|
|
172040
|
+
this._payloadLength = 0;
|
|
172041
|
+
this._mask = undefined;
|
|
172042
|
+
this._fragmented = 0;
|
|
172043
|
+
this._masked = false;
|
|
172044
|
+
this._fin = false;
|
|
172045
|
+
this._opcode = 0;
|
|
172046
|
+
this._totalPayloadLength = 0;
|
|
172047
|
+
this._messageLength = 0;
|
|
172048
|
+
this._fragments = [];
|
|
172049
|
+
this._errored = false;
|
|
172050
|
+
this._loop = false;
|
|
172051
|
+
this._state = GET_INFO;
|
|
172052
|
+
}
|
|
172053
|
+
_write(chunk, encoding, cb) {
|
|
172054
|
+
if (this._opcode === 8 && this._state == GET_INFO)
|
|
172055
|
+
return cb();
|
|
172056
|
+
if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
|
|
172057
|
+
cb(this.createError(RangeError, "Too many buffered chunks", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
172058
|
+
return;
|
|
172059
|
+
}
|
|
172060
|
+
this._bufferedBytes += chunk.length;
|
|
172061
|
+
this._buffers.push(chunk);
|
|
172062
|
+
this.startLoop(cb);
|
|
172063
|
+
}
|
|
172064
|
+
consume(n) {
|
|
172065
|
+
this._bufferedBytes -= n;
|
|
172066
|
+
if (n === this._buffers[0].length)
|
|
172067
|
+
return this._buffers.shift();
|
|
172068
|
+
if (n < this._buffers[0].length) {
|
|
172069
|
+
const buf = this._buffers[0];
|
|
172070
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
172071
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
172072
|
+
}
|
|
172073
|
+
const dst = Buffer.allocUnsafe(n);
|
|
172074
|
+
do {
|
|
172075
|
+
const buf = this._buffers[0];
|
|
172076
|
+
const offset = dst.length - n;
|
|
172077
|
+
if (n >= buf.length) {
|
|
172078
|
+
dst.set(this._buffers.shift(), offset);
|
|
172079
|
+
} else {
|
|
172080
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
172081
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
172082
|
+
}
|
|
172083
|
+
n -= buf.length;
|
|
172084
|
+
} while (n > 0);
|
|
172085
|
+
return dst;
|
|
172086
|
+
}
|
|
172087
|
+
startLoop(cb) {
|
|
172088
|
+
this._loop = true;
|
|
172089
|
+
do {
|
|
172090
|
+
switch (this._state) {
|
|
172091
|
+
case GET_INFO:
|
|
172092
|
+
this.getInfo(cb);
|
|
172093
|
+
break;
|
|
172094
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
172095
|
+
this.getPayloadLength16(cb);
|
|
172096
|
+
break;
|
|
172097
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
172098
|
+
this.getPayloadLength64(cb);
|
|
172099
|
+
break;
|
|
172100
|
+
case GET_MASK:
|
|
172101
|
+
this.getMask();
|
|
172102
|
+
break;
|
|
172103
|
+
case GET_DATA:
|
|
172104
|
+
this.getData(cb);
|
|
172105
|
+
break;
|
|
172106
|
+
case INFLATING:
|
|
172107
|
+
case DEFER_EVENT:
|
|
172108
|
+
this._loop = false;
|
|
172109
|
+
return;
|
|
172110
|
+
}
|
|
172111
|
+
} while (this._loop);
|
|
172112
|
+
if (!this._errored)
|
|
172113
|
+
cb();
|
|
172114
|
+
}
|
|
172115
|
+
getInfo(cb) {
|
|
172116
|
+
if (this._bufferedBytes < 2) {
|
|
172117
|
+
this._loop = false;
|
|
172118
|
+
return;
|
|
172119
|
+
}
|
|
172120
|
+
const buf = this.consume(2);
|
|
172121
|
+
if ((buf[0] & 48) !== 0) {
|
|
172122
|
+
const error = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
|
|
172123
|
+
cb(error);
|
|
172124
|
+
return;
|
|
172125
|
+
}
|
|
172126
|
+
const compressed = (buf[0] & 64) === 64;
|
|
172127
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
172128
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
172129
|
+
cb(error);
|
|
172130
|
+
return;
|
|
172131
|
+
}
|
|
172132
|
+
this._fin = (buf[0] & 128) === 128;
|
|
172133
|
+
this._opcode = buf[0] & 15;
|
|
172134
|
+
this._payloadLength = buf[1] & 127;
|
|
172135
|
+
if (this._opcode === 0) {
|
|
172136
|
+
if (compressed) {
|
|
172137
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
172138
|
+
cb(error);
|
|
172139
|
+
return;
|
|
172140
|
+
}
|
|
172141
|
+
if (!this._fragmented) {
|
|
172142
|
+
const error = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
172143
|
+
cb(error);
|
|
172144
|
+
return;
|
|
172145
|
+
}
|
|
172146
|
+
this._opcode = this._fragmented;
|
|
172147
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
172148
|
+
if (this._fragmented) {
|
|
172149
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
172150
|
+
cb(error);
|
|
172151
|
+
return;
|
|
172152
|
+
}
|
|
172153
|
+
this._compressed = compressed;
|
|
172154
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
172155
|
+
if (!this._fin) {
|
|
172156
|
+
const error = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
|
|
172157
|
+
cb(error);
|
|
172158
|
+
return;
|
|
172159
|
+
}
|
|
172160
|
+
if (compressed) {
|
|
172161
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
172162
|
+
cb(error);
|
|
172163
|
+
return;
|
|
172164
|
+
}
|
|
172165
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
172166
|
+
const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
|
|
172167
|
+
cb(error);
|
|
172168
|
+
return;
|
|
172169
|
+
}
|
|
172170
|
+
} else {
|
|
172171
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
172172
|
+
cb(error);
|
|
172173
|
+
return;
|
|
172174
|
+
}
|
|
172175
|
+
if (!this._fin && !this._fragmented)
|
|
172176
|
+
this._fragmented = this._opcode;
|
|
172177
|
+
this._masked = (buf[1] & 128) === 128;
|
|
172178
|
+
if (this._isServer) {
|
|
172179
|
+
if (!this._masked) {
|
|
172180
|
+
const error = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
|
|
172181
|
+
cb(error);
|
|
172182
|
+
return;
|
|
172183
|
+
}
|
|
172184
|
+
} else if (this._masked) {
|
|
172185
|
+
const error = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
|
|
172186
|
+
cb(error);
|
|
172187
|
+
return;
|
|
172188
|
+
}
|
|
172189
|
+
if (this._payloadLength === 126)
|
|
172190
|
+
this._state = GET_PAYLOAD_LENGTH_16;
|
|
172191
|
+
else if (this._payloadLength === 127)
|
|
172192
|
+
this._state = GET_PAYLOAD_LENGTH_64;
|
|
172193
|
+
else
|
|
172194
|
+
this.haveLength(cb);
|
|
172195
|
+
}
|
|
172196
|
+
getPayloadLength16(cb) {
|
|
172197
|
+
if (this._bufferedBytes < 2) {
|
|
172198
|
+
this._loop = false;
|
|
172199
|
+
return;
|
|
172200
|
+
}
|
|
172201
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
172202
|
+
this.haveLength(cb);
|
|
172203
|
+
}
|
|
172204
|
+
getPayloadLength64(cb) {
|
|
172205
|
+
if (this._bufferedBytes < 8) {
|
|
172206
|
+
this._loop = false;
|
|
172207
|
+
return;
|
|
172208
|
+
}
|
|
172209
|
+
const buf = this.consume(8);
|
|
172210
|
+
const num = buf.readUInt32BE(0);
|
|
172211
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
172212
|
+
const error = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
|
|
172213
|
+
cb(error);
|
|
172214
|
+
return;
|
|
172215
|
+
}
|
|
172216
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
172217
|
+
this.haveLength(cb);
|
|
172218
|
+
}
|
|
172219
|
+
haveLength(cb) {
|
|
172220
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
172221
|
+
this._totalPayloadLength += this._payloadLength;
|
|
172222
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
172223
|
+
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
172224
|
+
cb(error);
|
|
172225
|
+
return;
|
|
172226
|
+
}
|
|
172227
|
+
}
|
|
172228
|
+
if (this._masked)
|
|
172229
|
+
this._state = GET_MASK;
|
|
172230
|
+
else
|
|
172231
|
+
this._state = GET_DATA;
|
|
172232
|
+
}
|
|
172233
|
+
getMask() {
|
|
172234
|
+
if (this._bufferedBytes < 4) {
|
|
172235
|
+
this._loop = false;
|
|
172236
|
+
return;
|
|
172237
|
+
}
|
|
172238
|
+
this._mask = this.consume(4);
|
|
172239
|
+
this._state = GET_DATA;
|
|
172240
|
+
}
|
|
172241
|
+
getData(cb) {
|
|
172242
|
+
let data = EMPTY_BUFFER;
|
|
172243
|
+
if (this._payloadLength) {
|
|
172244
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
172245
|
+
this._loop = false;
|
|
172246
|
+
return;
|
|
172247
|
+
}
|
|
172248
|
+
data = this.consume(this._payloadLength);
|
|
172249
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
172250
|
+
unmask(data, this._mask);
|
|
172251
|
+
}
|
|
172252
|
+
}
|
|
172253
|
+
if (this._opcode > 7) {
|
|
172254
|
+
this.controlMessage(data, cb);
|
|
172255
|
+
return;
|
|
172256
|
+
}
|
|
172257
|
+
if (this._compressed) {
|
|
172258
|
+
this._state = INFLATING;
|
|
172259
|
+
this.decompress(data, cb);
|
|
172260
|
+
return;
|
|
172261
|
+
}
|
|
172262
|
+
if (data.length) {
|
|
172263
|
+
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
172264
|
+
const error = this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS");
|
|
172265
|
+
cb(error);
|
|
172266
|
+
return;
|
|
172267
|
+
}
|
|
172268
|
+
this._messageLength = this._totalPayloadLength;
|
|
172269
|
+
this._fragments.push(data);
|
|
172270
|
+
}
|
|
172271
|
+
this.dataMessage(cb);
|
|
172272
|
+
}
|
|
172273
|
+
decompress(data, cb) {
|
|
172274
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
172275
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
172276
|
+
if (err)
|
|
172277
|
+
return cb(err);
|
|
172278
|
+
if (buf.length) {
|
|
172279
|
+
this._messageLength += buf.length;
|
|
172280
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
172281
|
+
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
172282
|
+
cb(error);
|
|
172283
|
+
return;
|
|
172284
|
+
}
|
|
172285
|
+
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
172286
|
+
const error = this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS");
|
|
172287
|
+
cb(error);
|
|
172288
|
+
return;
|
|
172289
|
+
}
|
|
172290
|
+
this._fragments.push(buf);
|
|
172291
|
+
}
|
|
172292
|
+
this.dataMessage(cb);
|
|
172293
|
+
if (this._state === GET_INFO)
|
|
172294
|
+
this.startLoop(cb);
|
|
172295
|
+
});
|
|
172296
|
+
}
|
|
172297
|
+
dataMessage(cb) {
|
|
172298
|
+
if (!this._fin) {
|
|
172299
|
+
this._state = GET_INFO;
|
|
172300
|
+
return;
|
|
172301
|
+
}
|
|
172302
|
+
const messageLength = this._messageLength;
|
|
172303
|
+
const fragments = this._fragments;
|
|
172304
|
+
this._totalPayloadLength = 0;
|
|
172305
|
+
this._messageLength = 0;
|
|
172306
|
+
this._fragmented = 0;
|
|
172307
|
+
this._fragments = [];
|
|
172308
|
+
if (this._opcode === 2) {
|
|
172309
|
+
let data;
|
|
172310
|
+
if (this._binaryType === "nodebuffer") {
|
|
172311
|
+
data = concat(fragments, messageLength);
|
|
172312
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
172313
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
172314
|
+
} else if (this._binaryType === "blob") {
|
|
172315
|
+
data = new Blob(fragments);
|
|
172316
|
+
} else {
|
|
172317
|
+
data = fragments;
|
|
172318
|
+
}
|
|
172319
|
+
if (this._allowSynchronousEvents) {
|
|
172320
|
+
this.emit("message", data, true);
|
|
172321
|
+
this._state = GET_INFO;
|
|
172322
|
+
} else {
|
|
172323
|
+
this._state = DEFER_EVENT;
|
|
172324
|
+
setImmediate(() => {
|
|
172325
|
+
this.emit("message", data, true);
|
|
172326
|
+
this._state = GET_INFO;
|
|
172327
|
+
this.startLoop(cb);
|
|
172328
|
+
});
|
|
172329
|
+
}
|
|
172330
|
+
} else {
|
|
172331
|
+
const buf = concat(fragments, messageLength);
|
|
172332
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
172333
|
+
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
172334
|
+
cb(error);
|
|
172335
|
+
return;
|
|
172336
|
+
}
|
|
172337
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
172338
|
+
this.emit("message", buf, false);
|
|
172339
|
+
this._state = GET_INFO;
|
|
172340
|
+
} else {
|
|
172341
|
+
this._state = DEFER_EVENT;
|
|
172342
|
+
setImmediate(() => {
|
|
172343
|
+
this.emit("message", buf, false);
|
|
172344
|
+
this._state = GET_INFO;
|
|
172345
|
+
this.startLoop(cb);
|
|
172346
|
+
});
|
|
172347
|
+
}
|
|
172348
|
+
}
|
|
172349
|
+
}
|
|
172350
|
+
controlMessage(data, cb) {
|
|
172351
|
+
if (this._opcode === 8) {
|
|
172352
|
+
if (data.length === 0) {
|
|
172353
|
+
this._loop = false;
|
|
172354
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
172355
|
+
this.end();
|
|
172356
|
+
} else {
|
|
172357
|
+
const code = data.readUInt16BE(0);
|
|
172358
|
+
if (!isValidStatusCode(code)) {
|
|
172359
|
+
const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
|
|
172360
|
+
cb(error);
|
|
172361
|
+
return;
|
|
172362
|
+
}
|
|
172363
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
172364
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
172365
|
+
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
172366
|
+
cb(error);
|
|
172367
|
+
return;
|
|
172368
|
+
}
|
|
172369
|
+
this._loop = false;
|
|
172370
|
+
this.emit("conclude", code, buf);
|
|
172371
|
+
this.end();
|
|
172372
|
+
}
|
|
172373
|
+
this._state = GET_INFO;
|
|
172374
|
+
return;
|
|
172375
|
+
}
|
|
172376
|
+
if (this._allowSynchronousEvents) {
|
|
172377
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
172378
|
+
this._state = GET_INFO;
|
|
172379
|
+
} else {
|
|
172380
|
+
this._state = DEFER_EVENT;
|
|
172381
|
+
setImmediate(() => {
|
|
172382
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
172383
|
+
this._state = GET_INFO;
|
|
172384
|
+
this.startLoop(cb);
|
|
172385
|
+
});
|
|
172386
|
+
}
|
|
172387
|
+
}
|
|
172388
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
172389
|
+
this._loop = false;
|
|
172390
|
+
this._errored = true;
|
|
172391
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
172392
|
+
Error.captureStackTrace(err, this.createError);
|
|
172393
|
+
err.code = errorCode;
|
|
172394
|
+
err[kStatusCode] = statusCode;
|
|
172395
|
+
return err;
|
|
172396
|
+
}
|
|
172397
|
+
}
|
|
172398
|
+
module.exports = Receiver;
|
|
172399
|
+
});
|
|
172400
|
+
|
|
172401
|
+
// ../../node_modules/ws/lib/sender.js
|
|
172402
|
+
var require_sender = __commonJS(function(exports, module) {
|
|
172403
|
+
var { Duplex } = __require("stream");
|
|
172404
|
+
var { randomFillSync } = __require("crypto");
|
|
172405
|
+
var {
|
|
172406
|
+
types: { isUint8Array }
|
|
172407
|
+
} = __require("util");
|
|
172408
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
172409
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants6();
|
|
172410
|
+
var { isBlob, isValidStatusCode } = require_validation();
|
|
172411
|
+
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
172412
|
+
var kByteLength = Symbol("kByteLength");
|
|
172413
|
+
var maskBuffer = Buffer.alloc(4);
|
|
172414
|
+
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
172415
|
+
var randomPool;
|
|
172416
|
+
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
172417
|
+
var DEFAULT = 0;
|
|
172418
|
+
var DEFLATING = 1;
|
|
172419
|
+
var GET_BLOB_DATA = 2;
|
|
172420
|
+
|
|
172421
|
+
class Sender {
|
|
172422
|
+
constructor(socket, extensions, generateMask) {
|
|
172423
|
+
this._extensions = extensions || {};
|
|
172424
|
+
if (generateMask) {
|
|
172425
|
+
this._generateMask = generateMask;
|
|
172426
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
172427
|
+
}
|
|
172428
|
+
this._socket = socket;
|
|
172429
|
+
this._firstFragment = true;
|
|
172430
|
+
this._compress = false;
|
|
172431
|
+
this._bufferedBytes = 0;
|
|
172432
|
+
this._queue = [];
|
|
172433
|
+
this._state = DEFAULT;
|
|
172434
|
+
this.onerror = NOOP;
|
|
172435
|
+
this[kWebSocket] = undefined;
|
|
172436
|
+
}
|
|
172437
|
+
static frame(data, options) {
|
|
172438
|
+
let mask;
|
|
172439
|
+
let merge = false;
|
|
172440
|
+
let offset = 2;
|
|
172441
|
+
let skipMasking = false;
|
|
172442
|
+
if (options.mask) {
|
|
172443
|
+
mask = options.maskBuffer || maskBuffer;
|
|
172444
|
+
if (options.generateMask) {
|
|
172445
|
+
options.generateMask(mask);
|
|
172446
|
+
} else {
|
|
172447
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
172448
|
+
if (randomPool === undefined) {
|
|
172449
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
172450
|
+
}
|
|
172451
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
172452
|
+
randomPoolPointer = 0;
|
|
172453
|
+
}
|
|
172454
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
172455
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
172456
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
172457
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
172458
|
+
}
|
|
172459
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
172460
|
+
offset = 6;
|
|
172461
|
+
}
|
|
172462
|
+
let dataLength;
|
|
172463
|
+
if (typeof data === "string") {
|
|
172464
|
+
if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
|
|
172465
|
+
dataLength = options[kByteLength];
|
|
172466
|
+
} else {
|
|
172467
|
+
data = Buffer.from(data);
|
|
172468
|
+
dataLength = data.length;
|
|
172469
|
+
}
|
|
172470
|
+
} else {
|
|
172471
|
+
dataLength = data.length;
|
|
172472
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
172473
|
+
}
|
|
172474
|
+
let payloadLength = dataLength;
|
|
172475
|
+
if (dataLength >= 65536) {
|
|
172476
|
+
offset += 8;
|
|
172477
|
+
payloadLength = 127;
|
|
172478
|
+
} else if (dataLength > 125) {
|
|
172479
|
+
offset += 2;
|
|
172480
|
+
payloadLength = 126;
|
|
172481
|
+
}
|
|
172482
|
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
172483
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
172484
|
+
if (options.rsv1)
|
|
172485
|
+
target[0] |= 64;
|
|
172486
|
+
target[1] = payloadLength;
|
|
172487
|
+
if (payloadLength === 126) {
|
|
172488
|
+
target.writeUInt16BE(dataLength, 2);
|
|
172489
|
+
} else if (payloadLength === 127) {
|
|
172490
|
+
target[2] = target[3] = 0;
|
|
172491
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
172492
|
+
}
|
|
172493
|
+
if (!options.mask)
|
|
172494
|
+
return [target, data];
|
|
172495
|
+
target[1] |= 128;
|
|
172496
|
+
target[offset - 4] = mask[0];
|
|
172497
|
+
target[offset - 3] = mask[1];
|
|
172498
|
+
target[offset - 2] = mask[2];
|
|
172499
|
+
target[offset - 1] = mask[3];
|
|
172500
|
+
if (skipMasking)
|
|
172501
|
+
return [target, data];
|
|
172502
|
+
if (merge) {
|
|
172503
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
172504
|
+
return [target];
|
|
172505
|
+
}
|
|
172506
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
172507
|
+
return [target, data];
|
|
172508
|
+
}
|
|
172509
|
+
close(code, data, mask, cb) {
|
|
172510
|
+
let buf;
|
|
172511
|
+
if (code === undefined) {
|
|
172512
|
+
buf = EMPTY_BUFFER;
|
|
172513
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
172514
|
+
throw new TypeError("First argument must be a valid error code number");
|
|
172515
|
+
} else if (data === undefined || !data.length) {
|
|
172516
|
+
buf = Buffer.allocUnsafe(2);
|
|
172517
|
+
buf.writeUInt16BE(code, 0);
|
|
172518
|
+
} else {
|
|
172519
|
+
const length = Buffer.byteLength(data);
|
|
172520
|
+
if (length > 123) {
|
|
172521
|
+
throw new RangeError("The message must not be greater than 123 bytes");
|
|
172522
|
+
}
|
|
172523
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
172524
|
+
buf.writeUInt16BE(code, 0);
|
|
172525
|
+
if (typeof data === "string") {
|
|
172526
|
+
buf.write(data, 2);
|
|
172527
|
+
} else if (isUint8Array(data)) {
|
|
172528
|
+
buf.set(data, 2);
|
|
172529
|
+
} else {
|
|
172530
|
+
throw new TypeError("Second argument must be a string or a Uint8Array");
|
|
172531
|
+
}
|
|
172532
|
+
}
|
|
172533
|
+
const options = {
|
|
172534
|
+
[kByteLength]: buf.length,
|
|
172535
|
+
fin: true,
|
|
172536
|
+
generateMask: this._generateMask,
|
|
172537
|
+
mask,
|
|
172538
|
+
maskBuffer: this._maskBuffer,
|
|
172539
|
+
opcode: 8,
|
|
172540
|
+
readOnly: false,
|
|
172541
|
+
rsv1: false
|
|
172542
|
+
};
|
|
172543
|
+
if (this._state !== DEFAULT) {
|
|
172544
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
172545
|
+
} else {
|
|
172546
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
172547
|
+
}
|
|
172548
|
+
}
|
|
172549
|
+
ping(data, mask, cb) {
|
|
172550
|
+
let byteLength;
|
|
172551
|
+
let readOnly;
|
|
172552
|
+
if (typeof data === "string") {
|
|
172553
|
+
byteLength = Buffer.byteLength(data);
|
|
172554
|
+
readOnly = false;
|
|
172555
|
+
} else if (isBlob(data)) {
|
|
172556
|
+
byteLength = data.size;
|
|
172557
|
+
readOnly = false;
|
|
172558
|
+
} else {
|
|
172559
|
+
data = toBuffer(data);
|
|
172560
|
+
byteLength = data.length;
|
|
172561
|
+
readOnly = toBuffer.readOnly;
|
|
172562
|
+
}
|
|
172563
|
+
if (byteLength > 125) {
|
|
172564
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
172565
|
+
}
|
|
172566
|
+
const options = {
|
|
172567
|
+
[kByteLength]: byteLength,
|
|
172568
|
+
fin: true,
|
|
172569
|
+
generateMask: this._generateMask,
|
|
172570
|
+
mask,
|
|
172571
|
+
maskBuffer: this._maskBuffer,
|
|
172572
|
+
opcode: 9,
|
|
172573
|
+
readOnly,
|
|
172574
|
+
rsv1: false
|
|
172575
|
+
};
|
|
172576
|
+
if (isBlob(data)) {
|
|
172577
|
+
if (this._state !== DEFAULT) {
|
|
172578
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
172579
|
+
} else {
|
|
172580
|
+
this.getBlobData(data, false, options, cb);
|
|
172581
|
+
}
|
|
172582
|
+
} else if (this._state !== DEFAULT) {
|
|
172583
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
172584
|
+
} else {
|
|
172585
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172586
|
+
}
|
|
172587
|
+
}
|
|
172588
|
+
pong(data, mask, cb) {
|
|
172589
|
+
let byteLength;
|
|
172590
|
+
let readOnly;
|
|
172591
|
+
if (typeof data === "string") {
|
|
172592
|
+
byteLength = Buffer.byteLength(data);
|
|
172593
|
+
readOnly = false;
|
|
172594
|
+
} else if (isBlob(data)) {
|
|
172595
|
+
byteLength = data.size;
|
|
172596
|
+
readOnly = false;
|
|
172597
|
+
} else {
|
|
172598
|
+
data = toBuffer(data);
|
|
172599
|
+
byteLength = data.length;
|
|
172600
|
+
readOnly = toBuffer.readOnly;
|
|
172601
|
+
}
|
|
172602
|
+
if (byteLength > 125) {
|
|
172603
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
172604
|
+
}
|
|
172605
|
+
const options = {
|
|
172606
|
+
[kByteLength]: byteLength,
|
|
172607
|
+
fin: true,
|
|
172608
|
+
generateMask: this._generateMask,
|
|
172609
|
+
mask,
|
|
172610
|
+
maskBuffer: this._maskBuffer,
|
|
172611
|
+
opcode: 10,
|
|
172612
|
+
readOnly,
|
|
172613
|
+
rsv1: false
|
|
172614
|
+
};
|
|
172615
|
+
if (isBlob(data)) {
|
|
172616
|
+
if (this._state !== DEFAULT) {
|
|
172617
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
172618
|
+
} else {
|
|
172619
|
+
this.getBlobData(data, false, options, cb);
|
|
172620
|
+
}
|
|
172621
|
+
} else if (this._state !== DEFAULT) {
|
|
172622
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
172623
|
+
} else {
|
|
172624
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172625
|
+
}
|
|
172626
|
+
}
|
|
172627
|
+
send(data, options, cb) {
|
|
172628
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
172629
|
+
let opcode = options.binary ? 2 : 1;
|
|
172630
|
+
let rsv1 = options.compress;
|
|
172631
|
+
let byteLength;
|
|
172632
|
+
let readOnly;
|
|
172633
|
+
if (typeof data === "string") {
|
|
172634
|
+
byteLength = Buffer.byteLength(data);
|
|
172635
|
+
readOnly = false;
|
|
172636
|
+
} else if (isBlob(data)) {
|
|
172637
|
+
byteLength = data.size;
|
|
172638
|
+
readOnly = false;
|
|
172639
|
+
} else {
|
|
172640
|
+
data = toBuffer(data);
|
|
172641
|
+
byteLength = data.length;
|
|
172642
|
+
readOnly = toBuffer.readOnly;
|
|
172643
|
+
}
|
|
172644
|
+
if (this._firstFragment) {
|
|
172645
|
+
this._firstFragment = false;
|
|
172646
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
172647
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
172648
|
+
}
|
|
172649
|
+
this._compress = rsv1;
|
|
172650
|
+
} else {
|
|
172651
|
+
rsv1 = false;
|
|
172652
|
+
opcode = 0;
|
|
172653
|
+
}
|
|
172654
|
+
if (options.fin)
|
|
172655
|
+
this._firstFragment = true;
|
|
172656
|
+
const opts = {
|
|
172657
|
+
[kByteLength]: byteLength,
|
|
172658
|
+
fin: options.fin,
|
|
172659
|
+
generateMask: this._generateMask,
|
|
172660
|
+
mask: options.mask,
|
|
172661
|
+
maskBuffer: this._maskBuffer,
|
|
172662
|
+
opcode,
|
|
172663
|
+
readOnly,
|
|
172664
|
+
rsv1
|
|
172665
|
+
};
|
|
172666
|
+
if (isBlob(data)) {
|
|
172667
|
+
if (this._state !== DEFAULT) {
|
|
172668
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
172669
|
+
} else {
|
|
172670
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
172671
|
+
}
|
|
172672
|
+
} else if (this._state !== DEFAULT) {
|
|
172673
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
172674
|
+
} else {
|
|
172675
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
172676
|
+
}
|
|
172677
|
+
}
|
|
172678
|
+
getBlobData(blob, compress, options, cb) {
|
|
172679
|
+
this._bufferedBytes += options[kByteLength];
|
|
172680
|
+
this._state = GET_BLOB_DATA;
|
|
172681
|
+
blob.arrayBuffer().then((arrayBuffer) => {
|
|
172682
|
+
if (this._socket.destroyed) {
|
|
172683
|
+
const err = new Error("The socket was closed while the blob was being read");
|
|
172684
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
172685
|
+
return;
|
|
172686
|
+
}
|
|
172687
|
+
this._bufferedBytes -= options[kByteLength];
|
|
172688
|
+
const data = toBuffer(arrayBuffer);
|
|
172689
|
+
if (!compress) {
|
|
172690
|
+
this._state = DEFAULT;
|
|
172691
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172692
|
+
this.dequeue();
|
|
172693
|
+
} else {
|
|
172694
|
+
this.dispatch(data, compress, options, cb);
|
|
172695
|
+
}
|
|
172696
|
+
}).catch((err) => {
|
|
172697
|
+
process.nextTick(onError, this, err, cb);
|
|
172698
|
+
});
|
|
172699
|
+
}
|
|
172700
|
+
dispatch(data, compress, options, cb) {
|
|
172701
|
+
if (!compress) {
|
|
172702
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172703
|
+
return;
|
|
172704
|
+
}
|
|
172705
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
172706
|
+
this._bufferedBytes += options[kByteLength];
|
|
172707
|
+
this._state = DEFLATING;
|
|
172708
|
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
172709
|
+
if (this._socket.destroyed) {
|
|
172710
|
+
const err = new Error("The socket was closed while data was being compressed");
|
|
172711
|
+
callCallbacks(this, err, cb);
|
|
172712
|
+
return;
|
|
172713
|
+
}
|
|
172714
|
+
this._bufferedBytes -= options[kByteLength];
|
|
172715
|
+
this._state = DEFAULT;
|
|
172716
|
+
options.readOnly = false;
|
|
172717
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
172718
|
+
this.dequeue();
|
|
172719
|
+
});
|
|
172720
|
+
}
|
|
172721
|
+
dequeue() {
|
|
172722
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
172723
|
+
const params = this._queue.shift();
|
|
172724
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
172725
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
172726
|
+
}
|
|
172727
|
+
}
|
|
172728
|
+
enqueue(params) {
|
|
172729
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
172730
|
+
this._queue.push(params);
|
|
172731
|
+
}
|
|
172732
|
+
sendFrame(list, cb) {
|
|
172733
|
+
if (list.length === 2) {
|
|
172734
|
+
this._socket.cork();
|
|
172735
|
+
this._socket.write(list[0]);
|
|
172736
|
+
this._socket.write(list[1], cb);
|
|
172737
|
+
this._socket.uncork();
|
|
172738
|
+
} else {
|
|
172739
|
+
this._socket.write(list[0], cb);
|
|
172740
|
+
}
|
|
172741
|
+
}
|
|
172742
|
+
}
|
|
172743
|
+
module.exports = Sender;
|
|
172744
|
+
function callCallbacks(sender, err, cb) {
|
|
172745
|
+
if (typeof cb === "function")
|
|
172746
|
+
cb(err);
|
|
172747
|
+
for (let i = 0;i < sender._queue.length; i++) {
|
|
172748
|
+
const params = sender._queue[i];
|
|
172749
|
+
const callback = params[params.length - 1];
|
|
172750
|
+
if (typeof callback === "function")
|
|
172751
|
+
callback(err);
|
|
172752
|
+
}
|
|
172753
|
+
}
|
|
172754
|
+
function onError(sender, err, cb) {
|
|
172755
|
+
callCallbacks(sender, err, cb);
|
|
172756
|
+
sender.onerror(err);
|
|
172757
|
+
}
|
|
172758
|
+
});
|
|
172759
|
+
|
|
172760
|
+
// ../../node_modules/ws/lib/event-target.js
|
|
172761
|
+
var require_event_target = __commonJS(function(exports, module) {
|
|
172762
|
+
var { kForOnEventAttribute, kListener } = require_constants6();
|
|
172763
|
+
var kCode = Symbol("kCode");
|
|
172764
|
+
var kData = Symbol("kData");
|
|
172765
|
+
var kError = Symbol("kError");
|
|
172766
|
+
var kMessage = Symbol("kMessage");
|
|
172767
|
+
var kReason = Symbol("kReason");
|
|
172768
|
+
var kTarget = Symbol("kTarget");
|
|
172769
|
+
var kType = Symbol("kType");
|
|
172770
|
+
var kWasClean = Symbol("kWasClean");
|
|
172771
|
+
|
|
172772
|
+
class Event2 {
|
|
172773
|
+
constructor(type) {
|
|
172774
|
+
this[kTarget] = null;
|
|
172775
|
+
this[kType] = type;
|
|
172776
|
+
}
|
|
172777
|
+
get target() {
|
|
172778
|
+
return this[kTarget];
|
|
172779
|
+
}
|
|
172780
|
+
get type() {
|
|
172781
|
+
return this[kType];
|
|
172782
|
+
}
|
|
172783
|
+
}
|
|
172784
|
+
Object.defineProperty(Event2.prototype, "target", { enumerable: true });
|
|
172785
|
+
Object.defineProperty(Event2.prototype, "type", { enumerable: true });
|
|
172786
|
+
|
|
172787
|
+
class CloseEvent extends Event2 {
|
|
172788
|
+
constructor(type, options = {}) {
|
|
172789
|
+
super(type);
|
|
172790
|
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
172791
|
+
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
172792
|
+
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
172793
|
+
}
|
|
172794
|
+
get code() {
|
|
172795
|
+
return this[kCode];
|
|
172796
|
+
}
|
|
172797
|
+
get reason() {
|
|
172798
|
+
return this[kReason];
|
|
172799
|
+
}
|
|
172800
|
+
get wasClean() {
|
|
172801
|
+
return this[kWasClean];
|
|
172802
|
+
}
|
|
172803
|
+
}
|
|
172804
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
172805
|
+
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
172806
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
172807
|
+
|
|
172808
|
+
class ErrorEvent extends Event2 {
|
|
172809
|
+
constructor(type, options = {}) {
|
|
172810
|
+
super(type);
|
|
172811
|
+
this[kError] = options.error === undefined ? null : options.error;
|
|
172812
|
+
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
172813
|
+
}
|
|
172814
|
+
get error() {
|
|
172815
|
+
return this[kError];
|
|
172816
|
+
}
|
|
172817
|
+
get message() {
|
|
172818
|
+
return this[kMessage];
|
|
172819
|
+
}
|
|
172820
|
+
}
|
|
172821
|
+
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
172822
|
+
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
172823
|
+
|
|
172824
|
+
class MessageEvent extends Event2 {
|
|
172825
|
+
constructor(type, options = {}) {
|
|
172826
|
+
super(type);
|
|
172827
|
+
this[kData] = options.data === undefined ? null : options.data;
|
|
172828
|
+
}
|
|
172829
|
+
get data() {
|
|
172830
|
+
return this[kData];
|
|
172831
|
+
}
|
|
172832
|
+
}
|
|
172833
|
+
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
172834
|
+
var EventTarget = {
|
|
172835
|
+
addEventListener(type, handler, options = {}) {
|
|
172836
|
+
for (const listener of this.listeners(type)) {
|
|
172837
|
+
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
172838
|
+
return;
|
|
172839
|
+
}
|
|
172840
|
+
}
|
|
172841
|
+
let wrapper;
|
|
172842
|
+
if (type === "message") {
|
|
172843
|
+
wrapper = function onMessage(data, isBinary) {
|
|
172844
|
+
const event = new MessageEvent("message", {
|
|
172845
|
+
data: isBinary ? data : data.toString()
|
|
172846
|
+
});
|
|
172847
|
+
event[kTarget] = this;
|
|
172848
|
+
callListener(handler, this, event);
|
|
172849
|
+
};
|
|
172850
|
+
} else if (type === "close") {
|
|
172851
|
+
wrapper = function onClose(code, message) {
|
|
172852
|
+
const event = new CloseEvent("close", {
|
|
172853
|
+
code,
|
|
172854
|
+
reason: message.toString(),
|
|
172855
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
172856
|
+
});
|
|
172857
|
+
event[kTarget] = this;
|
|
172858
|
+
callListener(handler, this, event);
|
|
172859
|
+
};
|
|
172860
|
+
} else if (type === "error") {
|
|
172861
|
+
wrapper = function onError(error) {
|
|
172862
|
+
const event = new ErrorEvent("error", {
|
|
172863
|
+
error,
|
|
172864
|
+
message: error.message
|
|
172865
|
+
});
|
|
172866
|
+
event[kTarget] = this;
|
|
172867
|
+
callListener(handler, this, event);
|
|
172868
|
+
};
|
|
172869
|
+
} else if (type === "open") {
|
|
172870
|
+
wrapper = function onOpen() {
|
|
172871
|
+
const event = new Event2("open");
|
|
172872
|
+
event[kTarget] = this;
|
|
172873
|
+
callListener(handler, this, event);
|
|
172874
|
+
};
|
|
172875
|
+
} else {
|
|
172876
|
+
return;
|
|
172877
|
+
}
|
|
172878
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
172879
|
+
wrapper[kListener] = handler;
|
|
172880
|
+
if (options.once) {
|
|
172881
|
+
this.once(type, wrapper);
|
|
172882
|
+
} else {
|
|
172883
|
+
this.on(type, wrapper);
|
|
172884
|
+
}
|
|
172885
|
+
},
|
|
172886
|
+
removeEventListener(type, handler) {
|
|
172887
|
+
for (const listener of this.listeners(type)) {
|
|
172888
|
+
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
172889
|
+
this.removeListener(type, listener);
|
|
172890
|
+
break;
|
|
172891
|
+
}
|
|
172892
|
+
}
|
|
172893
|
+
}
|
|
172894
|
+
};
|
|
172895
|
+
module.exports = {
|
|
172896
|
+
CloseEvent,
|
|
172897
|
+
ErrorEvent,
|
|
172898
|
+
Event: Event2,
|
|
172899
|
+
EventTarget,
|
|
172900
|
+
MessageEvent
|
|
172901
|
+
};
|
|
172902
|
+
function callListener(listener, thisArg, event) {
|
|
172903
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
172904
|
+
listener.handleEvent.call(listener, event);
|
|
172905
|
+
} else {
|
|
172906
|
+
listener.call(thisArg, event);
|
|
172907
|
+
}
|
|
172908
|
+
}
|
|
172909
|
+
});
|
|
172910
|
+
|
|
172911
|
+
// ../../node_modules/ws/lib/extension.js
|
|
172912
|
+
var require_extension = __commonJS(function(exports, module) {
|
|
172913
|
+
var { tokenChars } = require_validation();
|
|
172914
|
+
function push(dest, name, elem) {
|
|
172915
|
+
if (dest[name] === undefined)
|
|
172916
|
+
dest[name] = [elem];
|
|
172917
|
+
else
|
|
172918
|
+
dest[name].push(elem);
|
|
172919
|
+
}
|
|
172920
|
+
function parse(header) {
|
|
172921
|
+
const offers = Object.create(null);
|
|
172922
|
+
let params = Object.create(null);
|
|
172923
|
+
let mustUnescape = false;
|
|
172924
|
+
let isEscaping = false;
|
|
172925
|
+
let inQuotes = false;
|
|
172926
|
+
let extensionName;
|
|
172927
|
+
let paramName;
|
|
172928
|
+
let start = -1;
|
|
172929
|
+
let code = -1;
|
|
172930
|
+
let end = -1;
|
|
172931
|
+
let i = 0;
|
|
172932
|
+
for (;i < header.length; i++) {
|
|
172933
|
+
code = header.charCodeAt(i);
|
|
172934
|
+
if (extensionName === undefined) {
|
|
172935
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
172936
|
+
if (start === -1)
|
|
172937
|
+
start = i;
|
|
172938
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
172939
|
+
if (end === -1 && start !== -1)
|
|
172940
|
+
end = i;
|
|
172941
|
+
} else if (code === 59 || code === 44) {
|
|
172942
|
+
if (start === -1) {
|
|
172943
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172944
|
+
}
|
|
172945
|
+
if (end === -1)
|
|
172946
|
+
end = i;
|
|
172947
|
+
const name = header.slice(start, end);
|
|
172948
|
+
if (code === 44) {
|
|
172949
|
+
push(offers, name, params);
|
|
172950
|
+
params = Object.create(null);
|
|
172951
|
+
} else {
|
|
172952
|
+
extensionName = name;
|
|
172953
|
+
}
|
|
172954
|
+
start = end = -1;
|
|
172955
|
+
} else {
|
|
172956
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172957
|
+
}
|
|
172958
|
+
} else if (paramName === undefined) {
|
|
172959
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
172960
|
+
if (start === -1)
|
|
172961
|
+
start = i;
|
|
172962
|
+
} else if (code === 32 || code === 9) {
|
|
172963
|
+
if (end === -1 && start !== -1)
|
|
172964
|
+
end = i;
|
|
172965
|
+
} else if (code === 59 || code === 44) {
|
|
172966
|
+
if (start === -1) {
|
|
172967
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172968
|
+
}
|
|
172969
|
+
if (end === -1)
|
|
172970
|
+
end = i;
|
|
172971
|
+
push(params, header.slice(start, end), true);
|
|
172972
|
+
if (code === 44) {
|
|
172973
|
+
push(offers, extensionName, params);
|
|
172974
|
+
params = Object.create(null);
|
|
172975
|
+
extensionName = undefined;
|
|
172976
|
+
}
|
|
172977
|
+
start = end = -1;
|
|
172978
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
172979
|
+
paramName = header.slice(start, i);
|
|
172980
|
+
start = end = -1;
|
|
172981
|
+
} else {
|
|
172982
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172983
|
+
}
|
|
172984
|
+
} else {
|
|
172985
|
+
if (isEscaping) {
|
|
172986
|
+
if (tokenChars[code] !== 1) {
|
|
172987
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172988
|
+
}
|
|
172989
|
+
if (start === -1)
|
|
172990
|
+
start = i;
|
|
172991
|
+
else if (!mustUnescape)
|
|
172992
|
+
mustUnescape = true;
|
|
172993
|
+
isEscaping = false;
|
|
172994
|
+
} else if (inQuotes) {
|
|
172995
|
+
if (tokenChars[code] === 1) {
|
|
172996
|
+
if (start === -1)
|
|
172997
|
+
start = i;
|
|
172998
|
+
} else if (code === 34 && start !== -1) {
|
|
172999
|
+
inQuotes = false;
|
|
173000
|
+
end = i;
|
|
173001
|
+
} else if (code === 92) {
|
|
173002
|
+
isEscaping = true;
|
|
173003
|
+
} else {
|
|
173004
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173005
|
+
}
|
|
173006
|
+
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
173007
|
+
inQuotes = true;
|
|
173008
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
173009
|
+
if (start === -1)
|
|
173010
|
+
start = i;
|
|
173011
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
173012
|
+
if (end === -1)
|
|
173013
|
+
end = i;
|
|
173014
|
+
} else if (code === 59 || code === 44) {
|
|
173015
|
+
if (start === -1) {
|
|
173016
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173017
|
+
}
|
|
173018
|
+
if (end === -1)
|
|
173019
|
+
end = i;
|
|
173020
|
+
let value = header.slice(start, end);
|
|
173021
|
+
if (mustUnescape) {
|
|
173022
|
+
value = value.replace(/\\/g, "");
|
|
173023
|
+
mustUnescape = false;
|
|
173024
|
+
}
|
|
173025
|
+
push(params, paramName, value);
|
|
173026
|
+
if (code === 44) {
|
|
173027
|
+
push(offers, extensionName, params);
|
|
173028
|
+
params = Object.create(null);
|
|
173029
|
+
extensionName = undefined;
|
|
173030
|
+
}
|
|
173031
|
+
paramName = undefined;
|
|
173032
|
+
start = end = -1;
|
|
173033
|
+
} else {
|
|
173034
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173035
|
+
}
|
|
173036
|
+
}
|
|
173037
|
+
}
|
|
173038
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
173039
|
+
throw new SyntaxError("Unexpected end of input");
|
|
173040
|
+
}
|
|
173041
|
+
if (end === -1)
|
|
173042
|
+
end = i;
|
|
173043
|
+
const token = header.slice(start, end);
|
|
173044
|
+
if (extensionName === undefined) {
|
|
173045
|
+
push(offers, token, params);
|
|
173046
|
+
} else {
|
|
173047
|
+
if (paramName === undefined) {
|
|
173048
|
+
push(params, token, true);
|
|
173049
|
+
} else if (mustUnescape) {
|
|
173050
|
+
push(params, paramName, token.replace(/\\/g, ""));
|
|
173051
|
+
} else {
|
|
173052
|
+
push(params, paramName, token);
|
|
173053
|
+
}
|
|
173054
|
+
push(offers, extensionName, params);
|
|
173055
|
+
}
|
|
173056
|
+
return offers;
|
|
173057
|
+
}
|
|
173058
|
+
function format(extensions) {
|
|
173059
|
+
return Object.keys(extensions).map((extension) => {
|
|
173060
|
+
let configurations = extensions[extension];
|
|
173061
|
+
if (!Array.isArray(configurations))
|
|
173062
|
+
configurations = [configurations];
|
|
173063
|
+
return configurations.map((params) => {
|
|
173064
|
+
return [extension].concat(Object.keys(params).map((k) => {
|
|
173065
|
+
let values = params[k];
|
|
173066
|
+
if (!Array.isArray(values))
|
|
173067
|
+
values = [values];
|
|
173068
|
+
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
173069
|
+
})).join("; ");
|
|
173070
|
+
}).join(", ");
|
|
173071
|
+
}).join(", ");
|
|
173072
|
+
}
|
|
173073
|
+
module.exports = { format, parse };
|
|
173074
|
+
});
|
|
173075
|
+
|
|
173076
|
+
// ../../node_modules/ws/lib/websocket.js
|
|
173077
|
+
var require_websocket = __commonJS(function(exports, module) {
|
|
173078
|
+
var EventEmitter = __require("events");
|
|
173079
|
+
var https = __require("https");
|
|
173080
|
+
var http = __require("http");
|
|
173081
|
+
var net = __require("net");
|
|
173082
|
+
var tls = __require("tls");
|
|
173083
|
+
var { randomBytes, createHash } = __require("crypto");
|
|
173084
|
+
var { Duplex, Readable } = __require("stream");
|
|
173085
|
+
var { URL: URL2 } = __require("url");
|
|
173086
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
173087
|
+
var Receiver = require_receiver();
|
|
173088
|
+
var Sender = require_sender();
|
|
173089
|
+
var { isBlob } = require_validation();
|
|
173090
|
+
var {
|
|
173091
|
+
BINARY_TYPES,
|
|
173092
|
+
CLOSE_TIMEOUT,
|
|
173093
|
+
EMPTY_BUFFER,
|
|
173094
|
+
GUID,
|
|
173095
|
+
kForOnEventAttribute,
|
|
173096
|
+
kListener,
|
|
173097
|
+
kStatusCode,
|
|
173098
|
+
kWebSocket,
|
|
173099
|
+
NOOP
|
|
173100
|
+
} = require_constants6();
|
|
173101
|
+
var {
|
|
173102
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
173103
|
+
} = require_event_target();
|
|
173104
|
+
var { format, parse } = require_extension();
|
|
173105
|
+
var { toBuffer } = require_buffer_util();
|
|
173106
|
+
var kAborted = Symbol("kAborted");
|
|
173107
|
+
var protocolVersions = [8, 13];
|
|
173108
|
+
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
173109
|
+
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
173110
|
+
|
|
173111
|
+
class WebSocket extends EventEmitter {
|
|
173112
|
+
constructor(address, protocols, options) {
|
|
173113
|
+
super();
|
|
173114
|
+
this._binaryType = BINARY_TYPES[0];
|
|
173115
|
+
this._closeCode = 1006;
|
|
173116
|
+
this._closeFrameReceived = false;
|
|
173117
|
+
this._closeFrameSent = false;
|
|
173118
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
173119
|
+
this._closeTimer = null;
|
|
173120
|
+
this._errorEmitted = false;
|
|
173121
|
+
this._extensions = {};
|
|
173122
|
+
this._paused = false;
|
|
173123
|
+
this._protocol = "";
|
|
173124
|
+
this._readyState = WebSocket.CONNECTING;
|
|
173125
|
+
this._receiver = null;
|
|
173126
|
+
this._sender = null;
|
|
173127
|
+
this._socket = null;
|
|
173128
|
+
if (address !== null) {
|
|
173129
|
+
this._bufferedAmount = 0;
|
|
173130
|
+
this._isServer = false;
|
|
173131
|
+
this._redirects = 0;
|
|
173132
|
+
if (protocols === undefined) {
|
|
173133
|
+
protocols = [];
|
|
173134
|
+
} else if (!Array.isArray(protocols)) {
|
|
173135
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
173136
|
+
options = protocols;
|
|
173137
|
+
protocols = [];
|
|
173138
|
+
} else {
|
|
173139
|
+
protocols = [protocols];
|
|
173140
|
+
}
|
|
173141
|
+
}
|
|
173142
|
+
initAsClient(this, address, protocols, options);
|
|
173143
|
+
} else {
|
|
173144
|
+
this._autoPong = options.autoPong;
|
|
173145
|
+
this._closeTimeout = options.closeTimeout;
|
|
173146
|
+
this._isServer = true;
|
|
173147
|
+
}
|
|
173148
|
+
}
|
|
173149
|
+
get binaryType() {
|
|
173150
|
+
return this._binaryType;
|
|
173151
|
+
}
|
|
173152
|
+
set binaryType(type) {
|
|
173153
|
+
if (!BINARY_TYPES.includes(type))
|
|
173154
|
+
return;
|
|
173155
|
+
this._binaryType = type;
|
|
173156
|
+
if (this._receiver)
|
|
173157
|
+
this._receiver._binaryType = type;
|
|
173158
|
+
}
|
|
173159
|
+
get bufferedAmount() {
|
|
173160
|
+
if (!this._socket)
|
|
173161
|
+
return this._bufferedAmount;
|
|
173162
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
173163
|
+
}
|
|
173164
|
+
get extensions() {
|
|
173165
|
+
return Object.keys(this._extensions).join();
|
|
173166
|
+
}
|
|
173167
|
+
get isPaused() {
|
|
173168
|
+
return this._paused;
|
|
173169
|
+
}
|
|
173170
|
+
get onclose() {
|
|
173171
|
+
return null;
|
|
173172
|
+
}
|
|
173173
|
+
get onerror() {
|
|
173174
|
+
return null;
|
|
173175
|
+
}
|
|
173176
|
+
get onopen() {
|
|
173177
|
+
return null;
|
|
173178
|
+
}
|
|
173179
|
+
get onmessage() {
|
|
173180
|
+
return null;
|
|
173181
|
+
}
|
|
173182
|
+
get protocol() {
|
|
173183
|
+
return this._protocol;
|
|
173184
|
+
}
|
|
173185
|
+
get readyState() {
|
|
173186
|
+
return this._readyState;
|
|
173187
|
+
}
|
|
173188
|
+
get url() {
|
|
173189
|
+
return this._url;
|
|
173190
|
+
}
|
|
173191
|
+
setSocket(socket, head, options) {
|
|
173192
|
+
const receiver = new Receiver({
|
|
173193
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
173194
|
+
binaryType: this.binaryType,
|
|
173195
|
+
extensions: this._extensions,
|
|
173196
|
+
isServer: this._isServer,
|
|
173197
|
+
maxBufferedChunks: options.maxBufferedChunks,
|
|
173198
|
+
maxFragments: options.maxFragments,
|
|
173199
|
+
maxPayload: options.maxPayload,
|
|
173200
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
173201
|
+
});
|
|
173202
|
+
const sender = new Sender(socket, this._extensions, options.generateMask);
|
|
173203
|
+
this._receiver = receiver;
|
|
173204
|
+
this._sender = sender;
|
|
173205
|
+
this._socket = socket;
|
|
173206
|
+
receiver[kWebSocket] = this;
|
|
173207
|
+
sender[kWebSocket] = this;
|
|
173208
|
+
socket[kWebSocket] = this;
|
|
173209
|
+
receiver.on("conclude", receiverOnConclude);
|
|
173210
|
+
receiver.on("drain", receiverOnDrain);
|
|
173211
|
+
receiver.on("error", receiverOnError);
|
|
173212
|
+
receiver.on("message", receiverOnMessage);
|
|
173213
|
+
receiver.on("ping", receiverOnPing);
|
|
173214
|
+
receiver.on("pong", receiverOnPong);
|
|
173215
|
+
sender.onerror = senderOnError;
|
|
173216
|
+
if (socket.setTimeout)
|
|
173217
|
+
socket.setTimeout(0);
|
|
173218
|
+
if (socket.setNoDelay)
|
|
173219
|
+
socket.setNoDelay();
|
|
173220
|
+
if (head.length > 0)
|
|
173221
|
+
socket.unshift(head);
|
|
173222
|
+
socket.on("close", socketOnClose);
|
|
173223
|
+
socket.on("data", socketOnData);
|
|
173224
|
+
socket.on("end", socketOnEnd);
|
|
173225
|
+
socket.on("error", socketOnError);
|
|
173226
|
+
this._readyState = WebSocket.OPEN;
|
|
173227
|
+
this.emit("open");
|
|
173228
|
+
}
|
|
173229
|
+
emitClose() {
|
|
173230
|
+
if (!this._socket) {
|
|
173231
|
+
this._readyState = WebSocket.CLOSED;
|
|
173232
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
173233
|
+
return;
|
|
173234
|
+
}
|
|
173235
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
173236
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
173237
|
+
}
|
|
173238
|
+
this._receiver.removeAllListeners();
|
|
173239
|
+
this._readyState = WebSocket.CLOSED;
|
|
173240
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
173241
|
+
}
|
|
173242
|
+
close(code, data) {
|
|
173243
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
173244
|
+
return;
|
|
173245
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173246
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
173247
|
+
abortHandshake(this, this._req, msg);
|
|
173248
|
+
return;
|
|
173249
|
+
}
|
|
173250
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
173251
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
173252
|
+
this._socket.end();
|
|
173253
|
+
}
|
|
173254
|
+
return;
|
|
173255
|
+
}
|
|
173256
|
+
this._readyState = WebSocket.CLOSING;
|
|
173257
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
173258
|
+
if (err)
|
|
173259
|
+
return;
|
|
173260
|
+
this._closeFrameSent = true;
|
|
173261
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
173262
|
+
this._socket.end();
|
|
173263
|
+
}
|
|
173264
|
+
});
|
|
173265
|
+
setCloseTimer(this);
|
|
173266
|
+
}
|
|
173267
|
+
pause() {
|
|
173268
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
173269
|
+
return;
|
|
173270
|
+
}
|
|
173271
|
+
this._paused = true;
|
|
173272
|
+
this._socket.pause();
|
|
173273
|
+
}
|
|
173274
|
+
ping(data, mask, cb) {
|
|
173275
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173276
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
173277
|
+
}
|
|
173278
|
+
if (typeof data === "function") {
|
|
173279
|
+
cb = data;
|
|
173280
|
+
data = mask = undefined;
|
|
173281
|
+
} else if (typeof mask === "function") {
|
|
173282
|
+
cb = mask;
|
|
173283
|
+
mask = undefined;
|
|
173284
|
+
}
|
|
173285
|
+
if (typeof data === "number")
|
|
173286
|
+
data = data.toString();
|
|
173287
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
173288
|
+
sendAfterClose(this, data, cb);
|
|
173289
|
+
return;
|
|
173290
|
+
}
|
|
173291
|
+
if (mask === undefined)
|
|
173292
|
+
mask = !this._isServer;
|
|
173293
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
173294
|
+
}
|
|
173295
|
+
pong(data, mask, cb) {
|
|
173296
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173297
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
173298
|
+
}
|
|
173299
|
+
if (typeof data === "function") {
|
|
173300
|
+
cb = data;
|
|
173301
|
+
data = mask = undefined;
|
|
173302
|
+
} else if (typeof mask === "function") {
|
|
173303
|
+
cb = mask;
|
|
173304
|
+
mask = undefined;
|
|
173305
|
+
}
|
|
173306
|
+
if (typeof data === "number")
|
|
173307
|
+
data = data.toString();
|
|
173308
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
173309
|
+
sendAfterClose(this, data, cb);
|
|
173310
|
+
return;
|
|
173311
|
+
}
|
|
173312
|
+
if (mask === undefined)
|
|
173313
|
+
mask = !this._isServer;
|
|
173314
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
173315
|
+
}
|
|
173316
|
+
resume() {
|
|
173317
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
173318
|
+
return;
|
|
173319
|
+
}
|
|
173320
|
+
this._paused = false;
|
|
173321
|
+
if (!this._receiver._writableState.needDrain)
|
|
173322
|
+
this._socket.resume();
|
|
173323
|
+
}
|
|
173324
|
+
send(data, options, cb) {
|
|
173325
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173326
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
173327
|
+
}
|
|
173328
|
+
if (typeof options === "function") {
|
|
173329
|
+
cb = options;
|
|
173330
|
+
options = {};
|
|
173331
|
+
}
|
|
173332
|
+
if (typeof data === "number")
|
|
173333
|
+
data = data.toString();
|
|
173334
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
173335
|
+
sendAfterClose(this, data, cb);
|
|
173336
|
+
return;
|
|
173337
|
+
}
|
|
173338
|
+
const opts = {
|
|
173339
|
+
binary: typeof data !== "string",
|
|
173340
|
+
mask: !this._isServer,
|
|
173341
|
+
compress: true,
|
|
173342
|
+
fin: true,
|
|
173343
|
+
...options
|
|
173344
|
+
};
|
|
173345
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
173346
|
+
opts.compress = false;
|
|
173347
|
+
}
|
|
173348
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
173349
|
+
}
|
|
173350
|
+
terminate() {
|
|
173351
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
173352
|
+
return;
|
|
173353
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173354
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
173355
|
+
abortHandshake(this, this._req, msg);
|
|
173356
|
+
return;
|
|
173357
|
+
}
|
|
173358
|
+
if (this._socket) {
|
|
173359
|
+
this._readyState = WebSocket.CLOSING;
|
|
173360
|
+
this._socket.destroy();
|
|
173361
|
+
}
|
|
173362
|
+
}
|
|
173363
|
+
}
|
|
173364
|
+
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
173365
|
+
enumerable: true,
|
|
173366
|
+
value: readyStates.indexOf("CONNECTING")
|
|
173367
|
+
});
|
|
173368
|
+
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
173369
|
+
enumerable: true,
|
|
173370
|
+
value: readyStates.indexOf("CONNECTING")
|
|
173371
|
+
});
|
|
173372
|
+
Object.defineProperty(WebSocket, "OPEN", {
|
|
173373
|
+
enumerable: true,
|
|
173374
|
+
value: readyStates.indexOf("OPEN")
|
|
173375
|
+
});
|
|
173376
|
+
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
173377
|
+
enumerable: true,
|
|
173378
|
+
value: readyStates.indexOf("OPEN")
|
|
173379
|
+
});
|
|
173380
|
+
Object.defineProperty(WebSocket, "CLOSING", {
|
|
173381
|
+
enumerable: true,
|
|
173382
|
+
value: readyStates.indexOf("CLOSING")
|
|
173383
|
+
});
|
|
173384
|
+
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
173385
|
+
enumerable: true,
|
|
173386
|
+
value: readyStates.indexOf("CLOSING")
|
|
173387
|
+
});
|
|
173388
|
+
Object.defineProperty(WebSocket, "CLOSED", {
|
|
173389
|
+
enumerable: true,
|
|
173390
|
+
value: readyStates.indexOf("CLOSED")
|
|
173391
|
+
});
|
|
173392
|
+
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
173393
|
+
enumerable: true,
|
|
173394
|
+
value: readyStates.indexOf("CLOSED")
|
|
173395
|
+
});
|
|
173396
|
+
[
|
|
173397
|
+
"binaryType",
|
|
173398
|
+
"bufferedAmount",
|
|
173399
|
+
"extensions",
|
|
173400
|
+
"isPaused",
|
|
173401
|
+
"protocol",
|
|
173402
|
+
"readyState",
|
|
173403
|
+
"url"
|
|
173404
|
+
].forEach((property) => {
|
|
173405
|
+
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
|
173406
|
+
});
|
|
173407
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
173408
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
173409
|
+
enumerable: true,
|
|
173410
|
+
get() {
|
|
173411
|
+
for (const listener of this.listeners(method)) {
|
|
173412
|
+
if (listener[kForOnEventAttribute])
|
|
173413
|
+
return listener[kListener];
|
|
173414
|
+
}
|
|
173415
|
+
return null;
|
|
173416
|
+
},
|
|
173417
|
+
set(handler) {
|
|
173418
|
+
for (const listener of this.listeners(method)) {
|
|
173419
|
+
if (listener[kForOnEventAttribute]) {
|
|
173420
|
+
this.removeListener(method, listener);
|
|
173421
|
+
break;
|
|
173422
|
+
}
|
|
173423
|
+
}
|
|
173424
|
+
if (typeof handler !== "function")
|
|
173425
|
+
return;
|
|
173426
|
+
this.addEventListener(method, handler, {
|
|
173427
|
+
[kForOnEventAttribute]: true
|
|
173428
|
+
});
|
|
173429
|
+
}
|
|
173430
|
+
});
|
|
173431
|
+
});
|
|
173432
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
173433
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
173434
|
+
module.exports = WebSocket;
|
|
173435
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
173436
|
+
const opts = {
|
|
173437
|
+
allowSynchronousEvents: true,
|
|
173438
|
+
autoPong: true,
|
|
173439
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
173440
|
+
protocolVersion: protocolVersions[1],
|
|
173441
|
+
maxBufferedChunks: 1024 * 1024,
|
|
173442
|
+
maxFragments: 128 * 1024,
|
|
173443
|
+
maxPayload: 100 * 1024 * 1024,
|
|
173444
|
+
skipUTF8Validation: false,
|
|
173445
|
+
perMessageDeflate: true,
|
|
173446
|
+
followRedirects: false,
|
|
173447
|
+
maxRedirects: 10,
|
|
173448
|
+
...options,
|
|
173449
|
+
socketPath: undefined,
|
|
173450
|
+
hostname: undefined,
|
|
173451
|
+
protocol: undefined,
|
|
173452
|
+
timeout: undefined,
|
|
173453
|
+
method: "GET",
|
|
173454
|
+
host: undefined,
|
|
173455
|
+
path: undefined,
|
|
173456
|
+
port: undefined
|
|
173457
|
+
};
|
|
173458
|
+
websocket._autoPong = opts.autoPong;
|
|
173459
|
+
websocket._closeTimeout = opts.closeTimeout;
|
|
173460
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
173461
|
+
throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
|
|
173462
|
+
}
|
|
173463
|
+
let parsedUrl;
|
|
173464
|
+
if (address instanceof URL2) {
|
|
173465
|
+
parsedUrl = address;
|
|
173466
|
+
} else {
|
|
173467
|
+
try {
|
|
173468
|
+
parsedUrl = new URL2(address);
|
|
173469
|
+
} catch {
|
|
173470
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
173471
|
+
}
|
|
173472
|
+
}
|
|
173473
|
+
if (parsedUrl.protocol === "http:") {
|
|
173474
|
+
parsedUrl.protocol = "ws:";
|
|
173475
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
173476
|
+
parsedUrl.protocol = "wss:";
|
|
173477
|
+
}
|
|
173478
|
+
websocket._url = parsedUrl.href;
|
|
173479
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
173480
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
173481
|
+
let invalidUrlMessage;
|
|
173482
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
173483
|
+
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
|
|
173484
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
173485
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
173486
|
+
} else if (parsedUrl.hash) {
|
|
173487
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
173488
|
+
}
|
|
173489
|
+
if (invalidUrlMessage) {
|
|
173490
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
173491
|
+
if (websocket._redirects === 0) {
|
|
173492
|
+
throw err;
|
|
173493
|
+
} else {
|
|
173494
|
+
emitErrorAndClose(websocket, err);
|
|
173495
|
+
return;
|
|
173496
|
+
}
|
|
173497
|
+
}
|
|
173498
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
173499
|
+
const key = randomBytes(16).toString("base64");
|
|
173500
|
+
const request3 = isSecure ? https.request : http.request;
|
|
173501
|
+
const protocolSet = new Set;
|
|
173502
|
+
let perMessageDeflate;
|
|
173503
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
173504
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
173505
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
173506
|
+
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
173507
|
+
opts.headers = {
|
|
173508
|
+
...opts.headers,
|
|
173509
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
173510
|
+
"Sec-WebSocket-Key": key,
|
|
173511
|
+
Connection: "Upgrade",
|
|
173512
|
+
Upgrade: "websocket"
|
|
173513
|
+
};
|
|
173514
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
173515
|
+
opts.timeout = opts.handshakeTimeout;
|
|
173516
|
+
if (opts.perMessageDeflate) {
|
|
173517
|
+
perMessageDeflate = new PerMessageDeflate({
|
|
173518
|
+
...opts.perMessageDeflate,
|
|
173519
|
+
isServer: false,
|
|
173520
|
+
maxPayload: opts.maxPayload
|
|
173521
|
+
});
|
|
173522
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
173523
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
173524
|
+
});
|
|
173525
|
+
}
|
|
173526
|
+
if (protocols.length) {
|
|
173527
|
+
for (const protocol of protocols) {
|
|
173528
|
+
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
173529
|
+
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
173530
|
+
}
|
|
173531
|
+
protocolSet.add(protocol);
|
|
173532
|
+
}
|
|
173533
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
173534
|
+
}
|
|
173535
|
+
if (opts.origin) {
|
|
173536
|
+
if (opts.protocolVersion < 13) {
|
|
173537
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
173538
|
+
} else {
|
|
173539
|
+
opts.headers.Origin = opts.origin;
|
|
173540
|
+
}
|
|
173541
|
+
}
|
|
173542
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
173543
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
173544
|
+
}
|
|
173545
|
+
if (isIpcUrl) {
|
|
173546
|
+
const parts = opts.path.split(":");
|
|
173547
|
+
opts.socketPath = parts[0];
|
|
173548
|
+
opts.path = parts[1];
|
|
173549
|
+
}
|
|
173550
|
+
let req;
|
|
173551
|
+
if (opts.followRedirects) {
|
|
173552
|
+
if (websocket._redirects === 0) {
|
|
173553
|
+
websocket._originalIpc = isIpcUrl;
|
|
173554
|
+
websocket._originalSecure = isSecure;
|
|
173555
|
+
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
173556
|
+
const headers = options && options.headers;
|
|
173557
|
+
options = { ...options, headers: {} };
|
|
173558
|
+
if (headers) {
|
|
173559
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
173560
|
+
options.headers[key.toLowerCase()] = value;
|
|
173561
|
+
}
|
|
173562
|
+
}
|
|
173563
|
+
} else if (websocket.listenerCount("redirect") === 0) {
|
|
173564
|
+
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
173565
|
+
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
173566
|
+
delete opts.headers.authorization;
|
|
173567
|
+
delete opts.headers.cookie;
|
|
173568
|
+
if (!isSameHost)
|
|
173569
|
+
delete opts.headers.host;
|
|
173570
|
+
opts.auth = undefined;
|
|
173571
|
+
}
|
|
173572
|
+
}
|
|
173573
|
+
if (opts.auth && !options.headers.authorization) {
|
|
173574
|
+
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
173575
|
+
}
|
|
173576
|
+
req = websocket._req = request3(opts);
|
|
173577
|
+
if (websocket._redirects) {
|
|
173578
|
+
websocket.emit("redirect", websocket.url, req);
|
|
173579
|
+
}
|
|
173580
|
+
} else {
|
|
173581
|
+
req = websocket._req = request3(opts);
|
|
173582
|
+
}
|
|
173583
|
+
if (opts.timeout) {
|
|
173584
|
+
req.on("timeout", () => {
|
|
173585
|
+
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
173586
|
+
});
|
|
173587
|
+
}
|
|
173588
|
+
req.on("error", (err) => {
|
|
173589
|
+
if (req === null || req[kAborted])
|
|
173590
|
+
return;
|
|
173591
|
+
req = websocket._req = null;
|
|
173592
|
+
emitErrorAndClose(websocket, err);
|
|
173593
|
+
});
|
|
173594
|
+
req.on("response", (res) => {
|
|
173595
|
+
const location2 = res.headers.location;
|
|
173596
|
+
const statusCode = res.statusCode;
|
|
173597
|
+
if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
173598
|
+
if (++websocket._redirects > opts.maxRedirects) {
|
|
173599
|
+
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
173600
|
+
return;
|
|
173601
|
+
}
|
|
173602
|
+
req.abort();
|
|
173603
|
+
let addr;
|
|
173604
|
+
try {
|
|
173605
|
+
addr = new URL2(location2, address);
|
|
173606
|
+
} catch (e) {
|
|
173607
|
+
const err = new SyntaxError(`Invalid URL: ${location2}`);
|
|
173608
|
+
emitErrorAndClose(websocket, err);
|
|
173609
|
+
return;
|
|
173610
|
+
}
|
|
173611
|
+
initAsClient(websocket, addr, protocols, options);
|
|
173612
|
+
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
173613
|
+
abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
173614
|
+
}
|
|
173615
|
+
});
|
|
173616
|
+
req.on("upgrade", (res, socket, head) => {
|
|
173617
|
+
websocket.emit("upgrade", res);
|
|
173618
|
+
if (websocket.readyState !== WebSocket.CONNECTING)
|
|
173619
|
+
return;
|
|
173620
|
+
req = websocket._req = null;
|
|
173621
|
+
const upgrade = res.headers.upgrade;
|
|
173622
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
173623
|
+
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
173624
|
+
return;
|
|
173625
|
+
}
|
|
173626
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
173627
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
173628
|
+
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
173629
|
+
return;
|
|
173630
|
+
}
|
|
173631
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
173632
|
+
let protError;
|
|
173633
|
+
if (serverProt !== undefined) {
|
|
173634
|
+
if (!protocolSet.size) {
|
|
173635
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
173636
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
173637
|
+
protError = "Server sent an invalid subprotocol";
|
|
173638
|
+
}
|
|
173639
|
+
} else if (protocolSet.size) {
|
|
173640
|
+
protError = "Server sent no subprotocol";
|
|
173641
|
+
}
|
|
173642
|
+
if (protError) {
|
|
173643
|
+
abortHandshake(websocket, socket, protError);
|
|
173644
|
+
return;
|
|
173645
|
+
}
|
|
173646
|
+
if (serverProt)
|
|
173647
|
+
websocket._protocol = serverProt;
|
|
173648
|
+
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
173649
|
+
if (secWebSocketExtensions !== undefined) {
|
|
173650
|
+
if (!perMessageDeflate) {
|
|
173651
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
|
|
173652
|
+
abortHandshake(websocket, socket, message);
|
|
173653
|
+
return;
|
|
173654
|
+
}
|
|
173655
|
+
let extensions;
|
|
173656
|
+
try {
|
|
173657
|
+
extensions = parse(secWebSocketExtensions);
|
|
173658
|
+
} catch (err) {
|
|
173659
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
173660
|
+
abortHandshake(websocket, socket, message);
|
|
173661
|
+
return;
|
|
173662
|
+
}
|
|
173663
|
+
const extensionNames = Object.keys(extensions);
|
|
173664
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
173665
|
+
const message = "Server indicated an extension that was not requested";
|
|
173666
|
+
abortHandshake(websocket, socket, message);
|
|
173667
|
+
return;
|
|
173668
|
+
}
|
|
173669
|
+
try {
|
|
173670
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
173671
|
+
} catch (err) {
|
|
173672
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
173673
|
+
abortHandshake(websocket, socket, message);
|
|
173674
|
+
return;
|
|
173675
|
+
}
|
|
173676
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
173677
|
+
}
|
|
173678
|
+
websocket.setSocket(socket, head, {
|
|
173679
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
173680
|
+
generateMask: opts.generateMask,
|
|
173681
|
+
maxBufferedChunks: opts.maxBufferedChunks,
|
|
173682
|
+
maxFragments: opts.maxFragments,
|
|
173683
|
+
maxPayload: opts.maxPayload,
|
|
173684
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
173685
|
+
});
|
|
173686
|
+
});
|
|
173687
|
+
if (opts.finishRequest) {
|
|
173688
|
+
opts.finishRequest(req, websocket);
|
|
173689
|
+
} else {
|
|
173690
|
+
req.end();
|
|
173691
|
+
}
|
|
173692
|
+
}
|
|
173693
|
+
function emitErrorAndClose(websocket, err) {
|
|
173694
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173695
|
+
websocket._errorEmitted = true;
|
|
173696
|
+
websocket.emit("error", err);
|
|
173697
|
+
websocket.emitClose();
|
|
173698
|
+
}
|
|
173699
|
+
function netConnect(options) {
|
|
173700
|
+
options.path = options.socketPath;
|
|
173701
|
+
return net.connect(options);
|
|
173702
|
+
}
|
|
173703
|
+
function tlsConnect(options) {
|
|
173704
|
+
options.path = undefined;
|
|
173705
|
+
if (!options.servername && options.servername !== "") {
|
|
173706
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
173707
|
+
}
|
|
173708
|
+
return tls.connect(options);
|
|
173709
|
+
}
|
|
173710
|
+
function abortHandshake(websocket, stream, message) {
|
|
173711
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173712
|
+
const err = new Error(message);
|
|
173713
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
173714
|
+
if (stream.setHeader) {
|
|
173715
|
+
stream[kAborted] = true;
|
|
173716
|
+
stream.abort();
|
|
173717
|
+
if (stream.socket && !stream.socket.destroyed) {
|
|
173718
|
+
stream.socket.destroy();
|
|
173719
|
+
}
|
|
173720
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
173721
|
+
} else {
|
|
173722
|
+
stream.destroy(err);
|
|
173723
|
+
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
173724
|
+
stream.once("close", websocket.emitClose.bind(websocket));
|
|
173725
|
+
}
|
|
173726
|
+
}
|
|
173727
|
+
function sendAfterClose(websocket, data, cb) {
|
|
173728
|
+
if (data) {
|
|
173729
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
173730
|
+
if (websocket._socket)
|
|
173731
|
+
websocket._sender._bufferedBytes += length;
|
|
173732
|
+
else
|
|
173733
|
+
websocket._bufferedAmount += length;
|
|
173734
|
+
}
|
|
173735
|
+
if (cb) {
|
|
173736
|
+
const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
|
|
173737
|
+
process.nextTick(cb, err);
|
|
173738
|
+
}
|
|
173739
|
+
}
|
|
173740
|
+
function receiverOnConclude(code, reason) {
|
|
173741
|
+
const websocket = this[kWebSocket];
|
|
173742
|
+
websocket._closeFrameReceived = true;
|
|
173743
|
+
websocket._closeMessage = reason;
|
|
173744
|
+
websocket._closeCode = code;
|
|
173745
|
+
if (websocket._socket[kWebSocket] === undefined)
|
|
173746
|
+
return;
|
|
173747
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
173748
|
+
process.nextTick(resume, websocket._socket);
|
|
173749
|
+
if (code === 1005)
|
|
173750
|
+
websocket.close();
|
|
173751
|
+
else
|
|
173752
|
+
websocket.close(code, reason);
|
|
173753
|
+
}
|
|
173754
|
+
function receiverOnDrain() {
|
|
173755
|
+
const websocket = this[kWebSocket];
|
|
173756
|
+
if (!websocket.isPaused)
|
|
173757
|
+
websocket._socket.resume();
|
|
173758
|
+
}
|
|
173759
|
+
function receiverOnError(err) {
|
|
173760
|
+
const websocket = this[kWebSocket];
|
|
173761
|
+
if (websocket._socket[kWebSocket] !== undefined) {
|
|
173762
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
173763
|
+
process.nextTick(resume, websocket._socket);
|
|
173764
|
+
websocket.close(err[kStatusCode]);
|
|
173765
|
+
}
|
|
173766
|
+
if (!websocket._errorEmitted) {
|
|
173767
|
+
websocket._errorEmitted = true;
|
|
173768
|
+
websocket.emit("error", err);
|
|
173769
|
+
}
|
|
173770
|
+
}
|
|
173771
|
+
function receiverOnFinish() {
|
|
173772
|
+
this[kWebSocket].emitClose();
|
|
173773
|
+
}
|
|
173774
|
+
function receiverOnMessage(data, isBinary) {
|
|
173775
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
173776
|
+
}
|
|
173777
|
+
function receiverOnPing(data) {
|
|
173778
|
+
const websocket = this[kWebSocket];
|
|
173779
|
+
if (websocket._autoPong)
|
|
173780
|
+
websocket.pong(data, !this._isServer, NOOP);
|
|
173781
|
+
websocket.emit("ping", data);
|
|
173782
|
+
}
|
|
173783
|
+
function receiverOnPong(data) {
|
|
173784
|
+
this[kWebSocket].emit("pong", data);
|
|
173785
|
+
}
|
|
173786
|
+
function resume(stream) {
|
|
173787
|
+
stream.resume();
|
|
173788
|
+
}
|
|
173789
|
+
function senderOnError(err) {
|
|
173790
|
+
const websocket = this[kWebSocket];
|
|
173791
|
+
if (websocket.readyState === WebSocket.CLOSED)
|
|
173792
|
+
return;
|
|
173793
|
+
if (websocket.readyState === WebSocket.OPEN) {
|
|
173794
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173795
|
+
setCloseTimer(websocket);
|
|
173796
|
+
}
|
|
173797
|
+
this._socket.end();
|
|
173798
|
+
if (!websocket._errorEmitted) {
|
|
173799
|
+
websocket._errorEmitted = true;
|
|
173800
|
+
websocket.emit("error", err);
|
|
173801
|
+
}
|
|
173802
|
+
}
|
|
173803
|
+
function setCloseTimer(websocket) {
|
|
173804
|
+
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
173805
|
+
}
|
|
173806
|
+
function socketOnClose() {
|
|
173807
|
+
const websocket = this[kWebSocket];
|
|
173808
|
+
this.removeListener("close", socketOnClose);
|
|
173809
|
+
this.removeListener("data", socketOnData);
|
|
173810
|
+
this.removeListener("end", socketOnEnd);
|
|
173811
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173812
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
173813
|
+
const chunk = this.read(this._readableState.length);
|
|
173814
|
+
websocket._receiver.write(chunk);
|
|
173815
|
+
}
|
|
173816
|
+
websocket._receiver.end();
|
|
173817
|
+
this[kWebSocket] = undefined;
|
|
173818
|
+
clearTimeout(websocket._closeTimer);
|
|
173819
|
+
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
173820
|
+
websocket.emitClose();
|
|
173821
|
+
} else {
|
|
173822
|
+
websocket._receiver.on("error", receiverOnFinish);
|
|
173823
|
+
websocket._receiver.on("finish", receiverOnFinish);
|
|
173824
|
+
}
|
|
173825
|
+
}
|
|
173826
|
+
function socketOnData(chunk) {
|
|
173827
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
173828
|
+
this.pause();
|
|
173829
|
+
}
|
|
173830
|
+
}
|
|
173831
|
+
function socketOnEnd() {
|
|
173832
|
+
const websocket = this[kWebSocket];
|
|
173833
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173834
|
+
websocket._receiver.end();
|
|
173835
|
+
this.end();
|
|
173836
|
+
}
|
|
173837
|
+
function socketOnError() {
|
|
173838
|
+
const websocket = this[kWebSocket];
|
|
173839
|
+
this.removeListener("error", socketOnError);
|
|
173840
|
+
this.on("error", NOOP);
|
|
173841
|
+
if (websocket) {
|
|
173842
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173843
|
+
this.destroy();
|
|
173844
|
+
}
|
|
173845
|
+
}
|
|
173846
|
+
});
|
|
173847
|
+
|
|
173848
|
+
// ../../node_modules/ws/lib/stream.js
|
|
173849
|
+
var require_stream6 = __commonJS(function(exports, module) {
|
|
173850
|
+
var WebSocket = require_websocket();
|
|
173851
|
+
var { Duplex } = __require("stream");
|
|
173852
|
+
function emitClose(stream) {
|
|
173853
|
+
stream.emit("close");
|
|
173854
|
+
}
|
|
173855
|
+
function duplexOnEnd() {
|
|
173856
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
173857
|
+
this.destroy();
|
|
173858
|
+
}
|
|
173859
|
+
}
|
|
173860
|
+
function duplexOnError(err) {
|
|
173861
|
+
this.removeListener("error", duplexOnError);
|
|
173862
|
+
this.destroy();
|
|
173863
|
+
if (this.listenerCount("error") === 0) {
|
|
173864
|
+
this.emit("error", err);
|
|
173865
|
+
}
|
|
173866
|
+
}
|
|
173867
|
+
function createWebSocketStream(ws, options) {
|
|
173868
|
+
let terminateOnDestroy = true;
|
|
173869
|
+
const duplex = new Duplex({
|
|
173870
|
+
...options,
|
|
173871
|
+
autoDestroy: false,
|
|
173872
|
+
emitClose: false,
|
|
173873
|
+
objectMode: false,
|
|
173874
|
+
writableObjectMode: false
|
|
173875
|
+
});
|
|
173876
|
+
ws.on("message", function message(msg, isBinary) {
|
|
173877
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
173878
|
+
if (!duplex.push(data))
|
|
173879
|
+
ws.pause();
|
|
173880
|
+
});
|
|
173881
|
+
ws.once("error", function error(err) {
|
|
173882
|
+
if (duplex.destroyed)
|
|
173883
|
+
return;
|
|
173884
|
+
terminateOnDestroy = false;
|
|
173885
|
+
duplex.destroy(err);
|
|
173886
|
+
});
|
|
173887
|
+
ws.once("close", function close() {
|
|
173888
|
+
if (duplex.destroyed)
|
|
173889
|
+
return;
|
|
173890
|
+
duplex.push(null);
|
|
173891
|
+
});
|
|
173892
|
+
duplex._destroy = function(err, callback) {
|
|
173893
|
+
if (ws.readyState === ws.CLOSED) {
|
|
173894
|
+
callback(err);
|
|
173895
|
+
process.nextTick(emitClose, duplex);
|
|
173896
|
+
return;
|
|
173897
|
+
}
|
|
173898
|
+
let called = false;
|
|
173899
|
+
ws.once("error", function error(err) {
|
|
173900
|
+
called = true;
|
|
173901
|
+
callback(err);
|
|
173902
|
+
});
|
|
173903
|
+
ws.once("close", function close() {
|
|
173904
|
+
if (!called)
|
|
173905
|
+
callback(err);
|
|
173906
|
+
process.nextTick(emitClose, duplex);
|
|
173907
|
+
});
|
|
173908
|
+
if (terminateOnDestroy)
|
|
173909
|
+
ws.terminate();
|
|
173910
|
+
};
|
|
173911
|
+
duplex._final = function(callback) {
|
|
173912
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
173913
|
+
ws.once("open", function open() {
|
|
173914
|
+
duplex._final(callback);
|
|
173915
|
+
});
|
|
173916
|
+
return;
|
|
173917
|
+
}
|
|
173918
|
+
if (ws._socket === null)
|
|
173919
|
+
return;
|
|
173920
|
+
if (ws._socket._writableState.finished) {
|
|
173921
|
+
callback();
|
|
173922
|
+
if (duplex._readableState.endEmitted)
|
|
173923
|
+
duplex.destroy();
|
|
173924
|
+
} else {
|
|
173925
|
+
ws._socket.once("finish", function finish() {
|
|
173926
|
+
callback();
|
|
173927
|
+
});
|
|
173928
|
+
ws.close();
|
|
173929
|
+
}
|
|
173930
|
+
};
|
|
173931
|
+
duplex._read = function() {
|
|
173932
|
+
if (ws.isPaused)
|
|
173933
|
+
ws.resume();
|
|
173934
|
+
};
|
|
173935
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
173936
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
173937
|
+
ws.once("open", function open() {
|
|
173938
|
+
duplex._write(chunk, encoding, callback);
|
|
173939
|
+
});
|
|
173940
|
+
return;
|
|
173941
|
+
}
|
|
173942
|
+
ws.send(chunk, callback);
|
|
173943
|
+
};
|
|
173944
|
+
duplex.on("end", duplexOnEnd);
|
|
173945
|
+
duplex.on("error", duplexOnError);
|
|
173946
|
+
return duplex;
|
|
173947
|
+
}
|
|
173948
|
+
module.exports = createWebSocketStream;
|
|
173949
|
+
});
|
|
173950
|
+
|
|
173951
|
+
// ../../node_modules/ws/lib/subprotocol.js
|
|
173952
|
+
var require_subprotocol = __commonJS(function(exports, module) {
|
|
173953
|
+
var { tokenChars } = require_validation();
|
|
173954
|
+
function parse(header) {
|
|
173955
|
+
const protocols = new Set;
|
|
173956
|
+
let start = -1;
|
|
173957
|
+
let end = -1;
|
|
173958
|
+
let i = 0;
|
|
173959
|
+
for (i;i < header.length; i++) {
|
|
173960
|
+
const code = header.charCodeAt(i);
|
|
173961
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
173962
|
+
if (start === -1)
|
|
173963
|
+
start = i;
|
|
173964
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
173965
|
+
if (end === -1 && start !== -1)
|
|
173966
|
+
end = i;
|
|
173967
|
+
} else if (code === 44) {
|
|
173968
|
+
if (start === -1) {
|
|
173969
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173970
|
+
}
|
|
173971
|
+
if (end === -1)
|
|
173972
|
+
end = i;
|
|
173973
|
+
const protocol = header.slice(start, end);
|
|
173974
|
+
if (protocols.has(protocol)) {
|
|
173975
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
173976
|
+
}
|
|
173977
|
+
protocols.add(protocol);
|
|
173978
|
+
start = end = -1;
|
|
173979
|
+
} else {
|
|
173980
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173981
|
+
}
|
|
173982
|
+
}
|
|
173983
|
+
if (start === -1 || end !== -1) {
|
|
173984
|
+
throw new SyntaxError("Unexpected end of input");
|
|
173985
|
+
}
|
|
173986
|
+
const protocol = header.slice(start, i);
|
|
173987
|
+
if (protocols.has(protocol)) {
|
|
173988
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
173989
|
+
}
|
|
173990
|
+
protocols.add(protocol);
|
|
173991
|
+
return protocols;
|
|
173992
|
+
}
|
|
173993
|
+
module.exports = { parse };
|
|
173994
|
+
});
|
|
173995
|
+
|
|
173996
|
+
// ../../node_modules/ws/lib/websocket-server.js
|
|
173997
|
+
var require_websocket_server = __commonJS(function(exports, module) {
|
|
173998
|
+
var EventEmitter = __require("events");
|
|
173999
|
+
var http = __require("http");
|
|
174000
|
+
var { Duplex } = __require("stream");
|
|
174001
|
+
var { createHash } = __require("crypto");
|
|
174002
|
+
var extension = require_extension();
|
|
174003
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
174004
|
+
var subprotocol = require_subprotocol();
|
|
174005
|
+
var WebSocket = require_websocket();
|
|
174006
|
+
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants6();
|
|
174007
|
+
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
174008
|
+
var RUNNING = 0;
|
|
174009
|
+
var CLOSING = 1;
|
|
174010
|
+
var CLOSED = 2;
|
|
174011
|
+
|
|
174012
|
+
class WebSocketServer extends EventEmitter {
|
|
174013
|
+
constructor(options, callback) {
|
|
174014
|
+
super();
|
|
174015
|
+
options = {
|
|
174016
|
+
allowSynchronousEvents: true,
|
|
174017
|
+
autoPong: true,
|
|
174018
|
+
maxBufferedChunks: 1024 * 1024,
|
|
174019
|
+
maxFragments: 128 * 1024,
|
|
174020
|
+
maxPayload: 100 * 1024 * 1024,
|
|
174021
|
+
skipUTF8Validation: false,
|
|
174022
|
+
perMessageDeflate: false,
|
|
174023
|
+
handleProtocols: null,
|
|
174024
|
+
clientTracking: true,
|
|
174025
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
174026
|
+
verifyClient: null,
|
|
174027
|
+
noServer: false,
|
|
174028
|
+
backlog: null,
|
|
174029
|
+
server: null,
|
|
174030
|
+
host: null,
|
|
174031
|
+
path: null,
|
|
174032
|
+
port: null,
|
|
174033
|
+
WebSocket,
|
|
174034
|
+
...options
|
|
174035
|
+
};
|
|
174036
|
+
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
174037
|
+
throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
|
|
174038
|
+
}
|
|
174039
|
+
if (options.port != null) {
|
|
174040
|
+
this._server = http.createServer((req, res) => {
|
|
174041
|
+
const body = http.STATUS_CODES[426];
|
|
174042
|
+
res.writeHead(426, {
|
|
174043
|
+
"Content-Length": body.length,
|
|
174044
|
+
"Content-Type": "text/plain"
|
|
174045
|
+
});
|
|
174046
|
+
res.end(body);
|
|
174047
|
+
});
|
|
174048
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
174049
|
+
} else if (options.server) {
|
|
174050
|
+
this._server = options.server;
|
|
174051
|
+
}
|
|
174052
|
+
if (this._server) {
|
|
174053
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
174054
|
+
this._removeListeners = addListeners(this._server, {
|
|
174055
|
+
listening: this.emit.bind(this, "listening"),
|
|
174056
|
+
error: this.emit.bind(this, "error"),
|
|
174057
|
+
upgrade: (req, socket, head) => {
|
|
174058
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
174059
|
+
}
|
|
174060
|
+
});
|
|
174061
|
+
}
|
|
174062
|
+
if (options.perMessageDeflate === true)
|
|
174063
|
+
options.perMessageDeflate = {};
|
|
174064
|
+
if (options.clientTracking) {
|
|
174065
|
+
this.clients = new Set;
|
|
174066
|
+
this._shouldEmitClose = false;
|
|
174067
|
+
}
|
|
174068
|
+
this.options = options;
|
|
174069
|
+
this._state = RUNNING;
|
|
174070
|
+
}
|
|
174071
|
+
address() {
|
|
174072
|
+
if (this.options.noServer) {
|
|
174073
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
174074
|
+
}
|
|
174075
|
+
if (!this._server)
|
|
174076
|
+
return null;
|
|
174077
|
+
return this._server.address();
|
|
174078
|
+
}
|
|
174079
|
+
close(cb) {
|
|
174080
|
+
if (this._state === CLOSED) {
|
|
174081
|
+
if (cb) {
|
|
174082
|
+
this.once("close", () => {
|
|
174083
|
+
cb(new Error("The server is not running"));
|
|
174084
|
+
});
|
|
174085
|
+
}
|
|
174086
|
+
process.nextTick(emitClose, this);
|
|
174087
|
+
return;
|
|
174088
|
+
}
|
|
174089
|
+
if (cb)
|
|
174090
|
+
this.once("close", cb);
|
|
174091
|
+
if (this._state === CLOSING)
|
|
174092
|
+
return;
|
|
174093
|
+
this._state = CLOSING;
|
|
174094
|
+
if (this.options.noServer || this.options.server) {
|
|
174095
|
+
if (this._server) {
|
|
174096
|
+
this._removeListeners();
|
|
174097
|
+
this._removeListeners = this._server = null;
|
|
174098
|
+
}
|
|
174099
|
+
if (this.clients) {
|
|
174100
|
+
if (!this.clients.size) {
|
|
174101
|
+
process.nextTick(emitClose, this);
|
|
174102
|
+
} else {
|
|
174103
|
+
this._shouldEmitClose = true;
|
|
174104
|
+
}
|
|
174105
|
+
} else {
|
|
174106
|
+
process.nextTick(emitClose, this);
|
|
174107
|
+
}
|
|
174108
|
+
} else {
|
|
174109
|
+
const server = this._server;
|
|
174110
|
+
this._removeListeners();
|
|
174111
|
+
this._removeListeners = this._server = null;
|
|
174112
|
+
server.close(() => {
|
|
174113
|
+
emitClose(this);
|
|
174114
|
+
});
|
|
174115
|
+
}
|
|
174116
|
+
}
|
|
174117
|
+
shouldHandle(req) {
|
|
174118
|
+
if (this.options.path) {
|
|
174119
|
+
const index = req.url.indexOf("?");
|
|
174120
|
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
174121
|
+
if (pathname !== this.options.path)
|
|
174122
|
+
return false;
|
|
174123
|
+
}
|
|
174124
|
+
return true;
|
|
174125
|
+
}
|
|
174126
|
+
handleUpgrade(req, socket, head, cb) {
|
|
174127
|
+
socket.on("error", socketOnError);
|
|
174128
|
+
const key = req.headers["sec-websocket-key"];
|
|
174129
|
+
const upgrade = req.headers.upgrade;
|
|
174130
|
+
const version = +req.headers["sec-websocket-version"];
|
|
174131
|
+
if (req.method !== "GET") {
|
|
174132
|
+
const message = "Invalid HTTP method";
|
|
174133
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
174134
|
+
return;
|
|
174135
|
+
}
|
|
174136
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
174137
|
+
const message = "Invalid Upgrade header";
|
|
174138
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174139
|
+
return;
|
|
174140
|
+
}
|
|
174141
|
+
if (key === undefined || !keyRegex.test(key)) {
|
|
174142
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
174143
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174144
|
+
return;
|
|
174145
|
+
}
|
|
174146
|
+
if (version !== 13 && version !== 8) {
|
|
174147
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
174148
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
174149
|
+
"Sec-WebSocket-Version": "13, 8"
|
|
174150
|
+
});
|
|
174151
|
+
return;
|
|
174152
|
+
}
|
|
174153
|
+
if (!this.shouldHandle(req)) {
|
|
174154
|
+
abortHandshake(socket, 400);
|
|
174155
|
+
return;
|
|
174156
|
+
}
|
|
174157
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
174158
|
+
let protocols = new Set;
|
|
174159
|
+
if (secWebSocketProtocol !== undefined) {
|
|
174160
|
+
try {
|
|
174161
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
174162
|
+
} catch (err) {
|
|
174163
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
174164
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174165
|
+
return;
|
|
174166
|
+
}
|
|
174167
|
+
}
|
|
174168
|
+
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
174169
|
+
const extensions = {};
|
|
174170
|
+
if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
|
|
174171
|
+
const perMessageDeflate = new PerMessageDeflate({
|
|
174172
|
+
...this.options.perMessageDeflate,
|
|
174173
|
+
isServer: true,
|
|
174174
|
+
maxPayload: this.options.maxPayload
|
|
174175
|
+
});
|
|
174176
|
+
try {
|
|
174177
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
174178
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
174179
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
174180
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
174181
|
+
}
|
|
174182
|
+
} catch (err) {
|
|
174183
|
+
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
174184
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174185
|
+
return;
|
|
174186
|
+
}
|
|
174187
|
+
}
|
|
174188
|
+
if (this.options.verifyClient) {
|
|
174189
|
+
const info = {
|
|
174190
|
+
origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
174191
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
174192
|
+
req
|
|
174193
|
+
};
|
|
174194
|
+
if (this.options.verifyClient.length === 2) {
|
|
174195
|
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
174196
|
+
if (!verified) {
|
|
174197
|
+
return abortHandshake(socket, code || 401, message, headers);
|
|
174198
|
+
}
|
|
174199
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
174200
|
+
});
|
|
174201
|
+
return;
|
|
174202
|
+
}
|
|
174203
|
+
if (!this.options.verifyClient(info))
|
|
174204
|
+
return abortHandshake(socket, 401);
|
|
174205
|
+
}
|
|
174206
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
174207
|
+
}
|
|
174208
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
174209
|
+
if (!socket.readable || !socket.writable)
|
|
174210
|
+
return socket.destroy();
|
|
174211
|
+
if (socket[kWebSocket]) {
|
|
174212
|
+
throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
|
|
174213
|
+
}
|
|
174214
|
+
if (this._state > RUNNING)
|
|
174215
|
+
return abortHandshake(socket, 503);
|
|
174216
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
174217
|
+
const headers = [
|
|
174218
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
174219
|
+
"Upgrade: websocket",
|
|
174220
|
+
"Connection: Upgrade",
|
|
174221
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
174222
|
+
];
|
|
174223
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
174224
|
+
if (protocols.size) {
|
|
174225
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
174226
|
+
if (protocol) {
|
|
174227
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
174228
|
+
ws._protocol = protocol;
|
|
174229
|
+
}
|
|
174230
|
+
}
|
|
174231
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
174232
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
174233
|
+
const value = extension.format({
|
|
174234
|
+
[PerMessageDeflate.extensionName]: [params]
|
|
174235
|
+
});
|
|
174236
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
174237
|
+
ws._extensions = extensions;
|
|
174238
|
+
}
|
|
174239
|
+
this.emit("headers", headers, req);
|
|
174240
|
+
socket.write(headers.concat(`\r
|
|
174241
|
+
`).join(`\r
|
|
174242
|
+
`));
|
|
174243
|
+
socket.removeListener("error", socketOnError);
|
|
174244
|
+
ws.setSocket(socket, head, {
|
|
174245
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
174246
|
+
maxBufferedChunks: this.options.maxBufferedChunks,
|
|
174247
|
+
maxFragments: this.options.maxFragments,
|
|
174248
|
+
maxPayload: this.options.maxPayload,
|
|
174249
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
174250
|
+
});
|
|
174251
|
+
if (this.clients) {
|
|
174252
|
+
this.clients.add(ws);
|
|
174253
|
+
ws.on("close", () => {
|
|
174254
|
+
this.clients.delete(ws);
|
|
174255
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
174256
|
+
process.nextTick(emitClose, this);
|
|
174257
|
+
}
|
|
174258
|
+
});
|
|
174259
|
+
}
|
|
174260
|
+
cb(ws, req);
|
|
174261
|
+
}
|
|
174262
|
+
}
|
|
174263
|
+
module.exports = WebSocketServer;
|
|
174264
|
+
function addListeners(server, map) {
|
|
174265
|
+
for (const event of Object.keys(map))
|
|
174266
|
+
server.on(event, map[event]);
|
|
174267
|
+
return function removeListeners() {
|
|
174268
|
+
for (const event of Object.keys(map)) {
|
|
174269
|
+
server.removeListener(event, map[event]);
|
|
174270
|
+
}
|
|
174271
|
+
};
|
|
174272
|
+
}
|
|
174273
|
+
function emitClose(server) {
|
|
174274
|
+
server._state = CLOSED;
|
|
174275
|
+
server.emit("close");
|
|
174276
|
+
}
|
|
174277
|
+
function socketOnError() {
|
|
174278
|
+
this.destroy();
|
|
174279
|
+
}
|
|
174280
|
+
function abortHandshake(socket, code, message, headers) {
|
|
174281
|
+
message = message || http.STATUS_CODES[code];
|
|
174282
|
+
headers = {
|
|
174283
|
+
Connection: "close",
|
|
174284
|
+
"Content-Type": "text/html",
|
|
174285
|
+
"Content-Length": Buffer.byteLength(message),
|
|
174286
|
+
...headers
|
|
174287
|
+
};
|
|
174288
|
+
socket.once("finish", socket.destroy);
|
|
174289
|
+
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
174290
|
+
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
|
|
174291
|
+
`) + `\r
|
|
174292
|
+
\r
|
|
174293
|
+
` + message);
|
|
174294
|
+
}
|
|
174295
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
174296
|
+
if (server.listenerCount("wsClientError")) {
|
|
174297
|
+
const err = new Error(message);
|
|
174298
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
174299
|
+
server.emit("wsClientError", err, socket, req);
|
|
174300
|
+
} else {
|
|
174301
|
+
abortHandshake(socket, code, message, headers);
|
|
174302
|
+
}
|
|
174303
|
+
}
|
|
174304
|
+
});
|
|
174305
|
+
|
|
171423
174306
|
// ../../node_modules/@seald-io/nedb/lib/utils.js
|
|
171424
174307
|
var require_utils11 = __commonJS(function(exports, module) {
|
|
171425
174308
|
var uniq = (array, iteratee) => {
|
|
@@ -193410,7 +196293,7 @@ var require_polling_jsonp = __commonJS(function(exports) {
|
|
|
193410
196293
|
});
|
|
193411
196294
|
|
|
193412
196295
|
// ../../node_modules/engine.io/build/transports/websocket.js
|
|
193413
|
-
var
|
|
196296
|
+
var require_websocket2 = __commonJS(function(exports) {
|
|
193414
196297
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
193415
196298
|
exports.WebSocket = undefined;
|
|
193416
196299
|
var transport_1 = require_transport();
|
|
@@ -193549,7 +196432,7 @@ var require_transports = __commonJS(function(exports) {
|
|
|
193549
196432
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
193550
196433
|
var polling_1 = require_polling();
|
|
193551
196434
|
var polling_jsonp_1 = require_polling_jsonp();
|
|
193552
|
-
var websocket_1 =
|
|
196435
|
+
var websocket_1 = require_websocket2();
|
|
193553
196436
|
var webtransport_1 = require_webtransport();
|
|
193554
196437
|
exports.default = {
|
|
193555
196438
|
polling,
|
|
@@ -193897,7 +196780,7 @@ var require_socket = __commonJS(function(exports) {
|
|
|
193897
196780
|
});
|
|
193898
196781
|
|
|
193899
196782
|
// ../../node_modules/engine.io/node_modules/ws/lib/constants.js
|
|
193900
|
-
var
|
|
196783
|
+
var require_constants7 = __commonJS(function(exports, module) {
|
|
193901
196784
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
193902
196785
|
var hasBlob = typeof Blob !== "undefined";
|
|
193903
196786
|
if (hasBlob)
|
|
@@ -193916,8 +196799,8 @@ var require_constants6 = __commonJS(function(exports, module) {
|
|
|
193916
196799
|
});
|
|
193917
196800
|
|
|
193918
196801
|
// ../../node_modules/engine.io/node_modules/ws/lib/buffer-util.js
|
|
193919
|
-
var
|
|
193920
|
-
var { EMPTY_BUFFER } =
|
|
196802
|
+
var require_buffer_util2 = __commonJS(function(exports, module) {
|
|
196803
|
+
var { EMPTY_BUFFER } = require_constants7();
|
|
193921
196804
|
var FastBuffer = Buffer[Symbol.species];
|
|
193922
196805
|
function concat(list, totalLength) {
|
|
193923
196806
|
if (list.length === 0)
|
|
@@ -193994,7 +196877,7 @@ var require_buffer_util = __commonJS(function(exports, module) {
|
|
|
193994
196877
|
});
|
|
193995
196878
|
|
|
193996
196879
|
// ../../node_modules/engine.io/node_modules/ws/lib/limiter.js
|
|
193997
|
-
var
|
|
196880
|
+
var require_limiter2 = __commonJS(function(exports, module) {
|
|
193998
196881
|
var kDone = Symbol("kDone");
|
|
193999
196882
|
var kRun = Symbol("kRun");
|
|
194000
196883
|
|
|
@@ -194026,11 +196909,11 @@ var require_limiter = __commonJS(function(exports, module) {
|
|
|
194026
196909
|
});
|
|
194027
196910
|
|
|
194028
196911
|
// ../../node_modules/engine.io/node_modules/ws/lib/permessage-deflate.js
|
|
194029
|
-
var
|
|
196912
|
+
var require_permessage_deflate2 = __commonJS(function(exports, module) {
|
|
194030
196913
|
var zlib = __require("zlib");
|
|
194031
|
-
var bufferUtil =
|
|
194032
|
-
var Limiter =
|
|
194033
|
-
var { kStatusCode } =
|
|
196914
|
+
var bufferUtil = require_buffer_util2();
|
|
196915
|
+
var Limiter = require_limiter2();
|
|
196916
|
+
var { kStatusCode } = require_constants7();
|
|
194034
196917
|
var FastBuffer = Buffer[Symbol.species];
|
|
194035
196918
|
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
194036
196919
|
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
@@ -194290,9 +197173,9 @@ var require_permessage_deflate = __commonJS(function(exports, module) {
|
|
|
194290
197173
|
});
|
|
194291
197174
|
|
|
194292
197175
|
// ../../node_modules/engine.io/node_modules/ws/lib/validation.js
|
|
194293
|
-
var
|
|
197176
|
+
var require_validation2 = __commonJS(function(exports, module) {
|
|
194294
197177
|
var { isUtf8 } = __require("buffer");
|
|
194295
|
-
var { hasBlob } =
|
|
197178
|
+
var { hasBlob } = require_constants7();
|
|
194296
197179
|
var tokenChars = [
|
|
194297
197180
|
0,
|
|
194298
197181
|
0,
|
|
@@ -194477,17 +197360,17 @@ var require_validation = __commonJS(function(exports, module) {
|
|
|
194477
197360
|
});
|
|
194478
197361
|
|
|
194479
197362
|
// ../../node_modules/engine.io/node_modules/ws/lib/receiver.js
|
|
194480
|
-
var
|
|
197363
|
+
var require_receiver2 = __commonJS(function(exports, module) {
|
|
194481
197364
|
var { Writable } = __require("stream");
|
|
194482
|
-
var PerMessageDeflate =
|
|
197365
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
194483
197366
|
var {
|
|
194484
197367
|
BINARY_TYPES,
|
|
194485
197368
|
EMPTY_BUFFER,
|
|
194486
197369
|
kStatusCode,
|
|
194487
197370
|
kWebSocket
|
|
194488
|
-
} =
|
|
194489
|
-
var { concat, toArrayBuffer, unmask } =
|
|
194490
|
-
var { isValidStatusCode, isValidUTF8 } =
|
|
197371
|
+
} = require_constants7();
|
|
197372
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util2();
|
|
197373
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation2();
|
|
194491
197374
|
var FastBuffer = Buffer[Symbol.species];
|
|
194492
197375
|
var GET_INFO = 0;
|
|
194493
197376
|
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
@@ -194858,13 +197741,13 @@ var require_receiver = __commonJS(function(exports, module) {
|
|
|
194858
197741
|
});
|
|
194859
197742
|
|
|
194860
197743
|
// ../../node_modules/engine.io/node_modules/ws/lib/sender.js
|
|
194861
|
-
var
|
|
197744
|
+
var require_sender2 = __commonJS(function(exports, module) {
|
|
194862
197745
|
var { Duplex } = __require("stream");
|
|
194863
197746
|
var { randomFillSync } = __require("crypto");
|
|
194864
|
-
var PerMessageDeflate =
|
|
194865
|
-
var { EMPTY_BUFFER, kWebSocket, NOOP } =
|
|
194866
|
-
var { isBlob, isValidStatusCode } =
|
|
194867
|
-
var { mask: applyMask, toBuffer } =
|
|
197747
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
197748
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants7();
|
|
197749
|
+
var { isBlob, isValidStatusCode } = require_validation2();
|
|
197750
|
+
var { mask: applyMask, toBuffer } = require_buffer_util2();
|
|
194868
197751
|
var kByteLength = Symbol("kByteLength");
|
|
194869
197752
|
var maskBuffer = Buffer.alloc(4);
|
|
194870
197753
|
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
@@ -195212,8 +198095,8 @@ var require_sender = __commonJS(function(exports, module) {
|
|
|
195212
198095
|
});
|
|
195213
198096
|
|
|
195214
198097
|
// ../../node_modules/engine.io/node_modules/ws/lib/event-target.js
|
|
195215
|
-
var
|
|
195216
|
-
var { kForOnEventAttribute, kListener } =
|
|
198098
|
+
var require_event_target2 = __commonJS(function(exports, module) {
|
|
198099
|
+
var { kForOnEventAttribute, kListener } = require_constants7();
|
|
195217
198100
|
var kCode = Symbol("kCode");
|
|
195218
198101
|
var kData = Symbol("kData");
|
|
195219
198102
|
var kError = Symbol("kError");
|
|
@@ -195363,8 +198246,8 @@ var require_event_target = __commonJS(function(exports, module) {
|
|
|
195363
198246
|
});
|
|
195364
198247
|
|
|
195365
198248
|
// ../../node_modules/engine.io/node_modules/ws/lib/extension.js
|
|
195366
|
-
var
|
|
195367
|
-
var { tokenChars } =
|
|
198249
|
+
var require_extension2 = __commonJS(function(exports, module) {
|
|
198250
|
+
var { tokenChars } = require_validation2();
|
|
195368
198251
|
function push(dest, name, elem) {
|
|
195369
198252
|
if (dest[name] === undefined)
|
|
195370
198253
|
dest[name] = [elem];
|
|
@@ -195528,7 +198411,7 @@ var require_extension = __commonJS(function(exports, module) {
|
|
|
195528
198411
|
});
|
|
195529
198412
|
|
|
195530
198413
|
// ../../node_modules/engine.io/node_modules/ws/lib/websocket.js
|
|
195531
|
-
var
|
|
198414
|
+
var require_websocket3 = __commonJS(function(exports, module) {
|
|
195532
198415
|
var EventEmitter = __require("events");
|
|
195533
198416
|
var https = __require("https");
|
|
195534
198417
|
var http = __require("http");
|
|
@@ -195537,10 +198420,10 @@ var require_websocket2 = __commonJS(function(exports, module) {
|
|
|
195537
198420
|
var { randomBytes, createHash } = __require("crypto");
|
|
195538
198421
|
var { Duplex, Readable } = __require("stream");
|
|
195539
198422
|
var { URL: URL2 } = __require("url");
|
|
195540
|
-
var PerMessageDeflate =
|
|
195541
|
-
var Receiver =
|
|
195542
|
-
var Sender =
|
|
195543
|
-
var { isBlob } =
|
|
198423
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
198424
|
+
var Receiver = require_receiver2();
|
|
198425
|
+
var Sender = require_sender2();
|
|
198426
|
+
var { isBlob } = require_validation2();
|
|
195544
198427
|
var {
|
|
195545
198428
|
BINARY_TYPES,
|
|
195546
198429
|
EMPTY_BUFFER,
|
|
@@ -195550,12 +198433,12 @@ var require_websocket2 = __commonJS(function(exports, module) {
|
|
|
195550
198433
|
kStatusCode,
|
|
195551
198434
|
kWebSocket,
|
|
195552
198435
|
NOOP
|
|
195553
|
-
} =
|
|
198436
|
+
} = require_constants7();
|
|
195554
198437
|
var {
|
|
195555
198438
|
EventTarget: { addEventListener, removeEventListener }
|
|
195556
|
-
} =
|
|
195557
|
-
var { format, parse } =
|
|
195558
|
-
var { toBuffer } =
|
|
198439
|
+
} = require_event_target2();
|
|
198440
|
+
var { format, parse } = require_extension2();
|
|
198441
|
+
var { toBuffer } = require_buffer_util2();
|
|
195559
198442
|
var closeTimeout = 30 * 1000;
|
|
195560
198443
|
var kAborted = Symbol("kAborted");
|
|
195561
198444
|
var protocolVersions = [8, 13];
|
|
@@ -196287,8 +199170,8 @@ var require_websocket2 = __commonJS(function(exports, module) {
|
|
|
196287
199170
|
});
|
|
196288
199171
|
|
|
196289
199172
|
// ../../node_modules/engine.io/node_modules/ws/lib/stream.js
|
|
196290
|
-
var
|
|
196291
|
-
var WebSocket =
|
|
199173
|
+
var require_stream7 = __commonJS(function(exports, module) {
|
|
199174
|
+
var WebSocket = require_websocket3();
|
|
196292
199175
|
var { Duplex } = __require("stream");
|
|
196293
199176
|
function emitClose(stream) {
|
|
196294
199177
|
stream.emit("close");
|
|
@@ -196390,8 +199273,8 @@ var require_stream6 = __commonJS(function(exports, module) {
|
|
|
196390
199273
|
});
|
|
196391
199274
|
|
|
196392
199275
|
// ../../node_modules/engine.io/node_modules/ws/lib/subprotocol.js
|
|
196393
|
-
var
|
|
196394
|
-
var { tokenChars } =
|
|
199276
|
+
var require_subprotocol2 = __commonJS(function(exports, module) {
|
|
199277
|
+
var { tokenChars } = require_validation2();
|
|
196395
199278
|
function parse(header) {
|
|
196396
199279
|
const protocols = new Set;
|
|
196397
199280
|
let start = -1;
|
|
@@ -196435,16 +199318,16 @@ var require_subprotocol = __commonJS(function(exports, module) {
|
|
|
196435
199318
|
});
|
|
196436
199319
|
|
|
196437
199320
|
// ../../node_modules/engine.io/node_modules/ws/lib/websocket-server.js
|
|
196438
|
-
var
|
|
199321
|
+
var require_websocket_server2 = __commonJS(function(exports, module) {
|
|
196439
199322
|
var EventEmitter = __require("events");
|
|
196440
199323
|
var http = __require("http");
|
|
196441
199324
|
var { Duplex } = __require("stream");
|
|
196442
199325
|
var { createHash } = __require("crypto");
|
|
196443
|
-
var extension =
|
|
196444
|
-
var PerMessageDeflate =
|
|
196445
|
-
var subprotocol =
|
|
196446
|
-
var WebSocket =
|
|
196447
|
-
var { GUID, kWebSocket } =
|
|
199326
|
+
var extension = require_extension2();
|
|
199327
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
199328
|
+
var subprotocol = require_subprotocol2();
|
|
199329
|
+
var WebSocket = require_websocket3();
|
|
199330
|
+
var { GUID, kWebSocket } = require_constants7();
|
|
196448
199331
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
196449
199332
|
var RUNNING = 0;
|
|
196450
199333
|
var CLOSING = 1;
|
|
@@ -196737,11 +199620,11 @@ var require_websocket_server = __commonJS(function(exports, module) {
|
|
|
196737
199620
|
|
|
196738
199621
|
// ../../node_modules/engine.io/node_modules/ws/index.js
|
|
196739
199622
|
var require_ws = __commonJS(function(exports, module) {
|
|
196740
|
-
var WebSocket =
|
|
196741
|
-
WebSocket.createWebSocketStream =
|
|
196742
|
-
WebSocket.Server =
|
|
196743
|
-
WebSocket.Receiver =
|
|
196744
|
-
WebSocket.Sender =
|
|
199623
|
+
var WebSocket = require_websocket3();
|
|
199624
|
+
WebSocket.createWebSocketStream = require_stream7();
|
|
199625
|
+
WebSocket.Server = require_websocket_server2();
|
|
199626
|
+
WebSocket.Receiver = require_receiver2();
|
|
199627
|
+
WebSocket.Sender = require_sender2();
|
|
196745
199628
|
WebSocket.WebSocket = WebSocket;
|
|
196746
199629
|
WebSocket.WebSocketServer = WebSocket.Server;
|
|
196747
199630
|
module.exports = WebSocket;
|
|
@@ -197864,7 +200747,7 @@ var require_polling2 = __commonJS(function(exports) {
|
|
|
197864
200747
|
});
|
|
197865
200748
|
|
|
197866
200749
|
// ../../node_modules/engine.io/build/transports-uws/websocket.js
|
|
197867
|
-
var
|
|
200750
|
+
var require_websocket4 = __commonJS(function(exports) {
|
|
197868
200751
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
197869
200752
|
exports.WebSocket = undefined;
|
|
197870
200753
|
var transport_1 = require_transport();
|
|
@@ -197919,7 +200802,7 @@ var require_websocket3 = __commonJS(function(exports) {
|
|
|
197919
200802
|
var require_transports_uws = __commonJS(function(exports) {
|
|
197920
200803
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
197921
200804
|
var polling_1 = require_polling2();
|
|
197922
|
-
var websocket_1 =
|
|
200805
|
+
var websocket_1 = require_websocket4();
|
|
197923
200806
|
exports.default = {
|
|
197924
200807
|
polling: polling_1.Polling,
|
|
197925
200808
|
websocket: websocket_1.WebSocket
|
|
@@ -199725,7 +202608,7 @@ var require_yeast = __commonJS(function(exports) {
|
|
|
199725
202608
|
});
|
|
199726
202609
|
|
|
199727
202610
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/constants.js
|
|
199728
|
-
var
|
|
202611
|
+
var require_constants8 = __commonJS(function(exports, module) {
|
|
199729
202612
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
199730
202613
|
var hasBlob = typeof Blob !== "undefined";
|
|
199731
202614
|
if (hasBlob)
|
|
@@ -199744,8 +202627,8 @@ var require_constants7 = __commonJS(function(exports, module) {
|
|
|
199744
202627
|
});
|
|
199745
202628
|
|
|
199746
202629
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/buffer-util.js
|
|
199747
|
-
var
|
|
199748
|
-
var { EMPTY_BUFFER } =
|
|
202630
|
+
var require_buffer_util3 = __commonJS(function(exports, module) {
|
|
202631
|
+
var { EMPTY_BUFFER } = require_constants8();
|
|
199749
202632
|
var FastBuffer = Buffer[Symbol.species];
|
|
199750
202633
|
function concat(list, totalLength) {
|
|
199751
202634
|
if (list.length === 0)
|
|
@@ -199822,7 +202705,7 @@ var require_buffer_util2 = __commonJS(function(exports, module) {
|
|
|
199822
202705
|
});
|
|
199823
202706
|
|
|
199824
202707
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/limiter.js
|
|
199825
|
-
var
|
|
202708
|
+
var require_limiter3 = __commonJS(function(exports, module) {
|
|
199826
202709
|
var kDone = Symbol("kDone");
|
|
199827
202710
|
var kRun = Symbol("kRun");
|
|
199828
202711
|
|
|
@@ -199854,11 +202737,11 @@ var require_limiter2 = __commonJS(function(exports, module) {
|
|
|
199854
202737
|
});
|
|
199855
202738
|
|
|
199856
202739
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/permessage-deflate.js
|
|
199857
|
-
var
|
|
202740
|
+
var require_permessage_deflate3 = __commonJS(function(exports, module) {
|
|
199858
202741
|
var zlib = __require("zlib");
|
|
199859
|
-
var bufferUtil =
|
|
199860
|
-
var Limiter =
|
|
199861
|
-
var { kStatusCode } =
|
|
202742
|
+
var bufferUtil = require_buffer_util3();
|
|
202743
|
+
var Limiter = require_limiter3();
|
|
202744
|
+
var { kStatusCode } = require_constants8();
|
|
199862
202745
|
var FastBuffer = Buffer[Symbol.species];
|
|
199863
202746
|
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
199864
202747
|
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
@@ -200118,9 +203001,9 @@ var require_permessage_deflate2 = __commonJS(function(exports, module) {
|
|
|
200118
203001
|
});
|
|
200119
203002
|
|
|
200120
203003
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/validation.js
|
|
200121
|
-
var
|
|
203004
|
+
var require_validation3 = __commonJS(function(exports, module) {
|
|
200122
203005
|
var { isUtf8 } = __require("buffer");
|
|
200123
|
-
var { hasBlob } =
|
|
203006
|
+
var { hasBlob } = require_constants8();
|
|
200124
203007
|
var tokenChars = [
|
|
200125
203008
|
0,
|
|
200126
203009
|
0,
|
|
@@ -200305,17 +203188,17 @@ var require_validation2 = __commonJS(function(exports, module) {
|
|
|
200305
203188
|
});
|
|
200306
203189
|
|
|
200307
203190
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/receiver.js
|
|
200308
|
-
var
|
|
203191
|
+
var require_receiver3 = __commonJS(function(exports, module) {
|
|
200309
203192
|
var { Writable } = __require("stream");
|
|
200310
|
-
var PerMessageDeflate =
|
|
203193
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
200311
203194
|
var {
|
|
200312
203195
|
BINARY_TYPES,
|
|
200313
203196
|
EMPTY_BUFFER,
|
|
200314
203197
|
kStatusCode,
|
|
200315
203198
|
kWebSocket
|
|
200316
|
-
} =
|
|
200317
|
-
var { concat, toArrayBuffer, unmask } =
|
|
200318
|
-
var { isValidStatusCode, isValidUTF8 } =
|
|
203199
|
+
} = require_constants8();
|
|
203200
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util3();
|
|
203201
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation3();
|
|
200319
203202
|
var FastBuffer = Buffer[Symbol.species];
|
|
200320
203203
|
var GET_INFO = 0;
|
|
200321
203204
|
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
@@ -200686,13 +203569,13 @@ var require_receiver2 = __commonJS(function(exports, module) {
|
|
|
200686
203569
|
});
|
|
200687
203570
|
|
|
200688
203571
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/sender.js
|
|
200689
|
-
var
|
|
203572
|
+
var require_sender3 = __commonJS(function(exports, module) {
|
|
200690
203573
|
var { Duplex } = __require("stream");
|
|
200691
203574
|
var { randomFillSync } = __require("crypto");
|
|
200692
|
-
var PerMessageDeflate =
|
|
200693
|
-
var { EMPTY_BUFFER, kWebSocket, NOOP } =
|
|
200694
|
-
var { isBlob, isValidStatusCode } =
|
|
200695
|
-
var { mask: applyMask, toBuffer } =
|
|
203575
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
203576
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants8();
|
|
203577
|
+
var { isBlob, isValidStatusCode } = require_validation3();
|
|
203578
|
+
var { mask: applyMask, toBuffer } = require_buffer_util3();
|
|
200696
203579
|
var kByteLength = Symbol("kByteLength");
|
|
200697
203580
|
var maskBuffer = Buffer.alloc(4);
|
|
200698
203581
|
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
@@ -201040,8 +203923,8 @@ var require_sender2 = __commonJS(function(exports, module) {
|
|
|
201040
203923
|
});
|
|
201041
203924
|
|
|
201042
203925
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/event-target.js
|
|
201043
|
-
var
|
|
201044
|
-
var { kForOnEventAttribute, kListener } =
|
|
203926
|
+
var require_event_target3 = __commonJS(function(exports, module) {
|
|
203927
|
+
var { kForOnEventAttribute, kListener } = require_constants8();
|
|
201045
203928
|
var kCode = Symbol("kCode");
|
|
201046
203929
|
var kData = Symbol("kData");
|
|
201047
203930
|
var kError = Symbol("kError");
|
|
@@ -201191,8 +204074,8 @@ var require_event_target2 = __commonJS(function(exports, module) {
|
|
|
201191
204074
|
});
|
|
201192
204075
|
|
|
201193
204076
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/extension.js
|
|
201194
|
-
var
|
|
201195
|
-
var { tokenChars } =
|
|
204077
|
+
var require_extension3 = __commonJS(function(exports, module) {
|
|
204078
|
+
var { tokenChars } = require_validation3();
|
|
201196
204079
|
function push(dest, name, elem) {
|
|
201197
204080
|
if (dest[name] === undefined)
|
|
201198
204081
|
dest[name] = [elem];
|
|
@@ -201356,7 +204239,7 @@ var require_extension2 = __commonJS(function(exports, module) {
|
|
|
201356
204239
|
});
|
|
201357
204240
|
|
|
201358
204241
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/websocket.js
|
|
201359
|
-
var
|
|
204242
|
+
var require_websocket5 = __commonJS(function(exports, module) {
|
|
201360
204243
|
var EventEmitter = __require("events");
|
|
201361
204244
|
var https = __require("https");
|
|
201362
204245
|
var http = __require("http");
|
|
@@ -201365,10 +204248,10 @@ var require_websocket4 = __commonJS(function(exports, module) {
|
|
|
201365
204248
|
var { randomBytes, createHash } = __require("crypto");
|
|
201366
204249
|
var { Duplex, Readable } = __require("stream");
|
|
201367
204250
|
var { URL: URL2 } = __require("url");
|
|
201368
|
-
var PerMessageDeflate =
|
|
201369
|
-
var Receiver =
|
|
201370
|
-
var Sender =
|
|
201371
|
-
var { isBlob } =
|
|
204251
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
204252
|
+
var Receiver = require_receiver3();
|
|
204253
|
+
var Sender = require_sender3();
|
|
204254
|
+
var { isBlob } = require_validation3();
|
|
201372
204255
|
var {
|
|
201373
204256
|
BINARY_TYPES,
|
|
201374
204257
|
EMPTY_BUFFER,
|
|
@@ -201378,12 +204261,12 @@ var require_websocket4 = __commonJS(function(exports, module) {
|
|
|
201378
204261
|
kStatusCode,
|
|
201379
204262
|
kWebSocket,
|
|
201380
204263
|
NOOP
|
|
201381
|
-
} =
|
|
204264
|
+
} = require_constants8();
|
|
201382
204265
|
var {
|
|
201383
204266
|
EventTarget: { addEventListener, removeEventListener }
|
|
201384
|
-
} =
|
|
201385
|
-
var { format, parse } =
|
|
201386
|
-
var { toBuffer } =
|
|
204267
|
+
} = require_event_target3();
|
|
204268
|
+
var { format, parse } = require_extension3();
|
|
204269
|
+
var { toBuffer } = require_buffer_util3();
|
|
201387
204270
|
var closeTimeout = 30 * 1000;
|
|
201388
204271
|
var kAborted = Symbol("kAborted");
|
|
201389
204272
|
var protocolVersions = [8, 13];
|
|
@@ -202115,8 +204998,8 @@ var require_websocket4 = __commonJS(function(exports, module) {
|
|
|
202115
204998
|
});
|
|
202116
204999
|
|
|
202117
205000
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/stream.js
|
|
202118
|
-
var
|
|
202119
|
-
var WebSocket =
|
|
205001
|
+
var require_stream8 = __commonJS(function(exports, module) {
|
|
205002
|
+
var WebSocket = require_websocket5();
|
|
202120
205003
|
var { Duplex } = __require("stream");
|
|
202121
205004
|
function emitClose(stream) {
|
|
202122
205005
|
stream.emit("close");
|
|
@@ -202218,8 +205101,8 @@ var require_stream7 = __commonJS(function(exports, module) {
|
|
|
202218
205101
|
});
|
|
202219
205102
|
|
|
202220
205103
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/subprotocol.js
|
|
202221
|
-
var
|
|
202222
|
-
var { tokenChars } =
|
|
205104
|
+
var require_subprotocol3 = __commonJS(function(exports, module) {
|
|
205105
|
+
var { tokenChars } = require_validation3();
|
|
202223
205106
|
function parse(header) {
|
|
202224
205107
|
const protocols = new Set;
|
|
202225
205108
|
let start = -1;
|
|
@@ -202263,16 +205146,16 @@ var require_subprotocol2 = __commonJS(function(exports, module) {
|
|
|
202263
205146
|
});
|
|
202264
205147
|
|
|
202265
205148
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/websocket-server.js
|
|
202266
|
-
var
|
|
205149
|
+
var require_websocket_server3 = __commonJS(function(exports, module) {
|
|
202267
205150
|
var EventEmitter = __require("events");
|
|
202268
205151
|
var http = __require("http");
|
|
202269
205152
|
var { Duplex } = __require("stream");
|
|
202270
205153
|
var { createHash } = __require("crypto");
|
|
202271
|
-
var extension =
|
|
202272
|
-
var PerMessageDeflate =
|
|
202273
|
-
var subprotocol =
|
|
202274
|
-
var WebSocket =
|
|
202275
|
-
var { GUID, kWebSocket } =
|
|
205154
|
+
var extension = require_extension3();
|
|
205155
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
205156
|
+
var subprotocol = require_subprotocol3();
|
|
205157
|
+
var WebSocket = require_websocket5();
|
|
205158
|
+
var { GUID, kWebSocket } = require_constants8();
|
|
202276
205159
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
202277
205160
|
var RUNNING = 0;
|
|
202278
205161
|
var CLOSING = 1;
|
|
@@ -202565,11 +205448,11 @@ var require_websocket_server2 = __commonJS(function(exports, module) {
|
|
|
202565
205448
|
|
|
202566
205449
|
// ../../node_modules/socket.io-adapter/node_modules/ws/index.js
|
|
202567
205450
|
var require_ws2 = __commonJS(function(exports, module) {
|
|
202568
|
-
var WebSocket =
|
|
202569
|
-
WebSocket.createWebSocketStream =
|
|
202570
|
-
WebSocket.Server =
|
|
202571
|
-
WebSocket.Receiver =
|
|
202572
|
-
WebSocket.Sender =
|
|
205451
|
+
var WebSocket = require_websocket5();
|
|
205452
|
+
WebSocket.createWebSocketStream = require_stream8();
|
|
205453
|
+
WebSocket.Server = require_websocket_server3();
|
|
205454
|
+
WebSocket.Receiver = require_receiver3();
|
|
205455
|
+
WebSocket.Sender = require_sender3();
|
|
202573
205456
|
WebSocket.WebSocket = WebSocket;
|
|
202574
205457
|
WebSocket.WebSocketServer = WebSocket.Server;
|
|
202575
205458
|
module.exports = WebSocket;
|
|
@@ -236596,6 +239479,15 @@ var FinalizeDeploymentResponseSchema = object({
|
|
|
236596
239479
|
}).transform((data) => ({
|
|
236597
239480
|
deploymentId: data.deployment_id
|
|
236598
239481
|
}));
|
|
239482
|
+
var PublishDeploymentResponseSchema = object({
|
|
239483
|
+
git_hash: string2(),
|
|
239484
|
+
deployed_at: string2(),
|
|
239485
|
+
app_url: string2()
|
|
239486
|
+
}).transform((data) => ({
|
|
239487
|
+
gitHash: data.git_hash,
|
|
239488
|
+
deployedAt: data.deployed_at,
|
|
239489
|
+
appUrl: data.app_url
|
|
239490
|
+
}));
|
|
236599
239491
|
|
|
236600
239492
|
// src/core/project/api.ts
|
|
236601
239493
|
var PUBLIC_SETTINGS = {
|
|
@@ -239265,7 +242157,7 @@ import { join as join13 } from "node:path";
|
|
|
239265
242157
|
// package.json
|
|
239266
242158
|
var package_default = {
|
|
239267
242159
|
name: "base44",
|
|
239268
|
-
version: "0.1.
|
|
242160
|
+
version: "0.1.25",
|
|
239269
242161
|
description: "Base44 CLI - Unified interface for managing Base44 applications",
|
|
239270
242162
|
type: "module",
|
|
239271
242163
|
bin: {
|
|
@@ -239320,6 +242212,7 @@ var package_default = {
|
|
|
239320
242212
|
"@types/ms": "^2.1.0",
|
|
239321
242213
|
"@types/multer": "^2.0.0",
|
|
239322
242214
|
"@types/node": "^22.10.5",
|
|
242215
|
+
"@types/ws": "^8.18.1",
|
|
239323
242216
|
"@vercel/detect-agent": "^1.1.0",
|
|
239324
242217
|
chalk: "^5.6.2",
|
|
239325
242218
|
chokidar: "^5.0.0",
|
|
@@ -239354,6 +242247,7 @@ var package_default = {
|
|
|
239354
242247
|
"tmp-promise": "^3.0.3",
|
|
239355
242248
|
typescript: "^5.7.2",
|
|
239356
242249
|
vitest: "^4.0.16",
|
|
242250
|
+
ws: "8.21.0",
|
|
239357
242251
|
yaml: "^2.8.2",
|
|
239358
242252
|
zod: "^4.3.5"
|
|
239359
242253
|
},
|
|
@@ -239568,6 +242462,22 @@ async function finalizeDeployment(deploymentId, sessionId, payload) {
|
|
|
239568
242462
|
}
|
|
239569
242463
|
return result.data;
|
|
239570
242464
|
}
|
|
242465
|
+
async function publishDeployment(gitHash) {
|
|
242466
|
+
const appClient = getAppClient();
|
|
242467
|
+
let response;
|
|
242468
|
+
try {
|
|
242469
|
+
response = await appClient.post(`deployments/${gitHash}/publish`, {
|
|
242470
|
+
timeout: 120000
|
|
242471
|
+
});
|
|
242472
|
+
} catch (error) {
|
|
242473
|
+
throw await ApiError.fromHttpError(error, "publishing deployment");
|
|
242474
|
+
}
|
|
242475
|
+
const result = PublishDeploymentResponseSchema.safeParse(await response.json());
|
|
242476
|
+
if (!result.success) {
|
|
242477
|
+
throw new SchemaValidationError("Invalid response from server", result.error);
|
|
242478
|
+
}
|
|
242479
|
+
return result.data;
|
|
242480
|
+
}
|
|
239571
242481
|
// src/core/site/config.ts
|
|
239572
242482
|
async function getSiteFilePaths(outputDir) {
|
|
239573
242483
|
return await globby("**/*", {
|
|
@@ -240149,11 +243059,6 @@ async function putPresigned(upload, absolutePath) {
|
|
|
240149
243059
|
|
|
240150
243060
|
// src/core/site/deployment.ts
|
|
240151
243061
|
var NO_ASSETS = { manifest: {}, filesByHash: new Map };
|
|
240152
|
-
var DEPLOYMENTS_API_ENV = "BASE44_DEPLOYMENTS_API";
|
|
240153
|
-
function deploymentsApiEnabled(env = process.env) {
|
|
240154
|
-
const value = env[DEPLOYMENTS_API_ENV];
|
|
240155
|
-
return value === "1" || value === "true";
|
|
240156
|
-
}
|
|
240157
243062
|
async function deployToDeployments(options) {
|
|
240158
243063
|
const { projectRoot, outputDir, gitHash, concurrency, progress } = options;
|
|
240159
243064
|
const worker = await resolveWorkerBuild(projectRoot, progress);
|
|
@@ -246759,7 +249664,7 @@ async function gitHead(projectRoot) {
|
|
|
246759
249664
|
}
|
|
246760
249665
|
}
|
|
246761
249666
|
// src/core/project/deploy.ts
|
|
246762
|
-
function hasResourcesToDeploy(projectData) {
|
|
249667
|
+
async function hasResourcesToDeploy(projectData) {
|
|
246763
249668
|
const {
|
|
246764
249669
|
project,
|
|
246765
249670
|
entities,
|
|
@@ -246770,7 +249675,7 @@ function hasResourcesToDeploy(projectData) {
|
|
|
246770
249675
|
connectors,
|
|
246771
249676
|
authConfig
|
|
246772
249677
|
} = projectData;
|
|
246773
|
-
const hasSite = Boolean(project.site?.outputDirectory);
|
|
249678
|
+
const hasSite = Boolean(project.site?.outputDirectory) || Boolean(await detectFullStackArtifact(project.root));
|
|
246774
249679
|
const hasEntities = entities.length > 0;
|
|
246775
249680
|
const hasFunctions = functions.length > 0;
|
|
246776
249681
|
const hasActors = actors.length > 0;
|
|
@@ -246829,12 +249734,59 @@ async function deployAll(projectData, options) {
|
|
|
246829
249734
|
await authConfigResource.push(authConfig);
|
|
246830
249735
|
const skipConnectorSync = connectors.length === 0 && hasWorkspaceApiKeyAuth();
|
|
246831
249736
|
const connectorResults = skipConnectorSync ? [] : (await pushConnectors(connectors)).results;
|
|
246832
|
-
|
|
246833
|
-
|
|
249737
|
+
const appUrl = await deployProjectSite(project, options);
|
|
249738
|
+
return appUrl ? { appUrl, connectorResults } : { connectorResults };
|
|
249739
|
+
}
|
|
249740
|
+
async function deployProjectSite(project, options) {
|
|
249741
|
+
const outputDirectory = project.site?.outputDirectory;
|
|
249742
|
+
const outputDir = outputDirectory ? resolve5(project.root, outputDirectory) : null;
|
|
249743
|
+
if (!outputDir) {
|
|
249744
|
+
if (!await detectFullStackArtifact(project.root)) {
|
|
249745
|
+
return;
|
|
249746
|
+
}
|
|
249747
|
+
const gitHash = await resolveGitHash(project.root, options?.gitHash);
|
|
249748
|
+
return shipCommit(project.root, null, gitHash, options);
|
|
249749
|
+
}
|
|
249750
|
+
const gitHash = await resolveGitHash(project.root, options?.gitHash).catch(() => {
|
|
249751
|
+
return;
|
|
249752
|
+
});
|
|
249753
|
+
if (!gitHash) {
|
|
249754
|
+
options?.onSiteProgress?.("No commit found for this build, so it was deployed without one. Commit your work to address deployments by it.");
|
|
246834
249755
|
const { appUrl } = await deploySite(outputDir);
|
|
246835
|
-
return
|
|
249756
|
+
return appUrl;
|
|
246836
249757
|
}
|
|
246837
|
-
return
|
|
249758
|
+
return shipCommit(project.root, outputDir, gitHash, options);
|
|
249759
|
+
}
|
|
249760
|
+
async function shipCommit(projectRoot, outputDir, gitHash, options) {
|
|
249761
|
+
await deployToDeployments({
|
|
249762
|
+
projectRoot,
|
|
249763
|
+
outputDir,
|
|
249764
|
+
gitHash,
|
|
249765
|
+
progress: {
|
|
249766
|
+
onWarning: (message) => options?.onSiteProgress?.(message),
|
|
249767
|
+
onAssets: ({ totalAssets, newAssets }) => options?.onSiteProgress?.(`Found ${totalAssets} static assets (${newAssets} new)`)
|
|
249768
|
+
}
|
|
249769
|
+
});
|
|
249770
|
+
if (options?.publish === false) {
|
|
249771
|
+
return;
|
|
249772
|
+
}
|
|
249773
|
+
try {
|
|
249774
|
+
const { appUrl } = await publishDeployment(gitHash);
|
|
249775
|
+
return appUrl;
|
|
249776
|
+
} catch (error) {
|
|
249777
|
+
if (!publishesFromBuilder(error)) {
|
|
249778
|
+
throw error;
|
|
249779
|
+
}
|
|
249780
|
+
options?.onSiteProgress?.("Site deployed. This app is published from the Base44 builder, so production was left where it was.");
|
|
249781
|
+
return;
|
|
249782
|
+
}
|
|
249783
|
+
}
|
|
249784
|
+
function publishesFromBuilder(error) {
|
|
249785
|
+
if (!(error instanceof ApiError)) {
|
|
249786
|
+
return false;
|
|
249787
|
+
}
|
|
249788
|
+
const body = error.responseBody;
|
|
249789
|
+
return body?.extra_data?.code === "app_publishes_from_builder";
|
|
246838
249790
|
}
|
|
246839
249791
|
// src/core/project/target.ts
|
|
246840
249792
|
import { dirname as dirname13, join as join19, resolve as resolve6 } from "node:path";
|
|
@@ -249991,7 +252943,7 @@ async function deployAction(ctx, options = {}) {
|
|
|
249991
252943
|
throw new InvalidInputError("--yes is required in non-interactive mode");
|
|
249992
252944
|
}
|
|
249993
252945
|
const projectData = await readProjectConfig(options.projectRoot);
|
|
249994
|
-
if (!hasResourcesToDeploy(projectData)) {
|
|
252946
|
+
if (!await hasResourcesToDeploy(projectData)) {
|
|
249995
252947
|
return {
|
|
249996
252948
|
outroMessage: "No resources found to deploy"
|
|
249997
252949
|
};
|
|
@@ -250050,6 +253002,11 @@ ${summaryLines.join(`
|
|
|
250050
253002
|
const functionTotal = functions.length;
|
|
250051
253003
|
let actorCompleted = 0;
|
|
250052
253004
|
const result = await deployAll(projectData, {
|
|
253005
|
+
gitHash: options.gitHash,
|
|
253006
|
+
publish: options.publish,
|
|
253007
|
+
onSiteProgress: (message) => {
|
|
253008
|
+
log.message(theme.styles.dim(message));
|
|
253009
|
+
},
|
|
250053
253010
|
onVisibilitySet: (level) => {
|
|
250054
253011
|
log.success(`App visibility set to ${level}`);
|
|
250055
253012
|
},
|
|
@@ -250085,7 +253042,7 @@ ${summaryLines.join(`
|
|
|
250085
253042
|
return { outroMessage: "App deployed successfully" };
|
|
250086
253043
|
}
|
|
250087
253044
|
function getDeployCommand3() {
|
|
250088
|
-
return new Base44Command("deploy").description("Deploy all project resources (entities, functions, actors, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").action(deployAction);
|
|
253045
|
+
return new Base44Command("deploy").description("Deploy all project resources (entities, functions, actors, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").option("--no-publish", "Deploy the site without serving it in production yet").addOption(new Option2("--git-hash <hash>", "Commit the built site came from (defaults to the checkout's HEAD)").argParser(parseGitHash)).action(deployAction);
|
|
250089
253046
|
}
|
|
250090
253047
|
async function handleOAuthConnectors(connectorResults, isNonInteractive, options, log) {
|
|
250091
253048
|
const needsOAuth = filterPendingOAuth(connectorResults);
|
|
@@ -250106,6 +253063,12 @@ function printStripeResult(r, log) {
|
|
|
250106
253063
|
}
|
|
250107
253064
|
log.info(` Connectors dashboard: ${theme.colors.links(getConnectorsUrl())}`);
|
|
250108
253065
|
}
|
|
253066
|
+
function parseGitHash(value) {
|
|
253067
|
+
if (!isGitCommitHash(value)) {
|
|
253068
|
+
throw new InvalidArgumentError2("Expected a git commit hash (7-64 hex chars).");
|
|
253069
|
+
}
|
|
253070
|
+
return value;
|
|
253071
|
+
}
|
|
250109
253072
|
|
|
250110
253073
|
// src/cli/commands/project/app-id-options.ts
|
|
250111
253074
|
function readExplicitAppId(command) {
|
|
@@ -251410,11 +254373,20 @@ async function deployAction2(ctx, options) {
|
|
|
251410
254373
|
return { outroMessage: "Deployment cancelled" };
|
|
251411
254374
|
}
|
|
251412
254375
|
}
|
|
251413
|
-
return
|
|
254376
|
+
return deployToDeploymentsApi(ctx, project, options);
|
|
251414
254377
|
}
|
|
251415
254378
|
async function deployToDeploymentsApi(ctx, project, options) {
|
|
251416
254379
|
const { runTask, log, jsonMode } = ctx;
|
|
251417
254380
|
const projectRoot = project.root;
|
|
254381
|
+
if (!siteOutputDir(project) && !await detectFullStackArtifact(projectRoot)) {
|
|
254382
|
+
throw new ConfigNotFoundError("No site configuration found.", {
|
|
254383
|
+
hints: [
|
|
254384
|
+
{
|
|
254385
|
+
message: `Add 'site.outputDirectory' to your config.jsonc (e.g., "site": { "outputDirectory": "dist" })`
|
|
254386
|
+
}
|
|
254387
|
+
]
|
|
254388
|
+
});
|
|
254389
|
+
}
|
|
251418
254390
|
const gitHash = await resolveGitHash(projectRoot, options.gitHash);
|
|
251419
254391
|
const progressLines = [];
|
|
251420
254392
|
const warnings = [];
|
|
@@ -251446,42 +254418,24 @@ async function deployToDeploymentsApi(ctx, project, options) {
|
|
|
251446
254418
|
for (const warning of warnings) {
|
|
251447
254419
|
log.warn(warning);
|
|
251448
254420
|
}
|
|
254421
|
+
const published = options.publish ? await runTask("Publishing site...", async () => await publishDeployment(gitHash), { successMessage: "Site published", errorMessage: "Publish failed" }) : undefined;
|
|
254422
|
+
if (published) {
|
|
254423
|
+
log.message(`${theme.styles.header("App URL")}: ${theme.colors.links(published.appUrl)}`);
|
|
254424
|
+
}
|
|
251449
254425
|
return {
|
|
251450
254426
|
outroMessage: `Deployment ${deploymentId} (commit ${gitHash.slice(0, 12)})`,
|
|
251451
|
-
stdout: jsonMode ? `${JSON.stringify({ deploymentId, gitHash }, null, 2)}
|
|
254427
|
+
stdout: jsonMode ? `${JSON.stringify({ deploymentId, gitHash, published: Boolean(published) }, null, 2)}
|
|
251452
254428
|
` : undefined
|
|
251453
254429
|
};
|
|
251454
254430
|
}
|
|
251455
|
-
async function deployTarball({ runTask }, project) {
|
|
251456
|
-
const outputDir = siteOutputDir(project);
|
|
251457
|
-
if (!outputDir) {
|
|
251458
|
-
throw new ConfigNotFoundError("No site configuration found.", {
|
|
251459
|
-
hints: [
|
|
251460
|
-
{
|
|
251461
|
-
message: `Add 'site.outputDirectory' to your config.jsonc (e.g., "site": { "outputDirectory": "dist" })`
|
|
251462
|
-
}
|
|
251463
|
-
]
|
|
251464
|
-
});
|
|
251465
|
-
}
|
|
251466
|
-
const { appUrl } = await runTask("Creating archive and deploying site...", async () => await deploySite(outputDir), {
|
|
251467
|
-
successMessage: "Site deployed successfully",
|
|
251468
|
-
errorMessage: "Deployment failed"
|
|
251469
|
-
});
|
|
251470
|
-
return { outroMessage: `Visit your site at: ${appUrl}` };
|
|
251471
|
-
}
|
|
251472
254431
|
function siteOutputDir(project) {
|
|
251473
254432
|
const outputDirectory = project.site?.outputDirectory;
|
|
251474
254433
|
return outputDirectory ? resolve15(project.root, outputDirectory) : null;
|
|
251475
254434
|
}
|
|
251476
254435
|
function getSiteDeployCommand() {
|
|
251477
|
-
|
|
251478
|
-
if (deploymentsApiEnabled()) {
|
|
251479
|
-
command.addOption(new Option2("--git-hash <hash>", "Commit the build came from (defaults to the checkout's HEAD)").argParser(parseGitHash));
|
|
251480
|
-
command.addOption(new Option2("--concurrency <n>", "Parallel asset uploads").default(DEFAULT_UPLOAD_CONCURRENCY).argParser(parseConcurrency));
|
|
251481
|
-
}
|
|
251482
|
-
return command.action(deployAction2);
|
|
254436
|
+
return new Base44Command("deploy").description("Deploy built site files to Base44 hosting").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").option("--publish", "Serve this build in production once it is deployed").addOption(new Option2("--git-hash <hash>", "Commit the build came from (defaults to the checkout's HEAD)").argParser(parseGitHash2)).addOption(new Option2("--concurrency <n>", "Parallel asset uploads").default(DEFAULT_UPLOAD_CONCURRENCY).argParser(parseConcurrency)).action(deployAction2);
|
|
251483
254437
|
}
|
|
251484
|
-
function
|
|
254438
|
+
function parseGitHash2(value) {
|
|
251485
254439
|
if (!isGitCommitHash(value)) {
|
|
251486
254440
|
throw new InvalidArgumentError2("Expected a git commit hash (7-64 hex chars).");
|
|
251487
254441
|
}
|
|
@@ -251535,12 +254489,17 @@ function createDevLogger(label, labelColor = theme.styles.dim) {
|
|
|
251535
254489
|
// src/cli/dev/dev-server/serve-runner.ts
|
|
251536
254490
|
import { spawn as spawn2 } from "node:child_process";
|
|
251537
254491
|
import process21 from "node:process";
|
|
254492
|
+
var ANSI_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
254493
|
+
var LOCAL_ORIGIN_PATTERN = /https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):(\d+)/g;
|
|
251538
254494
|
|
|
251539
254495
|
class ServeRunner {
|
|
251540
254496
|
command;
|
|
251541
254497
|
cwd;
|
|
251542
254498
|
env;
|
|
251543
254499
|
logger;
|
|
254500
|
+
onOrigin;
|
|
254501
|
+
ignorePort;
|
|
254502
|
+
originReported = false;
|
|
251544
254503
|
child;
|
|
251545
254504
|
stopping = false;
|
|
251546
254505
|
stopPromise;
|
|
@@ -251550,6 +254509,8 @@ class ServeRunner {
|
|
|
251550
254509
|
this.cwd = options.cwd;
|
|
251551
254510
|
this.env = options.env;
|
|
251552
254511
|
this.logger = options.logger;
|
|
254512
|
+
this.onOrigin = options.onOrigin;
|
|
254513
|
+
this.ignorePort = options.ignorePort;
|
|
251553
254514
|
}
|
|
251554
254515
|
start() {
|
|
251555
254516
|
if (this.child) {
|
|
@@ -251626,6 +254587,7 @@ class ServeRunner {
|
|
|
251626
254587
|
const lines = data.toString().trimEnd().split(`
|
|
251627
254588
|
`);
|
|
251628
254589
|
for (const line of lines) {
|
|
254590
|
+
this.reportOrigin(line);
|
|
251629
254591
|
if (type === "error") {
|
|
251630
254592
|
this.logger.error(line);
|
|
251631
254593
|
} else {
|
|
@@ -251633,6 +254595,20 @@ class ServeRunner {
|
|
|
251633
254595
|
}
|
|
251634
254596
|
}
|
|
251635
254597
|
}
|
|
254598
|
+
reportOrigin(line) {
|
|
254599
|
+
if (this.originReported || !this.onOrigin) {
|
|
254600
|
+
return;
|
|
254601
|
+
}
|
|
254602
|
+
const matches = line.replace(ANSI_PATTERN, "").matchAll(LOCAL_ORIGIN_PATTERN);
|
|
254603
|
+
for (const [origin, port] of matches) {
|
|
254604
|
+
if (Number(port) === this.ignorePort) {
|
|
254605
|
+
continue;
|
|
254606
|
+
}
|
|
254607
|
+
this.originReported = true;
|
|
254608
|
+
this.onOrigin(origin);
|
|
254609
|
+
return;
|
|
254610
|
+
}
|
|
254611
|
+
}
|
|
251636
254612
|
}
|
|
251637
254613
|
|
|
251638
254614
|
// src/cli/dev/serve-command-runner.ts
|
|
@@ -251640,7 +254616,9 @@ function createServeCommandRunner({
|
|
|
251640
254616
|
serveCommand,
|
|
251641
254617
|
projectRoot,
|
|
251642
254618
|
appId,
|
|
251643
|
-
appBaseUrl
|
|
254619
|
+
appBaseUrl,
|
|
254620
|
+
onOrigin,
|
|
254621
|
+
ignorePort
|
|
251644
254622
|
}) {
|
|
251645
254623
|
return new ServeRunner({
|
|
251646
254624
|
command: serveCommand,
|
|
@@ -251649,7 +254627,9 @@ function createServeCommandRunner({
|
|
|
251649
254627
|
VITE_BASE44_APP_ID: appId,
|
|
251650
254628
|
...appBaseUrl ? { VITE_BASE44_APP_BASE_URL: appBaseUrl } : {}
|
|
251651
254629
|
},
|
|
251652
|
-
logger: createDevLogger("frontend", theme.colors.base44Orange)
|
|
254630
|
+
logger: createDevLogger("frontend", theme.colors.base44Orange),
|
|
254631
|
+
onOrigin,
|
|
254632
|
+
ignorePort
|
|
251653
254633
|
});
|
|
251654
254634
|
}
|
|
251655
254635
|
|
|
@@ -252428,7 +255408,7 @@ async function getPorts(options) {
|
|
|
252428
255408
|
}
|
|
252429
255409
|
|
|
252430
255410
|
// src/cli/dev/dev-server/main.ts
|
|
252431
|
-
var
|
|
255411
|
+
var import_http_proxy_middleware3 = __toESM(require_dist2(), 1);
|
|
252432
255412
|
|
|
252433
255413
|
// ../../node_modules/tmp-promise/index.js
|
|
252434
255414
|
var { promisify: promisify11 } = __require("util");
|
|
@@ -252993,11 +255973,20 @@ async function createFunctionRuntime(functions, logger, denoWrapperPath) {
|
|
|
252993
255973
|
return new FunctionManager(functions, logger, denoWrapperPath);
|
|
252994
255974
|
}
|
|
252995
255975
|
|
|
252996
|
-
// src/cli/dev/dev-server/routes/
|
|
252997
|
-
var import_express = __toESM(require_express(), 1);
|
|
255976
|
+
// src/cli/dev/dev-server/routes/app-server.ts
|
|
252998
255977
|
var import_http_proxy_middleware = __toESM(require_dist2(), 1);
|
|
252999
255978
|
import { ServerResponse } from "node:http";
|
|
253000
255979
|
|
|
255980
|
+
// ../../node_modules/ws/wrapper.mjs
|
|
255981
|
+
var import_stream3 = __toESM(require_stream6(), 1);
|
|
255982
|
+
var import_extension = __toESM(require_extension(), 1);
|
|
255983
|
+
var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
|
|
255984
|
+
var import_receiver = __toESM(require_receiver(), 1);
|
|
255985
|
+
var import_sender = __toESM(require_sender(), 1);
|
|
255986
|
+
var import_subprotocol = __toESM(require_subprotocol(), 1);
|
|
255987
|
+
var import_websocket = __toESM(require_websocket(), 1);
|
|
255988
|
+
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
255989
|
+
|
|
253001
255990
|
// src/cli/dev/dev-server/auth/tokens.ts
|
|
253002
255991
|
var import_jsonwebtoken2 = __toESM(require_jsonwebtoken(), 1);
|
|
253003
255992
|
var LOCAL_DEV_SECRET = "LOCAL_DEV_SECRET";
|
|
@@ -253011,11 +256000,132 @@ var createServiceToken = () => createJwtToken(SERVICE_ROLE_EMAIL);
|
|
|
253011
256000
|
var createServiceAuthorizationHeader = () => `Bearer ${createServiceToken()}`;
|
|
253012
256001
|
var isServiceSubject = (subject) => subject === SERVICE_ROLE_EMAIL;
|
|
253013
256002
|
|
|
256003
|
+
// src/cli/dev/dev-server/routes/app-server.ts
|
|
256004
|
+
var PLATFORM_OWNED_SDK_HEADERS = [
|
|
256005
|
+
"base44-app-id",
|
|
256006
|
+
"base44-api-url",
|
|
256007
|
+
"base44-service-authorization",
|
|
256008
|
+
"base44-state",
|
|
256009
|
+
"base44-functions-version",
|
|
256010
|
+
"x-base44-app-url",
|
|
256011
|
+
"x-data-env"
|
|
256012
|
+
];
|
|
256013
|
+
var FORWARDED_HEADER = "base44-dev-forwarded";
|
|
256014
|
+
var PROXY_LOOP_MESSAGE = [
|
|
256015
|
+
"The app dev server sent this request back to the Base44 dev server instead of handling it.",
|
|
256016
|
+
"Its Vite proxy is forwarding all of /api; only /api/apps belongs to the backend.",
|
|
256017
|
+
"Update @base44/vite-plugin, or narrow the proxy in vite.config.js to /api/apps."
|
|
256018
|
+
].join(" ");
|
|
256019
|
+
function sdkHeaders(appId, host) {
|
|
256020
|
+
return {
|
|
256021
|
+
"Base44-App-Id": appId,
|
|
256022
|
+
"Base44-Api-Url": `http://${host}`,
|
|
256023
|
+
"Base44-Service-Authorization": createServiceAuthorizationHeader(),
|
|
256024
|
+
[FORWARDED_HEADER]: "1"
|
|
256025
|
+
};
|
|
256026
|
+
}
|
|
256027
|
+
function createAppServerProxy(target, logger) {
|
|
256028
|
+
let origin = "http://127.0.0.1:0";
|
|
256029
|
+
const proxy = import_http_proxy_middleware.createProxyMiddleware({
|
|
256030
|
+
router: () => origin,
|
|
256031
|
+
changeOrigin: true,
|
|
256032
|
+
on: {
|
|
256033
|
+
proxyReq: (proxyReq, req) => {
|
|
256034
|
+
for (const header of PLATFORM_OWNED_SDK_HEADERS) {
|
|
256035
|
+
proxyReq.removeHeader(header);
|
|
256036
|
+
}
|
|
256037
|
+
for (const [name, value] of Object.entries(sdkHeaders(target.appId, req.headers.host))) {
|
|
256038
|
+
proxyReq.setHeader(name, value);
|
|
256039
|
+
}
|
|
256040
|
+
},
|
|
256041
|
+
error: (err, _req, res) => {
|
|
256042
|
+
logger.error("App dev server proxy error:", err);
|
|
256043
|
+
if (res instanceof ServerResponse && !res.headersSent) {
|
|
256044
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
256045
|
+
res.end(JSON.stringify({
|
|
256046
|
+
error: "Failed to proxy request to the app dev server",
|
|
256047
|
+
details: err.message
|
|
256048
|
+
}));
|
|
256049
|
+
}
|
|
256050
|
+
}
|
|
256051
|
+
}
|
|
256052
|
+
});
|
|
256053
|
+
const resolveOrigin = async () => {
|
|
256054
|
+
origin = await target.waitForOrigin();
|
|
256055
|
+
};
|
|
256056
|
+
const middleware = async (req, res, next) => {
|
|
256057
|
+
if (req.headers[FORWARDED_HEADER]) {
|
|
256058
|
+
logger.error(PROXY_LOOP_MESSAGE);
|
|
256059
|
+
res.status(508).json({ error: PROXY_LOOP_MESSAGE });
|
|
256060
|
+
return;
|
|
256061
|
+
}
|
|
256062
|
+
try {
|
|
256063
|
+
await resolveOrigin();
|
|
256064
|
+
} catch (error) {
|
|
256065
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
256066
|
+
logger.error(message);
|
|
256067
|
+
res.status(502).json({ error: message });
|
|
256068
|
+
return;
|
|
256069
|
+
}
|
|
256070
|
+
await proxy(req, res, next);
|
|
256071
|
+
};
|
|
256072
|
+
const relay = new import_websocket_server.default({
|
|
256073
|
+
noServer: true,
|
|
256074
|
+
handleProtocols: (protocols) => [...protocols][0] ?? false
|
|
256075
|
+
});
|
|
256076
|
+
const upgrade = (req, socket, head) => {
|
|
256077
|
+
resolveOrigin().then(() => relay.handleUpgrade(req, socket, head, (client) => relayTo(client, req)), (error) => {
|
|
256078
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
256079
|
+
socket.destroy();
|
|
256080
|
+
});
|
|
256081
|
+
};
|
|
256082
|
+
const relayTo = (client, req) => {
|
|
256083
|
+
const forwarded = {};
|
|
256084
|
+
for (let i = 0;i < req.rawHeaders.length; i += 2) {
|
|
256085
|
+
const lower = req.rawHeaders[i].toLowerCase();
|
|
256086
|
+
if (lower === "host" || lower.startsWith("sec-websocket-") || lower === "upgrade" || lower === "connection" || PLATFORM_OWNED_SDK_HEADERS.includes(lower)) {
|
|
256087
|
+
continue;
|
|
256088
|
+
}
|
|
256089
|
+
forwarded[req.rawHeaders[i]] = req.rawHeaders[i + 1];
|
|
256090
|
+
}
|
|
256091
|
+
const upstream = new import_websocket.default(`${origin.replace(/^http/, "ws")}${req.url}`, client.protocol || undefined, {
|
|
256092
|
+
headers: {
|
|
256093
|
+
...forwarded,
|
|
256094
|
+
...sdkHeaders(target.appId, req.headers.host)
|
|
256095
|
+
}
|
|
256096
|
+
});
|
|
256097
|
+
const pending = [];
|
|
256098
|
+
client.on("message", (data, isBinary) => {
|
|
256099
|
+
if (upstream.readyState === import_websocket.default.OPEN) {
|
|
256100
|
+
upstream.send(data, { binary: isBinary });
|
|
256101
|
+
} else {
|
|
256102
|
+
pending.push({ data, isBinary });
|
|
256103
|
+
}
|
|
256104
|
+
});
|
|
256105
|
+
upstream.on("open", () => {
|
|
256106
|
+
for (const { data, isBinary } of pending.splice(0)) {
|
|
256107
|
+
upstream.send(data, { binary: isBinary });
|
|
256108
|
+
}
|
|
256109
|
+
});
|
|
256110
|
+
upstream.on("message", (data, isBinary) => client.send(data, { binary: isBinary }));
|
|
256111
|
+
client.on("close", () => upstream.close());
|
|
256112
|
+
upstream.on("close", () => client.close());
|
|
256113
|
+
upstream.on("error", (error) => {
|
|
256114
|
+
logger.error("App dev server websocket error:", error);
|
|
256115
|
+
client.close();
|
|
256116
|
+
});
|
|
256117
|
+
};
|
|
256118
|
+
return { middleware, upgrade };
|
|
256119
|
+
}
|
|
256120
|
+
|
|
253014
256121
|
// src/cli/dev/dev-server/routes/functions.ts
|
|
256122
|
+
var import_express = __toESM(require_express(), 1);
|
|
256123
|
+
var import_http_proxy_middleware2 = __toESM(require_dist2(), 1);
|
|
256124
|
+
import { ServerResponse as ServerResponse2 } from "node:http";
|
|
253015
256125
|
function createFunctionRouter(manager, logger) {
|
|
253016
256126
|
const router = import_express.Router({ mergeParams: true });
|
|
253017
256127
|
const portsByRequest = new WeakMap;
|
|
253018
|
-
const proxy =
|
|
256128
|
+
const proxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
253019
256129
|
router: (req) => `http://localhost:${portsByRequest.get(req)}`,
|
|
253020
256130
|
changeOrigin: true,
|
|
253021
256131
|
on: {
|
|
@@ -253029,7 +256139,7 @@ function createFunctionRouter(manager, logger) {
|
|
|
253029
256139
|
},
|
|
253030
256140
|
error: (err, _req, res) => {
|
|
253031
256141
|
logger.error("Function proxy error:", err);
|
|
253032
|
-
if (res instanceof
|
|
256142
|
+
if (res instanceof ServerResponse2 && !res.headersSent) {
|
|
253033
256143
|
res.writeHead(502, { "Content-Type": "application/json" });
|
|
253034
256144
|
res.end(JSON.stringify({
|
|
253035
256145
|
error: "Failed to proxy request to function",
|
|
@@ -253375,9 +256485,10 @@ var import_dist = __toESM(require_dist4(), 1);
|
|
|
253375
256485
|
var { Server, Namespace, Socket } = import_dist.default;
|
|
253376
256486
|
|
|
253377
256487
|
// src/cli/dev/dev-server/realtime.ts
|
|
256488
|
+
var REALTIME_PATH = "/ws-user-apps/socket.io/";
|
|
253378
256489
|
function createRealtimeServer(httpServer) {
|
|
253379
256490
|
const io = new Server(httpServer, {
|
|
253380
|
-
path:
|
|
256491
|
+
path: REALTIME_PATH,
|
|
253381
256492
|
cors: {
|
|
253382
256493
|
origin: /^http:\/\/localhost(:\d+)?$/,
|
|
253383
256494
|
credentials: true
|
|
@@ -255910,6 +259021,7 @@ class WatchBase44 extends EventEmitter4 {
|
|
|
255910
259021
|
// src/cli/dev/dev-server/main.ts
|
|
255911
259022
|
var DEFAULT_PORT = 4400;
|
|
255912
259023
|
var BASE44_APP_URL = "https://base44.app";
|
|
259024
|
+
var PLATFORM_PATH_PATTERN = /^\/api\/apps(\/|$)/;
|
|
255913
259025
|
async function createDevServer(options) {
|
|
255914
259026
|
const { port: userPort } = options;
|
|
255915
259027
|
const port = userPort ?? await getPorts({
|
|
@@ -255918,7 +259030,7 @@ async function createDevServer(options) {
|
|
|
255918
259030
|
const baseUrl = `http://localhost:${port}`;
|
|
255919
259031
|
const { functions, entities, project, siteUrl } = await options.loadResources();
|
|
255920
259032
|
const app = import_express6.default();
|
|
255921
|
-
const remoteProxy =
|
|
259033
|
+
const remoteProxy = import_http_proxy_middleware3.createProxyMiddleware({
|
|
255922
259034
|
target: BASE44_APP_URL,
|
|
255923
259035
|
changeOrigin: true
|
|
255924
259036
|
});
|
|
@@ -255980,7 +259092,11 @@ async function createDevServer(options) {
|
|
|
255980
259092
|
app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
|
|
255981
259093
|
const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
|
|
255982
259094
|
app.use("/api/apps/:appId/integrations/custom", customIntegrationRoutes);
|
|
259095
|
+
const appServerProxy = options.appServer ? createAppServerProxy(options.appServer, devLogger) : undefined;
|
|
255983
259096
|
app.use((req, res, next) => {
|
|
259097
|
+
if (appServerProxy && !PLATFORM_PATH_PATTERN.test(req.path)) {
|
|
259098
|
+
return appServerProxy.middleware(req, res, next);
|
|
259099
|
+
}
|
|
255984
259100
|
if (siteUrl && (req.path === "/login" || req.path.startsWith("/login/"))) {
|
|
255985
259101
|
const targetUrl = new URL(req.originalUrl, siteUrl);
|
|
255986
259102
|
devLogger.warn(`"${req.originalUrl}" requires hosted login, redirecting to ${targetUrl.toString()}`);
|
|
@@ -256005,6 +259121,13 @@ async function createDevServer(options) {
|
|
|
256005
259121
|
}
|
|
256006
259122
|
});
|
|
256007
259123
|
});
|
|
259124
|
+
if (appServerProxy) {
|
|
259125
|
+
server.on("upgrade", (req, socket, head) => {
|
|
259126
|
+
if (!req.url?.startsWith(REALTIME_PATH)) {
|
|
259127
|
+
appServerProxy.upgrade(req, socket, head);
|
|
259128
|
+
}
|
|
259129
|
+
});
|
|
259130
|
+
}
|
|
256008
259131
|
const io = createRealtimeServer(server);
|
|
256009
259132
|
emitEntityEvent = (appId, entityName, event) => {
|
|
256010
259133
|
broadcastEntityEvent(io, appId, entityName, event);
|
|
@@ -256078,9 +259201,24 @@ async function createDevServer(options) {
|
|
|
256078
259201
|
}
|
|
256079
259202
|
|
|
256080
259203
|
// src/cli/commands/dev.ts
|
|
259204
|
+
var APP_SERVER_START_TIMEOUT_MS = 120000;
|
|
256081
259205
|
function localServerUrl(port) {
|
|
256082
259206
|
return `http://localhost:${port}`;
|
|
256083
259207
|
}
|
|
259208
|
+
function createAppServerOrigin() {
|
|
259209
|
+
let report;
|
|
259210
|
+
const announced = new Promise((resolve) => {
|
|
259211
|
+
report = resolve;
|
|
259212
|
+
});
|
|
259213
|
+
const timedOut = new Promise((_, reject) => {
|
|
259214
|
+
const timer = setTimeout(() => reject(new Error("The app dev server did not print a local URL, so requests cannot be forwarded to it.")), APP_SERVER_START_TIMEOUT_MS);
|
|
259215
|
+
timer.unref();
|
|
259216
|
+
});
|
|
259217
|
+
return {
|
|
259218
|
+
waitForOrigin: () => Promise.race([announced, timedOut]),
|
|
259219
|
+
report
|
|
259220
|
+
};
|
|
259221
|
+
}
|
|
256084
259222
|
function validateDevOptions(command) {
|
|
256085
259223
|
const { appId } = command.optsWithGlobals();
|
|
256086
259224
|
if (appId !== undefined) {
|
|
@@ -256133,10 +259271,12 @@ async function localDevAction(ctx, app, options) {
|
|
|
256133
259271
|
const siteUrlPromise = getSiteUrl().catch(() => {
|
|
256134
259272
|
return;
|
|
256135
259273
|
});
|
|
259274
|
+
const appServerOrigin = createAppServerOrigin();
|
|
256136
259275
|
const backend = await createDevServer({
|
|
256137
259276
|
log: ctx.log,
|
|
256138
259277
|
port: options.port ? Number(options.port) : undefined,
|
|
256139
259278
|
denoWrapperPath: getDenoWrapperPath(),
|
|
259279
|
+
appServer: site ? { appId: app.id, waitForOrigin: appServerOrigin.waitForOrigin } : undefined,
|
|
256140
259280
|
loadResources: async () => {
|
|
256141
259281
|
const { functions, entities, project } = await readProjectConfig();
|
|
256142
259282
|
const siteUrl = await siteUrlPromise;
|
|
@@ -256148,11 +259288,13 @@ async function localDevAction(ctx, app, options) {
|
|
|
256148
259288
|
const runner = createServeCommandRunner({
|
|
256149
259289
|
...site,
|
|
256150
259290
|
appId: app.id,
|
|
256151
|
-
appBaseUrl: backendUrl
|
|
259291
|
+
appBaseUrl: backendUrl,
|
|
259292
|
+
onOrigin: appServerOrigin.report,
|
|
259293
|
+
ignorePort: backend.port
|
|
256152
259294
|
});
|
|
256153
259295
|
startServeCommand(runner, { url: backendUrl, shutdown: backend.shutdown });
|
|
256154
259296
|
}
|
|
256155
|
-
const outroMessage = site ?
|
|
259297
|
+
const outroMessage = site ? `Your app is available at ${theme.colors.links(backendUrl)}` : `Dev server is available at ${theme.colors.links(backendUrl)}`;
|
|
256156
259298
|
return { outroMessage };
|
|
256157
259299
|
}
|
|
256158
259300
|
async function devAction(ctx, options) {
|
|
@@ -260579,4 +263721,4 @@ export {
|
|
|
260579
263721
|
runCLI
|
|
260580
263722
|
};
|
|
260581
263723
|
|
|
260582
|
-
//# debugId=
|
|
263724
|
+
//# debugId=39C9A48A8717939064756E2164756E21
|