sonic-ws 1.0.0-rc.8 → 1.0.3
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/LICENSE +190 -209
- package/README.md +11 -11
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -1
- package/dist/version.d.ts +5 -3
- package/dist/version.js +8 -5
- package/dist/ws/Connection.d.ts +44 -0
- package/dist/ws/Connection.js +17 -0
- package/dist/ws/client/core/ClientCore.d.ts +9 -17
- package/dist/ws/client/core/ClientCore.js +122 -159
- package/dist/ws/client/node/ClientNode.d.ts +0 -0
- package/dist/ws/client/node/ClientNode.js +8 -25
- package/dist/ws/packets/PacketProcessors.d.ts +11 -7
- package/dist/ws/packets/PacketProcessors.js +218 -177
- package/dist/ws/packets/PacketType.d.ts +20 -16
- package/dist/ws/packets/PacketType.js +21 -17
- package/dist/ws/packets/Packets.d.ts +8 -10
- package/dist/ws/packets/Packets.js +186 -161
- package/dist/ws/server/SonicWSConnection.d.ts +7 -21
- package/dist/ws/server/SonicWSConnection.js +117 -148
- package/dist/ws/server/SonicWSServer.d.ts +0 -0
- package/dist/ws/server/SonicWSServer.js +79 -98
- package/dist/ws/util/ArrayUtil.d.ts +0 -0
- package/dist/ws/util/ArrayUtil.js +3 -3
- package/dist/ws/util/BufferUtil.d.ts +3 -0
- package/dist/ws/util/BufferUtil.js +19 -3
- package/dist/ws/util/StringUtil.d.ts +6 -0
- package/dist/ws/util/StringUtil.js +66 -0
- package/dist/ws/util/enums/EnumHandler.d.ts +2 -3
- package/dist/ws/util/enums/EnumHandler.js +17 -17
- package/dist/ws/util/enums/EnumType.d.ts +1 -1
- package/dist/ws/util/enums/EnumType.js +28 -24
- package/dist/ws/util/packets/BatchHelper.d.ts +9 -5
- package/dist/ws/util/packets/BatchHelper.js +50 -39
- package/dist/ws/util/packets/CompressionUtil.d.ts +22 -15
- package/dist/ws/util/packets/CompressionUtil.js +179 -141
- package/dist/ws/util/packets/PacketHolder.d.ts +1 -6
- package/dist/ws/util/packets/PacketHolder.js +43 -41
- package/dist/ws/util/packets/PacketUtils.d.ts +2 -6
- package/dist/ws/util/packets/PacketUtils.js +71 -70
- package/dist/ws/util/packets/RateHandler.d.ts +0 -0
- package/dist/ws/util/packets/RateHandler.js +24 -26
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2025 Lily (
|
|
3
|
+
* Copyright 2025 Lily (liwybloc)
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,46 +14,59 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
-
if (ar || !(i in from)) {
|
|
20
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
-
ar[i] = from[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
-
};
|
|
26
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
18
|
exports.PacketSchema = exports.Packet = void 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
const EnumHandler_1 = require("../util/enums/EnumHandler");
|
|
20
|
+
const EnumType_1 = require("../util/enums/EnumType");
|
|
21
|
+
const CompressionUtil_1 = require("../util/packets/CompressionUtil");
|
|
22
|
+
const PacketUtils_1 = require("../util/packets/PacketUtils");
|
|
23
|
+
const PacketProcessors_1 = require("./PacketProcessors");
|
|
24
|
+
const PacketType_1 = require("./PacketType");
|
|
25
|
+
const BufferUtil_1 = require("../util/BufferUtil");
|
|
26
|
+
const StringUtil_1 = require("../util/StringUtil");
|
|
27
|
+
class Packet {
|
|
28
|
+
tag;
|
|
29
|
+
defaultEnabled;
|
|
30
|
+
maxSize;
|
|
31
|
+
minSize;
|
|
32
|
+
type;
|
|
33
|
+
enumData;
|
|
34
|
+
dataMax;
|
|
35
|
+
dataMin;
|
|
36
|
+
dataBatching;
|
|
37
|
+
maxBatchSize;
|
|
38
|
+
dontSpread;
|
|
39
|
+
autoFlatten;
|
|
40
|
+
rateLimit;
|
|
41
|
+
object;
|
|
42
|
+
client;
|
|
43
|
+
receiveProcessor;
|
|
44
|
+
sendProcessor;
|
|
45
|
+
validator;
|
|
46
|
+
processReceive;
|
|
47
|
+
processSend;
|
|
48
|
+
validate;
|
|
49
|
+
customValidator;
|
|
50
|
+
constructor(tag, schema, customValidator, enabled, client) {
|
|
38
51
|
this.tag = tag;
|
|
39
52
|
this.defaultEnabled = enabled;
|
|
53
|
+
this.client = client;
|
|
40
54
|
this.enumData = schema.enumData;
|
|
41
55
|
this.rateLimit = schema.rateLimit;
|
|
42
56
|
this.dontSpread = schema.dontSpread;
|
|
43
57
|
this.autoFlatten = schema.autoFlatten;
|
|
44
58
|
this.dataBatching = schema.dataBatching;
|
|
45
59
|
this.maxBatchSize = client ? Infinity : schema.maxBatchSize;
|
|
46
|
-
this.
|
|
47
|
-
if (
|
|
60
|
+
this.object = schema.object;
|
|
61
|
+
if (this.object) {
|
|
48
62
|
this.type = schema.types;
|
|
49
63
|
this.dataMax = schema.dataMaxes;
|
|
50
64
|
this.dataMin = schema.dataMins;
|
|
51
65
|
this.maxSize = this.type.length;
|
|
52
66
|
this.minSize = this.type.length;
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.sendProcessor = (0, PacketProcessors_1.createObjSendProcessor)(this.type, this.packetDelimitSize);
|
|
67
|
+
this.receiveProcessor = (0, PacketProcessors_1.createObjReceiveProcessor)(this);
|
|
68
|
+
this.validator = (0, PacketProcessors_1.createObjValidator)(this);
|
|
69
|
+
this.sendProcessor = (0, PacketProcessors_1.createObjSendProcessor)(this);
|
|
57
70
|
}
|
|
58
71
|
else {
|
|
59
72
|
this.type = schema.type;
|
|
@@ -61,25 +74,25 @@ var Packet = /** @class */ (function () {
|
|
|
61
74
|
this.dataMin = schema.dataMin;
|
|
62
75
|
this.maxSize = this.dataMax;
|
|
63
76
|
this.minSize = this.dataMin;
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this.sendProcessor = PacketProcessors_1.PacketSendProcessors[this.type];
|
|
77
|
+
this.receiveProcessor = (0, PacketProcessors_1.createReceiveProcessor)(this.type, this.enumData, this.dataMax);
|
|
78
|
+
this.validator = (0, PacketProcessors_1.createValidator)(this.type, this.dataMax, this.dataMin, this);
|
|
79
|
+
this.sendProcessor = (0, PacketProcessors_1.createSendProcessor)(this.type);
|
|
68
80
|
}
|
|
69
|
-
this.processReceive =
|
|
70
|
-
this.processSend =
|
|
71
|
-
this.validate =
|
|
81
|
+
this.processReceive = (data, validationResult) => this.receiveProcessor(data, validationResult, 0);
|
|
82
|
+
this.processSend = (data) => this.sendProcessor(data);
|
|
83
|
+
this.validate = (data) => this.validator(data, 0);
|
|
72
84
|
this.customValidator = customValidator;
|
|
73
85
|
}
|
|
74
|
-
|
|
86
|
+
listen(value, socket) {
|
|
75
87
|
try {
|
|
76
|
-
|
|
88
|
+
const validationResult = this.validate(value);
|
|
89
|
+
if (!this.client && validationResult == false)
|
|
77
90
|
return "Invalid packet";
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
const processed = this.processReceive(value, validationResult);
|
|
92
|
+
const useableData = this.autoFlatten ? (0, PacketUtils_1.UnFlattenData)(processed) : processed;
|
|
80
93
|
if (this.customValidator != null) {
|
|
81
94
|
if (!this.dontSpread) {
|
|
82
|
-
if (!this.customValidator
|
|
95
|
+
if (!this.customValidator(socket, ...useableData))
|
|
83
96
|
return "Didn't pass custom validator";
|
|
84
97
|
}
|
|
85
98
|
else {
|
|
@@ -93,146 +106,160 @@ var Packet = /** @class */ (function () {
|
|
|
93
106
|
console.error("There was an error processing the packet! This is probably my fault... report at https://github.com/cutelittlelily/sonic-ws", err);
|
|
94
107
|
return "Error: " + err;
|
|
95
108
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
var enumData = String.fromCharCode(this.enumData.length + 1) + this.enumData.map(function (x) { return x.serialize(); }).join("");
|
|
106
|
-
// data batching, also avoid null
|
|
107
|
-
var dataBatching = String.fromCharCode(this.dataBatching + 1) + String.fromCharCode(this.maxBatchSize + 1);
|
|
108
|
-
// rate limit, avoiding null again... ugh i should prob fix this with a map-
|
|
109
|
-
var rateLimit = String.fromCharCode(this.rateLimit + 1);
|
|
109
|
+
}
|
|
110
|
+
serialize() {
|
|
111
|
+
// shared values for both
|
|
112
|
+
const sharedData = [
|
|
113
|
+
this.tag.length, ...(0, StringUtil_1.processCharCodes)(this.tag),
|
|
114
|
+
this.dontSpread ? 1 : 0,
|
|
115
|
+
this.dataBatching,
|
|
116
|
+
this.enumData.length, ...this.enumData.map(x => x.serialize()).flat(),
|
|
117
|
+
];
|
|
110
118
|
// single-value packet (not an object schema)
|
|
111
119
|
if (!this.object) {
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
return [
|
|
121
|
+
...sharedData, // shared
|
|
122
|
+
0, // dummy byte flag for consistent deserialization; becomes -1 to indicate single
|
|
123
|
+
...(0, CompressionUtil_1.convertVarInt)(this.dataMax), // the data max
|
|
124
|
+
...(0, CompressionUtil_1.convertVarInt)(this.dataMin), // the data min
|
|
125
|
+
this.type,
|
|
126
|
+
];
|
|
119
127
|
}
|
|
120
128
|
// object packet
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.dataMax.map(
|
|
126
|
-
this.dataMin.map(
|
|
127
|
-
this.type
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
129
|
+
return [
|
|
130
|
+
...sharedData,
|
|
131
|
+
this.maxSize + 1, // size, and +1 because of 0 for single
|
|
132
|
+
this.autoFlatten ? 1 : 0, // auto flatten flag
|
|
133
|
+
...this.dataMax.map(CompressionUtil_1.convertVarInt).flat(), // all data maxes, serialized
|
|
134
|
+
...this.dataMin.map(CompressionUtil_1.convertVarInt).flat(), // all data mins, serialized
|
|
135
|
+
...this.type, // all types, offset by 1 for NULL
|
|
136
|
+
this.tag.length, // tag length, offset by 1 for NULL
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
static readVarInts(data, offset, size) {
|
|
140
|
+
const res = [];
|
|
141
|
+
for (let i = 0; i < size; i++) {
|
|
142
|
+
const [off, varint] = (0, CompressionUtil_1.readVarInt)(data, offset);
|
|
143
|
+
offset = off;
|
|
144
|
+
res.push(varint);
|
|
145
|
+
}
|
|
146
|
+
return [res, offset];
|
|
147
|
+
}
|
|
148
|
+
static deserialize(data, offset, client) {
|
|
149
|
+
const beginningOffset = offset;
|
|
150
|
+
// read length, go up 1
|
|
151
|
+
const tagLength = data[offset++];
|
|
152
|
+
// read tag as it's up 1, and add offset
|
|
153
|
+
const tag = (0, BufferUtil_1.as8String)(data.slice(offset, offset += tagLength));
|
|
154
|
+
// then read dont spread, go up 1
|
|
155
|
+
const dontSpread = data[offset++] == 1;
|
|
156
|
+
// read batching, up 1
|
|
157
|
+
const dataBatching = data[offset++];
|
|
158
|
+
// read enum length, up 1
|
|
159
|
+
const enumLength = data[offset++];
|
|
160
|
+
const enums = [];
|
|
161
|
+
for (let i = 0; i < enumLength; i++) {
|
|
162
|
+
// read tag length, go up 1
|
|
163
|
+
const enumTagLength = data[offset++];
|
|
164
|
+
// up 1 so read offset -> offset += tag length, to add tag length and skip over it
|
|
165
|
+
const enumTag = (0, BufferUtil_1.as8String)(data.slice(offset, offset += enumTagLength));
|
|
166
|
+
// read amount of values
|
|
167
|
+
const valueCount = data[offset++];
|
|
168
|
+
const values = [];
|
|
169
|
+
for (let j = 0; j < valueCount; j++) {
|
|
170
|
+
// read the length of the value, go up 1
|
|
171
|
+
const valueLength = data[offset++];
|
|
172
|
+
// then read the type of value, up 1
|
|
173
|
+
const valueType = data[offset++];
|
|
174
|
+
// now can just read the values, increase offset for later use
|
|
175
|
+
const value = (0, BufferUtil_1.as8String)(data.slice(offset, offset += valueLength));
|
|
176
|
+
// process it
|
|
155
177
|
values.push(EnumType_1.TYPE_CONVERSION_MAP[valueType](value));
|
|
156
178
|
}
|
|
179
|
+
// define the enum with the values
|
|
157
180
|
enums.push((0, EnumHandler_1.DefineEnum)(enumTag, values));
|
|
158
181
|
}
|
|
159
|
-
|
|
182
|
+
// read type count; prob should change sometime
|
|
183
|
+
const size = data[offset++] - 1;
|
|
160
184
|
// objects
|
|
161
|
-
//
|
|
185
|
+
// single packet is 0, 0 - 1 = -1
|
|
162
186
|
if (size != -1) {
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
var index_1 = 0;
|
|
179
|
-
var finalTypes = types.map(function (x) { return x == PacketType_1.PacketType.ENUMS ? enums[index_1++] : x; }); // convert enums to their enum packages
|
|
180
|
-
var tagLength_1 = text.charCodeAt(tagStart_1 - 1) - 1; // tag length is right behind tag, subtracting 1 to reverse
|
|
181
|
-
var tag_1 = text.substring(tagStart_1, tagStart_1 + tagLength_1); // tag is tag length long. yeah
|
|
182
|
-
var schema_1 = PacketSchema.object(finalTypes, dataMaxes, dataMins, dontSpread, autoFlatten, packetDelimitSize, dataBatching, maxBatchSize, rateLimit);
|
|
187
|
+
// 1 for true, 0 for false
|
|
188
|
+
const autoFlatten = data[offset++] == 1;
|
|
189
|
+
// read var ints for the datamaxes
|
|
190
|
+
const [dataMaxes, o1] = this.readVarInts(data, offset, size);
|
|
191
|
+
offset = o1;
|
|
192
|
+
// read var ints for the datamins
|
|
193
|
+
const [dataMins, o2] = this.readVarInts(data, offset, size);
|
|
194
|
+
offset = o2;
|
|
195
|
+
// get types, skip past size since there'll be size of these
|
|
196
|
+
const types = Array.from(data.slice(offset, offset += size));
|
|
197
|
+
// convert any enums into their indexed form for best bandwidth
|
|
198
|
+
let index = 0;
|
|
199
|
+
const finalTypes = types.map(x => x == PacketType_1.PacketType.ENUMS ? enums[index++] : x); // convert enums to their enum packages
|
|
200
|
+
// make schema
|
|
201
|
+
const schema = PacketSchema.object(finalTypes, dataMaxes, dataMins, dontSpread, autoFlatten, dataBatching, -1, -1);
|
|
183
202
|
return [
|
|
184
|
-
new Packet(
|
|
185
|
-
|
|
203
|
+
new Packet(tag, schema, null, false, client),
|
|
204
|
+
// +1 to go next
|
|
205
|
+
(offset - beginningOffset) + 1,
|
|
186
206
|
];
|
|
187
207
|
}
|
|
188
|
-
// single packet
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
208
|
+
// single packet
|
|
209
|
+
// read varint for datamax
|
|
210
|
+
const [o1, dataMax] = (0, CompressionUtil_1.readVarInt)(data, offset);
|
|
211
|
+
offset = o1;
|
|
212
|
+
// read varint for datamin
|
|
213
|
+
const [o2, dataMin] = (0, CompressionUtil_1.readVarInt)(data, offset);
|
|
214
|
+
offset = o2;
|
|
215
|
+
// read type, no more so no +1
|
|
216
|
+
const type = data[offset];
|
|
217
|
+
// do enum stuff
|
|
218
|
+
const finalType = type == PacketType_1.PacketType.ENUMS ? enums[0] : type; // convert enum to enum package
|
|
219
|
+
console.log(tag, finalType, data, offset, data[offset]);
|
|
220
|
+
// make schema
|
|
221
|
+
const schema = PacketSchema.single(finalType, dataMax, dataMin, dontSpread, dataBatching, -1, -1);
|
|
197
222
|
return [
|
|
198
223
|
new Packet(tag, schema, null, false, client),
|
|
199
|
-
|
|
224
|
+
// +1 to go next
|
|
225
|
+
(offset - beginningOffset) + 1,
|
|
200
226
|
];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
while (offset <
|
|
206
|
-
|
|
227
|
+
}
|
|
228
|
+
static deserializeAll(data, client) {
|
|
229
|
+
const arr = [];
|
|
230
|
+
let offset = 0;
|
|
231
|
+
while (offset < data.length) {
|
|
232
|
+
const [packet, len] = this.deserialize(data, offset, client);
|
|
207
233
|
arr.push(packet);
|
|
208
234
|
offset += len;
|
|
209
235
|
}
|
|
210
236
|
return arr;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
}());
|
|
237
|
+
}
|
|
238
|
+
}
|
|
214
239
|
exports.Packet = Packet;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
240
|
+
class PacketSchema {
|
|
241
|
+
types = [];
|
|
242
|
+
dataMaxes = [];
|
|
243
|
+
dataMins = [];
|
|
244
|
+
type = PacketType_1.PacketType.NONE;
|
|
245
|
+
dataMax = -1;
|
|
246
|
+
dataMin = -1;
|
|
247
|
+
dataBatching = 0;
|
|
248
|
+
maxBatchSize = 10;
|
|
249
|
+
rateLimit = 0;
|
|
250
|
+
enumData = [];
|
|
251
|
+
dontSpread = false;
|
|
252
|
+
autoFlatten = false;
|
|
253
|
+
object;
|
|
254
|
+
constructor(object) {
|
|
230
255
|
this.object = object;
|
|
231
256
|
}
|
|
232
|
-
|
|
233
|
-
|
|
257
|
+
static single(type, dataMax, dataMin, dontSpread, dataBatching, maxBatchSize, rateLimit) {
|
|
258
|
+
const schema = new PacketSchema(false);
|
|
234
259
|
if (typeof type == 'number') {
|
|
235
260
|
schema.type = type;
|
|
261
|
+
if (type == PacketType_1.PacketType.NONE)
|
|
262
|
+
dataMax = dataMin = 0; // remove garbage data issues
|
|
236
263
|
}
|
|
237
264
|
else {
|
|
238
265
|
schema.type = PacketType_1.PacketType.ENUMS;
|
|
@@ -245,12 +272,12 @@ var PacketSchema = /** @class */ (function () {
|
|
|
245
272
|
schema.maxBatchSize = maxBatchSize;
|
|
246
273
|
schema.rateLimit = rateLimit;
|
|
247
274
|
return schema;
|
|
248
|
-
}
|
|
249
|
-
|
|
275
|
+
}
|
|
276
|
+
static object(types, dataMaxes, dataMins, dontSpread, autoFlatten, dataBatching, maxBatchSize, rateLimit) {
|
|
250
277
|
if (types.length != dataMaxes.length || types.length != dataMins.length)
|
|
251
278
|
throw new Error("There is an inbalance between the amount of types, data maxes, and data mins!");
|
|
252
|
-
|
|
253
|
-
types.forEach(
|
|
279
|
+
const schema = new PacketSchema(true);
|
|
280
|
+
types.forEach(type => {
|
|
254
281
|
if (typeof type == 'number') {
|
|
255
282
|
schema.types.push(type);
|
|
256
283
|
}
|
|
@@ -263,12 +290,10 @@ var PacketSchema = /** @class */ (function () {
|
|
|
263
290
|
schema.dataMins = dataMins;
|
|
264
291
|
schema.dontSpread = dontSpread;
|
|
265
292
|
schema.autoFlatten = autoFlatten;
|
|
266
|
-
schema.packetDelimitSize = packetDelimitSize;
|
|
267
293
|
schema.dataBatching = dataBatching;
|
|
268
294
|
schema.maxBatchSize = maxBatchSize;
|
|
269
295
|
schema.rateLimit = rateLimit;
|
|
270
296
|
return schema;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
}());
|
|
297
|
+
}
|
|
298
|
+
}
|
|
274
299
|
exports.PacketSchema = PacketSchema;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as WS from 'ws';
|
|
2
2
|
import { SonicWSServer } from './SonicWSServer';
|
|
3
3
|
import { Packet } from '../packets/Packets';
|
|
4
|
-
|
|
4
|
+
import { Connection } from '../Connection';
|
|
5
|
+
export declare class SonicWSConnection implements Connection {
|
|
5
6
|
/** Raw 'ws' library socket */
|
|
6
7
|
socket: WS.WebSocket;
|
|
7
8
|
private host;
|
|
8
9
|
private listeners;
|
|
9
10
|
private print;
|
|
10
|
-
private timers;
|
|
11
11
|
private handshakePacket;
|
|
12
12
|
private handshakeLambda;
|
|
13
13
|
private messageLambda;
|
|
@@ -19,17 +19,13 @@ export declare class SonicWSConnection {
|
|
|
19
19
|
handshakeComplete: boolean;
|
|
20
20
|
/** The index of the connection; unique for all connected, recycles old disconnected ids. Should be safe for INTS_C unless you have more than 27,647 connected at once. */
|
|
21
21
|
id: number;
|
|
22
|
-
|
|
23
|
-
code: string;
|
|
22
|
+
_timers: Record<number, number>;
|
|
24
23
|
constructor(socket: WS.WebSocket, host: SonicWSServer, id: number, handshakePacket: string | null, clientRateLimit: number, serverRateLimit: number);
|
|
25
24
|
private parseData;
|
|
26
25
|
private handshakeHandler;
|
|
27
26
|
private invalidPacket;
|
|
28
27
|
private listenPacket;
|
|
29
28
|
private messageHandler;
|
|
30
|
-
private hideNewLines;
|
|
31
|
-
/** Sends raw data to the user; will likely fail validity checks if used externally */
|
|
32
|
-
raw_send(data: Uint8Array): void;
|
|
33
29
|
/**
|
|
34
30
|
* Enables a packet for the client.
|
|
35
31
|
* @param tag The tag of the packet
|
|
@@ -82,20 +78,10 @@ export declare class SonicWSConnection {
|
|
|
82
78
|
* Toggles printing all sent and received messages
|
|
83
79
|
*/
|
|
84
80
|
togglePrint(): void;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*/
|
|
88
|
-
close(code?: number): void;
|
|
89
|
-
/**
|
|
90
|
-
* Sets a timeout that will automatically end when the socket closes
|
|
91
|
-
* @param call The function to call
|
|
92
|
-
* @param time The time between now and the call (ms)
|
|
93
|
-
*/
|
|
81
|
+
raw_send(data: Uint8Array): void;
|
|
82
|
+
close(code?: number, reason?: string): void;
|
|
94
83
|
setTimeout(call: () => void, time: number): number;
|
|
95
|
-
/**
|
|
96
|
-
* Sets an interval that will automatically end when the socket closes
|
|
97
|
-
* @param call The function to call
|
|
98
|
-
* @param time The time between calls (ms)
|
|
99
|
-
*/
|
|
100
84
|
setInterval(call: () => void, time: number): number;
|
|
85
|
+
clearTimeout(id: number): void;
|
|
86
|
+
clearInterval(id: number): void;
|
|
101
87
|
}
|