Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer 5b87187bc0
*Update dist 2023-02-06 05:51:41 -05:00
Derrick Hammer b4b30cbdea
*If data is a Uint8Array, convert to a buffer 2023-02-06 05:51:13 -05:00
3 changed files with 18 additions and 1 deletions

9
dist/peer.js vendored
View File

@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const socket_js_1 = __importDefault(require("./socket.js"));
const buffer_1 = require("buffer");
class Peer {
_proxy;
_peer;
@ -33,7 +34,10 @@ class Peer {
protocol: this._proxy.protocol,
async onopen(m) {
if (!m) {
m = Buffer.from([]);
m = buffer_1.Buffer.from([]);
}
if (m instanceof Uint8Array) {
m = buffer_1.Buffer.from(m);
}
self._socket = new socket_js_1.default({
remoteAddress: self._peer.rawStream.remoteHost,
@ -55,6 +59,9 @@ class Peer {
});
const pipe = channel.addMessage({
async onmessage(m) {
if (m instanceof Uint8Array) {
m = buffer_1.Buffer.from(m);
}
self._socket.emit("data", m);
await self._onreceive?.(m);
},

View File

@ -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"

View File

@ -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);
},