@seriousme/opifex 2.3.0 → 2.4.1
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/client/client.ts +5 -0
- package/connNext/baseConnNext.ts +123 -0
- package/deno/tlsServer.test.ts +1 -1
- package/deno/wsServer.ts +11 -3
- package/dev_utils/WebStreamEndpoint.ts +5 -0
- package/dev_utils/asyncStreamEndpoint.ts +5 -0
- package/dev_utils/asyncStreamPair.ts +4 -9
- package/dev_utils/asyncStreamPairToNext.ts +45 -0
- package/dev_utils/asyncStreamToNext.ts +30 -137
- package/dev_utils/connNextPair.test.ts +2 -2
- package/dev_utils/generateCert.ts +297 -77
- package/dev_utils/mockConn.ts +37 -93
- package/dev_utils/mockServer.ts +1 -1
- package/dev_utils/webStreamPair.ts +3 -7
- package/dev_utils/webStreamPairToNext.ts +48 -0
- package/dev_utils/webStreamToNext.ts +28 -161
- package/dist/client/client.d.ts +4 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +3 -0
- package/dist/client/client.js.map +1 -1
- package/dist/connNext/baseConnNext.d.ts +20 -0
- package/dist/connNext/baseConnNext.d.ts.map +1 -0
- package/dist/connNext/baseConnNext.js +95 -0
- package/dist/connNext/baseConnNext.js.map +1 -0
- package/dist/dev_utils/generateCert.d.ts +5 -4
- package/dist/dev_utils/generateCert.d.ts.map +1 -1
- package/dist/dev_utils/generateCert.js +230 -65
- package/dist/dev_utils/generateCert.js.map +1 -1
- package/dist/examples/mqtt+mqtts.test.js +1 -1
- package/dist/examples/mqtt+mqtts.test.js.map +1 -1
- package/dist/examples/mqtts.test.js +1 -1
- package/dist/examples/mqtts.test.js.map +1 -1
- package/dist/node/nodeSocketToNext.d.ts +10 -13
- package/dist/node/nodeSocketToNext.d.ts.map +1 -1
- package/dist/node/nodeSocketToNext.js +75 -131
- package/dist/node/nodeSocketToNext.js.map +1 -1
- package/dist/web/webSocketToNext.d.ts +18 -1
- package/dist/web/webSocketToNext.d.ts.map +1 -1
- package/dist/web/webSocketToNext.js +92 -127
- package/dist/web/webSocketToNext.js.map +1 -1
- package/dist/web/wsClient.d.ts.map +1 -1
- package/dist/web/wsClient.js +4 -3
- package/dist/web/wsClient.js.map +1 -1
- package/examples/mqtt+mqtts.test.ts +1 -1
- package/examples/mqtts.test.ts +1 -1
- package/node/nodeSocketToNext.ts +85 -148
- package/node/tlsServer.test.ts +1 -1
- package/package.json +2 -4
- package/web/webSocketToNext.ts +108 -145
- package/web/wsClient.ts +10 -3
- package/dev_utils/webStreamPair.test.ts +0 -171
|
@@ -1,161 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
export class
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
-
|
|
13
|
-
/** Create a new ConnNext object from a Webstream */
|
|
14
|
-
constructor(endPoint) {
|
|
15
|
-
this.endPoint = endPoint;
|
|
16
|
-
this.closed = false;
|
|
17
|
-
this.endPoint;
|
|
1
|
+
import { BaseConnNext } from "../connNext/baseConnNext.js";
|
|
2
|
+
export class NodeSocketConnNext extends BaseConnNext {
|
|
3
|
+
socket;
|
|
4
|
+
constructor(socket) {
|
|
5
|
+
super();
|
|
6
|
+
this.socket = socket;
|
|
7
|
+
const markClosed = () => {
|
|
8
|
+
this.closed = true;
|
|
9
|
+
};
|
|
10
|
+
this.socket.on("end", markClosed);
|
|
11
|
+
this.socket.on("close", markClosed);
|
|
12
|
+
this.socket.on("error", markClosed);
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const chunk = this.endPoint.read();
|
|
26
|
-
return chunk
|
|
27
|
-
? Promise.resolve(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength))
|
|
28
|
-
: Promise.resolve(null);
|
|
29
|
-
}
|
|
30
|
-
if (length === 0) {
|
|
31
|
-
return new Uint8Array(0);
|
|
32
|
-
}
|
|
33
|
-
const result = new Uint8Array(length);
|
|
34
|
-
let bytesAccumulated = 0;
|
|
35
|
-
// 1. Process leftover data from the previous read operation
|
|
36
|
-
if (this.leftover.byteLength > 0) {
|
|
37
|
-
const take = Math.min(this.leftover.byteLength, length);
|
|
38
|
-
result.set(this.leftover.subarray(0, take), bytesAccumulated);
|
|
39
|
-
bytesAccumulated += take;
|
|
40
|
-
this.leftover = this.leftover.subarray(take);
|
|
41
|
-
}
|
|
42
|
-
// 2. Loop until the requested number of bytes is accumulated
|
|
43
|
-
while (bytesAccumulated < length) {
|
|
44
|
-
if (this.closed || !this.endPoint.readable) {
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
const chunk = this.endPoint.read();
|
|
48
|
-
if (chunk === null) {
|
|
49
|
-
await new Promise((resolve) => {
|
|
50
|
-
const cleanup = () => {
|
|
51
|
-
this.endPoint.off("readable", onEvent);
|
|
52
|
-
this.endPoint.off("end", onEvent);
|
|
53
|
-
this.endPoint.off("error", onEvent);
|
|
54
|
-
this.endPoint.off("close", onEvent);
|
|
55
|
-
};
|
|
56
|
-
const onEvent = () => {
|
|
57
|
-
cleanup();
|
|
58
|
-
resolve();
|
|
59
|
-
};
|
|
60
|
-
this.endPoint.on("readable", onEvent);
|
|
61
|
-
this.endPoint.on("end", onEvent);
|
|
62
|
-
this.endPoint.on("error", onEvent);
|
|
63
|
-
this.endPoint.on("close", onEvent);
|
|
64
|
-
});
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
// 3. Process the retrieved chunk
|
|
68
|
-
const chunkLength = chunk.byteLength;
|
|
69
|
-
const needed = length - bytesAccumulated;
|
|
70
|
-
if (chunkLength <= needed) {
|
|
71
|
-
result.set(chunk, bytesAccumulated);
|
|
72
|
-
bytesAccumulated += chunkLength;
|
|
14
|
+
get localAddr() {
|
|
15
|
+
return this.socket.localAddress
|
|
16
|
+
? {
|
|
17
|
+
transport: "tcp",
|
|
18
|
+
hostname: this.socket.localAddress,
|
|
19
|
+
port: this.socket.localPort ?? 0,
|
|
73
20
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
23
|
+
get remoteAddr() {
|
|
24
|
+
return this.socket.remoteAddress
|
|
25
|
+
? {
|
|
26
|
+
transport: "tcp",
|
|
27
|
+
hostname: this.socket.remoteAddress,
|
|
28
|
+
port: this.socket.remotePort ?? 0,
|
|
78
29
|
}
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Haalt direct op verzoek een chunk op via Node's ingebouwde socket.read() mechanisme.
|
|
34
|
+
*/
|
|
35
|
+
pullNextChunk() {
|
|
36
|
+
if (this.closed || !this.socket.readable) {
|
|
37
|
+
return Promise.resolve(null);
|
|
79
38
|
}
|
|
80
|
-
|
|
81
|
-
|
|
39
|
+
// Vraag direct om data uit de Node socket buffer
|
|
40
|
+
const chunk = this.socket.read();
|
|
41
|
+
if (chunk !== null) {
|
|
42
|
+
return Promise.resolve(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
82
43
|
}
|
|
83
|
-
|
|
44
|
+
// Als er nog geen data is ('null'), wachten we op het 'readable' (of 'end'/'close') event van Node
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const cleanup = () => {
|
|
47
|
+
this.socket.off("readable", onReadable);
|
|
48
|
+
this.socket.off("end", onEnd);
|
|
49
|
+
this.socket.off("error", onClose);
|
|
50
|
+
this.socket.off("close", onClose);
|
|
51
|
+
};
|
|
52
|
+
const onReadable = () => {
|
|
53
|
+
cleanup();
|
|
54
|
+
// Roep zichzelf direct weer aan om de data op te halen
|
|
55
|
+
resolve(this.pullNextChunk());
|
|
56
|
+
};
|
|
57
|
+
const onEnd = () => {
|
|
58
|
+
cleanup();
|
|
59
|
+
this.closed = true;
|
|
60
|
+
resolve(null);
|
|
61
|
+
};
|
|
62
|
+
const onClose = () => {
|
|
63
|
+
cleanup();
|
|
64
|
+
this.closed = true;
|
|
65
|
+
resolve(null);
|
|
66
|
+
};
|
|
67
|
+
this.socket.on("readable", onReadable);
|
|
68
|
+
this.socket.on("end", onEnd);
|
|
69
|
+
this.socket.on("error", onClose);
|
|
70
|
+
this.socket.on("close", onClose);
|
|
71
|
+
});
|
|
84
72
|
}
|
|
85
73
|
write(data) {
|
|
86
|
-
if (this.
|
|
87
|
-
return Promise.reject(new Error("
|
|
74
|
+
if (this.isClosed() || !this.socket.writable) {
|
|
75
|
+
return Promise.reject(new Error("Socket is closed or not writable"));
|
|
88
76
|
}
|
|
89
77
|
return new Promise((resolve, reject) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (err) {
|
|
78
|
+
const canWriteMore = this.socket.write(data, (err) => {
|
|
79
|
+
if (err)
|
|
93
80
|
reject(err);
|
|
94
|
-
}
|
|
95
81
|
});
|
|
96
|
-
// 2. Determine when to resolve based on the return value of write()
|
|
97
82
|
if (canWriteMore) {
|
|
98
|
-
// If the buffer is not full, we can resolve immediately
|
|
99
83
|
resolve();
|
|
100
84
|
}
|
|
101
85
|
else {
|
|
102
|
-
|
|
103
|
-
this.endPoint.once("drain", () => {
|
|
104
|
-
resolve();
|
|
105
|
-
});
|
|
86
|
+
this.socket.once("drain", resolve);
|
|
106
87
|
}
|
|
107
88
|
});
|
|
108
89
|
}
|
|
109
90
|
close() {
|
|
110
91
|
if (!this.closed) {
|
|
111
92
|
this.closed = true;
|
|
112
|
-
// Clean up permanent event listeners to prevent memory leaks
|
|
113
|
-
this.endPoint.off("close", this.onClose);
|
|
114
|
-
this.endPoint.off("error", this.onError);
|
|
115
|
-
// Safely destroy the stream first, then trigger the closer callback
|
|
116
93
|
try {
|
|
117
|
-
this.
|
|
118
|
-
// deno-coverage-ignore
|
|
119
|
-
}
|
|
120
|
-
catch (_) {
|
|
121
|
-
// Suppress stream destruction errors
|
|
122
|
-
// deno-coverage-ignore
|
|
94
|
+
this.socket.destroy();
|
|
123
95
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
async *[Symbol.asyncIterator]() {
|
|
127
|
-
while (true) {
|
|
128
|
-
const chunk = await this.read();
|
|
129
|
-
if (chunk === null) {
|
|
130
|
-
break;
|
|
96
|
+
catch {
|
|
97
|
+
/* swallow */
|
|
131
98
|
}
|
|
132
|
-
yield chunk;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// Convert addresses to custom ConnAddr format
|
|
136
|
-
get localAddr() {
|
|
137
|
-
if (this.endPoint.localAddress) {
|
|
138
|
-
return {
|
|
139
|
-
transport: "tcp",
|
|
140
|
-
hostname: this.endPoint.localAddress,
|
|
141
|
-
port: this.endPoint.localPort ?? 0,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
get remoteAddr() {
|
|
147
|
-
if (this.endPoint.remoteAddress) {
|
|
148
|
-
return {
|
|
149
|
-
transport: "tcp",
|
|
150
|
-
hostname: this.endPoint.remoteAddress,
|
|
151
|
-
port: this.endPoint.remotePort ?? 0,
|
|
152
|
-
};
|
|
153
99
|
}
|
|
154
|
-
return undefined;
|
|
155
100
|
}
|
|
156
101
|
}
|
|
157
102
|
export function nodeSocketToNext(socket) {
|
|
158
|
-
|
|
159
|
-
return connNext;
|
|
103
|
+
return new NodeSocketConnNext(socket);
|
|
160
104
|
}
|
|
161
105
|
//# sourceMappingURL=nodeSocketToNext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeSocketToNext.js","sourceRoot":"","sources":["../../node/nodeSocketToNext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodeSocketToNext.js","sourceRoot":"","sources":["../../node/nodeSocketToNext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,MAAM,OAAO,kBAAmB,SA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|
2
|
-
|
|
2
|
+
import { BaseConnNext } from "../connNext/baseConnNext.ts";
|
|
3
|
+
export declare class WebSocketConnNext extends BaseConnNext {
|
|
4
|
+
localAddr: undefined;
|
|
5
|
+
remoteAddr?: ConnAddr;
|
|
6
|
+
private ws;
|
|
7
|
+
private messageQueue;
|
|
8
|
+
private maxBufferSize;
|
|
9
|
+
private currentBufferSize;
|
|
10
|
+
private readResolvers;
|
|
11
|
+
constructor(ws: WebSocket, remoteAddr?: ConnAddr, maxBufferSize?: number);
|
|
12
|
+
private notifyWaiters;
|
|
13
|
+
private waitForData;
|
|
14
|
+
ensureOpen(): Promise<void>;
|
|
15
|
+
protected pullNextChunk(): Promise<Uint8Array | null>;
|
|
16
|
+
write(data: Uint8Array): Promise<void>;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function webSocketToNext(ws: WebSocket, remoteAddr?: ConnAddr, maxBufferSize?: number): Promise<ConnNext>;
|
|
3
20
|
//# sourceMappingURL=webSocketToNext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSocketToNext.d.ts","sourceRoot":"","sources":["../../web/webSocketToNext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"webSocketToNext.d.ts","sourceRoot":"","sources":["../../web/webSocketToNext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,SAAS,YAAa;IACtB,UAAU,CAAC,EAAE,QAAQ,CAAC;IAEtB,OAAO,CAAC,EAAE,CAAY;IACtB,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,aAAa,CAAyB;IAE9C,YACE,EAAE,EAAE,SAAS,EACb,UAAU,CAAC,EAAE,QAAQ,EACrB,aAAa,SAAkB,EAqChC;IAED,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,WAAW;IAMnB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CA8B1B;IAED,UAAgB,aAAa,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAU1D;IAEK,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAU3C;IAED,KAAK,IAAI,IAAI,CASZ;CACF;AAED,wBAAsB,eAAe,CACnC,EAAE,EAAE,SAAS,EACb,UAAU,CAAC,EAAE,QAAQ,EACrB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,QAAQ,CAAC,CAInB"}
|
|
@@ -1,20 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { BaseConnNext } from "../connNext/baseConnNext.js";
|
|
2
|
+
import { delay } from "../utils/utils.js";
|
|
3
|
+
export class WebSocketConnNext extends BaseConnNext {
|
|
4
|
+
localAddr = undefined;
|
|
5
|
+
remoteAddr;
|
|
6
|
+
ws;
|
|
7
|
+
messageQueue = [];
|
|
8
|
+
maxBufferSize;
|
|
9
|
+
currentBufferSize = 0;
|
|
10
|
+
readResolvers = [];
|
|
11
|
+
constructor(ws, remoteAddr, maxBufferSize = 1 * 1024 * 1024) {
|
|
12
|
+
super();
|
|
13
|
+
this.ws = ws;
|
|
14
|
+
this.remoteAddr = remoteAddr;
|
|
15
|
+
this.maxBufferSize = maxBufferSize;
|
|
16
|
+
this.ws.binaryType = "arraybuffer";
|
|
17
|
+
this.ws.addEventListener("message", (event) => {
|
|
18
|
+
let chunk;
|
|
19
|
+
if (typeof event.data === "string") {
|
|
20
|
+
chunk = new TextEncoder().encode(event.data);
|
|
21
|
+
}
|
|
22
|
+
else if (event.data instanceof ArrayBuffer) {
|
|
23
|
+
chunk = new Uint8Array(event.data);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Check the bufferlimit (Throttling / Overflow protection)
|
|
29
|
+
if (this.currentBufferSize + chunk.byteLength > this.maxBufferSize) {
|
|
30
|
+
this.close();
|
|
31
|
+
throw new Error("WebSocket buffer overflow: Too much unread data from push source");
|
|
32
|
+
}
|
|
33
|
+
this.messageQueue.push(chunk);
|
|
34
|
+
this.currentBufferSize += chunk.byteLength;
|
|
35
|
+
this.notifyWaiters();
|
|
36
|
+
});
|
|
37
|
+
const onClose = () => {
|
|
38
|
+
this.closed = true;
|
|
39
|
+
this.notifyWaiters();
|
|
40
|
+
};
|
|
41
|
+
this.ws.addEventListener("close", onClose);
|
|
42
|
+
this.ws.addEventListener("error", onClose);
|
|
43
|
+
}
|
|
44
|
+
notifyWaiters() {
|
|
45
|
+
while (this.readResolvers.length > 0) {
|
|
46
|
+
const resolve = this.readResolvers.shift();
|
|
9
47
|
resolve?.();
|
|
10
48
|
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
49
|
+
}
|
|
50
|
+
waitForData() {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
this.readResolvers.push(resolve);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
ensureOpen() {
|
|
56
|
+
if (this.ws.readyState === WebSocket.OPEN) {
|
|
15
57
|
return Promise.resolve();
|
|
16
58
|
}
|
|
17
|
-
if (ws.readyState >= WebSocket.CLOSING) {
|
|
59
|
+
if (this.ws.readyState >= WebSocket.CLOSING) {
|
|
18
60
|
return Promise.reject(new Error("WebSocket is closing or closed"));
|
|
19
61
|
}
|
|
20
62
|
return new Promise((resolve, reject) => {
|
|
@@ -31,130 +73,53 @@ export async function webSocketToNext(ws, remoteAddr) {
|
|
|
31
73
|
reject(new Error("WebSocket closed before opening"));
|
|
32
74
|
};
|
|
33
75
|
const cleanup = () => {
|
|
34
|
-
ws.removeEventListener("open", onOpen);
|
|
35
|
-
ws.removeEventListener("error", onError);
|
|
36
|
-
ws.removeEventListener("close", onClose);
|
|
76
|
+
this.ws.removeEventListener("open", onOpen);
|
|
77
|
+
this.ws.removeEventListener("error", onError);
|
|
78
|
+
this.ws.removeEventListener("close", onClose);
|
|
37
79
|
};
|
|
38
|
-
ws.addEventListener("open", onOpen);
|
|
39
|
-
ws.addEventListener("error", onError);
|
|
40
|
-
ws.addEventListener("close", onClose);
|
|
80
|
+
this.ws.addEventListener("open", onOpen);
|
|
81
|
+
this.ws.addEventListener("error", onError);
|
|
82
|
+
this.ws.addEventListener("close", onClose);
|
|
41
83
|
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
chunk = new TextEncoder().encode(event.data);
|
|
47
|
-
}
|
|
48
|
-
else if (event.data instanceof ArrayBuffer) {
|
|
49
|
-
chunk = new Uint8Array(event.data);
|
|
84
|
+
}
|
|
85
|
+
async pullNextChunk() {
|
|
86
|
+
if (this.messageQueue.length === 0) {
|
|
87
|
+
await this.waitForData();
|
|
50
88
|
}
|
|
51
|
-
|
|
52
|
-
return;
|
|
89
|
+
if (this.closed) {
|
|
90
|
+
return null;
|
|
53
91
|
}
|
|
54
|
-
messageQueue.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
const chunk = this.messageQueue.shift();
|
|
93
|
+
this.currentBufferSize -= chunk.byteLength;
|
|
94
|
+
return chunk;
|
|
95
|
+
}
|
|
96
|
+
async write(data) {
|
|
97
|
+
if (this.isClosed())
|
|
98
|
+
throw new Error("WebSocket is closed");
|
|
99
|
+
this.ws.send(data.buffer);
|
|
100
|
+
// Check WebSocket bufferedAmount for write-backpressure
|
|
101
|
+
const HIGH_WATER_MARK = 64 * 1024;
|
|
102
|
+
while (this.ws.bufferedAmount > HIGH_WATER_MARK) {
|
|
103
|
+
if (this.isClosed())
|
|
104
|
+
throw new Error("WebSocket closed while writing");
|
|
105
|
+
await delay(10);
|
|
65
106
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
readResolvers.push(resolve);
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
const connNext = {
|
|
74
|
-
remoteAddr,
|
|
75
|
-
localAddr: undefined,
|
|
76
|
-
async read(length) {
|
|
107
|
+
}
|
|
108
|
+
close() {
|
|
109
|
+
if (!this.closed) {
|
|
110
|
+
this.closed = true;
|
|
77
111
|
try {
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
if (getBufferedBytes() === 0 && ws.readyState >= WebSocket.CLOSING) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
while (getBufferedBytes() === 0) {
|
|
87
|
-
if (ws.readyState >= WebSocket.CLOSING)
|
|
88
|
-
return null;
|
|
89
|
-
await waitForData();
|
|
90
|
-
}
|
|
91
|
-
if (length === undefined) {
|
|
92
|
-
const firstChunk = messageQueue.shift();
|
|
93
|
-
const result = firstChunk.subarray(queueOffset);
|
|
94
|
-
queueOffset = 0;
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
while (getBufferedBytes() < length) {
|
|
98
|
-
if (ws.readyState >= WebSocket.CLOSING) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
await waitForData();
|
|
102
|
-
}
|
|
103
|
-
const result = new Uint8Array(length);
|
|
104
|
-
let bytesCopied = 0;
|
|
105
|
-
while (bytesCopied < length && messageQueue.length > 0) {
|
|
106
|
-
const currentChunk = messageQueue[0];
|
|
107
|
-
const bytesNeeded = length - bytesCopied;
|
|
108
|
-
const bytesAvailable = currentChunk.byteLength - queueOffset;
|
|
109
|
-
if (bytesAvailable <= bytesNeeded) {
|
|
110
|
-
result.set(currentChunk.subarray(queueOffset), bytesCopied);
|
|
111
|
-
bytesCopied += bytesAvailable;
|
|
112
|
-
messageQueue.shift();
|
|
113
|
-
queueOffset = 0;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
result.set(currentChunk.subarray(queueOffset, queueOffset + bytesNeeded), bytesCopied);
|
|
117
|
-
bytesCopied += bytesNeeded;
|
|
118
|
-
queueOffset += bytesNeeded;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return result;
|
|
122
|
-
},
|
|
123
|
-
async write(data) {
|
|
124
|
-
await ensureOpen();
|
|
125
|
-
if (data instanceof Uint8Array) {
|
|
126
|
-
ws.send(data.buffer);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
ws.send(data);
|
|
130
|
-
}
|
|
131
|
-
const HIGH_WATER_MARK = 64 * 1024;
|
|
132
|
-
while (ws.bufferedAmount > HIGH_WATER_MARK) {
|
|
133
|
-
if (ws.readyState >= WebSocket.CLOSING) {
|
|
134
|
-
throw new Error("WebSocket closed while writing");
|
|
135
|
-
}
|
|
136
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
close() {
|
|
140
|
-
try {
|
|
141
|
-
ws.close();
|
|
112
|
+
this.ws.close();
|
|
142
113
|
}
|
|
143
114
|
catch {
|
|
144
115
|
/* swallow */
|
|
145
116
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
break;
|
|
153
|
-
yield chunk;
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
await ensureOpen();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export async function webSocketToNext(ws, remoteAddr, maxBufferSize) {
|
|
121
|
+
const connNext = new WebSocketConnNext(ws, remoteAddr, maxBufferSize);
|
|
122
|
+
await connNext.ensureOpen();
|
|
158
123
|
return connNext;
|
|
159
124
|
}
|
|
160
125
|
//# sourceMappingURL=webSocketToNext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSocketToNext.js","sourceRoot":"","sources":["../../web/webSocketToNext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webSocketToNext.js","sourceRoot":"","sources":["../../web/webSocketToNext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IACjD,SAAS,GAAG,SAAS,CAAC;IACtB,UAAU,CAAY;IAEd,EAAE,CAAY;IACd,YAAY,GAAiB,EAAE,CAAC;IAChC,aAAa,CAAS;IACtB,iBAAiB,GAAG,CAAC,CAAC;IACtB,aAAa,GAAsB,EAAE,CAAC;IAE9C,YACE,EAAa,EACb,UAAqB,EACrB,aAAa,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI;QAE/B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,EAAE,CAAC,UAAU,GAAG,aAAa,CAAC;QAEnC,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAmB,EAAE,EAAE;YAC1D,IAAI,KAAiB,CAAC;YACtB,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACnC,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC;iBAAM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,GAAG,IAAI,iBAAiB,CAAC,EAAE,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IACtE,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC5B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../web/wsClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,mBAAmB,CAAC;AAG3D;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,MAAM;IAClC,mDAAmD;YACrC,eAAe;
|
|
1
|
+
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../web/wsClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,mBAAmB,CAAC;AAG3D;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,MAAM;IAClC,mDAAmD;YACrC,eAAe;IAsB7B,iEAAiE;IACjE,UAAmB,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAC,CAcjD;CACF"}
|
package/dist/web/wsClient.js
CHANGED
|
@@ -13,7 +13,7 @@ import { webSocketToNext } from "./webSocketToNext.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export class WsClient extends Client {
|
|
15
15
|
/** create a websocket and wrap it in a ConnNext */
|
|
16
|
-
async establishSocket(url) {
|
|
16
|
+
async establishSocket(url, maxBufferSize) {
|
|
17
17
|
try {
|
|
18
18
|
const urlObj = new URL(url);
|
|
19
19
|
const remoteAddr = {
|
|
@@ -22,7 +22,7 @@ export class WsClient extends Client {
|
|
|
22
22
|
port: Number(urlObj.port || 0),
|
|
23
23
|
};
|
|
24
24
|
const ws = new WebSocket(url);
|
|
25
|
-
const connNext = await webSocketToNext(ws, remoteAddr);
|
|
25
|
+
const connNext = await webSocketToNext(ws, remoteAddr, maxBufferSize);
|
|
26
26
|
return connNext;
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
@@ -37,9 +37,10 @@ export class WsClient extends Client {
|
|
|
37
37
|
const { protocol, hostname, port: portStr, pathname } = this.connectUrl;
|
|
38
38
|
const port = portStr ? Number(portStr) : (protocol === "wss:" ? 443 : 80);
|
|
39
39
|
const path = pathname || "/mqtt";
|
|
40
|
+
const maxBufferSize = this.maxBufferSize;
|
|
40
41
|
logger.debug({ hostname, port, path });
|
|
41
42
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
42
|
-
return this.establishSocket(`${protocol}//${hostname}:${port}${path}
|
|
43
|
+
return this.establishSocket(`${protocol}//${hostname}:${port}${path}`, maxBufferSize);
|
|
43
44
|
}
|
|
44
45
|
throw new Error(`Unsupported protocol: ${protocol}`);
|
|
45
46
|
}
|
package/dist/web/wsClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsClient.js","sourceRoot":"","sources":["../../web/wsClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM;IAClC,mDAAmD;IAC3C,KAAK,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"wsClient.js","sourceRoot":"","sources":["../../web/wsClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;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KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;YAC9C,OAAO,IAAI,CAAC,eAAe,CACzB,GAAG,QAAQ,KAAK,QAAQ,IAAI,IAAI,GAAG,IAAI,EAAE,EACzC,aAAa,CACd,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -14,7 +14,7 @@ test("Test pubSub using TLS client and a TCP client", async function () {
|
|
|
14
14
|
// the localhost certs generate here are great for testing but lack securiity
|
|
15
15
|
// use something like LetsEncrypt for any serious server
|
|
16
16
|
// generateLocalhostCerts is a dev tool and relies on node-forge as a (dev)dependency
|
|
17
|
-
const { key, cert, caCert } = generateLocalhostCerts();
|
|
17
|
+
const { key, cert, caCert } = await generateLocalhostCerts();
|
|
18
18
|
// first create the mqttServer, so we can pass it to multiple protocol servers
|
|
19
19
|
const mqttServer = new MqttServer({});
|
|
20
20
|
|