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