*If data is a Uint8Array, convert to a buffer
This commit is contained in:
parent
81559342be
commit
b4b30cbdea
|
@ -9,6 +9,7 @@
|
|||
"typescript": "^4.9.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"compact-encoding": "^2.11.0",
|
||||
"protomux": "^3.4.0",
|
||||
"streamx": "^2.13.0"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import Proxy from "./proxy.js";
|
||||
import Socket from "./socket.js";
|
||||
import { Buffer } from "buffer";
|
||||
export type OnOpen = (
|
||||
socket: Socket,
|
||||
data: any
|
||||
|
@ -70,6 +71,10 @@ export default class Peer {
|
|||
if (!m) {
|
||||
m = Buffer.from([]);
|
||||
}
|
||||
|
||||
if (m instanceof Uint8Array) {
|
||||
m = Buffer.from(m);
|
||||
}
|
||||
self._socket = new Socket({
|
||||
remoteAddress: self._peer.rawStream.remoteHost,
|
||||
remotePort: self._peer.rawStream.remotePort,
|
||||
|
@ -81,6 +86,7 @@ export default class Peer {
|
|||
// @ts-ignore
|
||||
self._socket.emit("connect");
|
||||
}
|
||||
|
||||
self._socket.emit("data", m);
|
||||
},
|
||||
async onclose() {
|
||||
|
@ -90,6 +96,9 @@ export default class Peer {
|
|||
});
|
||||
const pipe = channel.addMessage({
|
||||
async onmessage(m: any) {
|
||||
if (m instanceof Uint8Array) {
|
||||
m = Buffer.from(m);
|
||||
}
|
||||
self._socket.emit("data", m);
|
||||
await self._onreceive?.(m);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue