mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 17:18:25 +08:00
add comment
This commit is contained in:
@@ -86,7 +86,7 @@ vlessWServer.on('connection', async function connection(ws) {
|
|||||||
new WritableStream({
|
new WritableStream({
|
||||||
async write(chunk: Buffer, controller) {
|
async write(chunk: Buffer, controller) {
|
||||||
if (remoteConnection) {
|
if (remoteConnection) {
|
||||||
await wsAsyncWrite(remoteConnection, chunk);
|
await socketAsyncWrite(remoteConnection, chunk);
|
||||||
// remoteConnection.write(chunk);
|
// remoteConnection.write(chunk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ vlessWServer.on('connection', async function connection(ws) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async write(chunk: Uint8Array, controller) {
|
async write(chunk: Uint8Array, controller) {
|
||||||
ws.send(chunk);
|
await wsAsyncWrite(ws, chunk);
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -206,9 +206,21 @@ async function connect2Remote(port, host, log: Function): Promise<Socket> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function wsAsyncWrite(ws: Socket, chunk: Buffer) {
|
async function socketAsyncWrite(ws: Socket, chunk: Buffer) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ws.write(Buffer.from(chunk), (error) => {
|
ws.write(chunk, (error) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function wsAsyncWrite(ws: WebSocket, chunk: Uint8Array) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ws.send(chunk, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -176,6 +176,8 @@ export function makeReadableWebSocketStream(
|
|||||||
// console.log('MESSAGE', vlessBuffer);
|
// console.log('MESSAGE', vlessBuffer);
|
||||||
|
|
||||||
// console.log(`message is ${vlessBuffer.byteLength}`);
|
// console.log(`message is ${vlessBuffer.byteLength}`);
|
||||||
|
// this is not backpressure, but backpressure is depends on underying websocket can pasue
|
||||||
|
// https://streams.spec.whatwg.org/#example-rs-push-backpressure
|
||||||
controller.enqueue(vlessBuffer);
|
controller.enqueue(vlessBuffer);
|
||||||
});
|
});
|
||||||
ws.addEventListener('error', (e: any) => {
|
ws.addEventListener('error', (e: any) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user