Compare commits
2 Commits
619fe7913c
...
27261fedd2
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 27261fedd2 | |
Derrick Hammer | 2e639eb92a |
|
@ -35,12 +35,18 @@ class Peer {
|
||||||
return this._channel;
|
return this._channel;
|
||||||
}
|
}
|
||||||
async init() {
|
async init() {
|
||||||
const write = async (data, cb) => {
|
|
||||||
pipe.send(data);
|
|
||||||
await this._onsend?.(data);
|
|
||||||
cb();
|
|
||||||
};
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
this._socket = new socket_js_1.default({
|
||||||
|
remoteAddress: self._peer.rawStream.remoteHost,
|
||||||
|
remotePort: self._peer.rawStream.remotePort,
|
||||||
|
remotePublicKey: self._peer.remotePublicKey,
|
||||||
|
async write(data, cb) {
|
||||||
|
pipe.send(data);
|
||||||
|
await self._onsend?.(data);
|
||||||
|
cb();
|
||||||
|
},
|
||||||
|
emulateWebsocket: self._emulateWebsocket,
|
||||||
|
});
|
||||||
this._channel = this._muxer.createChannel({
|
this._channel = this._muxer.createChannel({
|
||||||
protocol: this._proxy.protocol,
|
protocol: this._proxy.protocol,
|
||||||
async onopen(m) {
|
async onopen(m) {
|
||||||
|
@ -50,13 +56,6 @@ class Peer {
|
||||||
if (m instanceof Uint8Array) {
|
if (m instanceof Uint8Array) {
|
||||||
m = buffer_1.Buffer.from(m);
|
m = buffer_1.Buffer.from(m);
|
||||||
}
|
}
|
||||||
self._socket = new socket_js_1.default({
|
|
||||||
remoteAddress: self._peer.rawStream.remoteHost,
|
|
||||||
remotePort: self._peer.rawStream.remotePort,
|
|
||||||
remotePublicKey: self._peer.remotePublicKey,
|
|
||||||
write,
|
|
||||||
emulateWebsocket: self._emulateWebsocket,
|
|
||||||
});
|
|
||||||
self._socket.on("end", () => this._channel.close());
|
self._socket.on("end", () => this._channel.close());
|
||||||
let ret = await self._onopen?.(self._socket, m);
|
let ret = await self._onopen?.(self._socket, m);
|
||||||
if (!ret || (ret && ret.connect === false)) {
|
if (!ret || (ret && ret.connect === false)) {
|
||||||
|
|
25
src/peer.ts
25
src/peer.ts
|
@ -95,12 +95,19 @@ export default class Peer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
const write = async (data: any, cb: Function) => {
|
|
||||||
pipe.send(data);
|
|
||||||
await this._onsend?.(data);
|
|
||||||
cb();
|
|
||||||
};
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
this._socket = new Socket({
|
||||||
|
remoteAddress: self._peer.rawStream.remoteHost,
|
||||||
|
remotePort: self._peer.rawStream.remotePort,
|
||||||
|
remotePublicKey: self._peer.remotePublicKey,
|
||||||
|
async write(data: any, cb: Function) {
|
||||||
|
pipe.send(data);
|
||||||
|
await self._onsend?.(data);
|
||||||
|
cb();
|
||||||
|
},
|
||||||
|
emulateWebsocket: self._emulateWebsocket,
|
||||||
|
});
|
||||||
|
|
||||||
this._channel = this._muxer.createChannel({
|
this._channel = this._muxer.createChannel({
|
||||||
protocol: this._proxy.protocol,
|
protocol: this._proxy.protocol,
|
||||||
async onopen(m: any) {
|
async onopen(m: any) {
|
||||||
|
@ -111,13 +118,7 @@ export default class Peer {
|
||||||
if (m instanceof Uint8Array) {
|
if (m instanceof Uint8Array) {
|
||||||
m = Buffer.from(m);
|
m = Buffer.from(m);
|
||||||
}
|
}
|
||||||
self._socket = new Socket({
|
|
||||||
remoteAddress: self._peer.rawStream.remoteHost,
|
|
||||||
remotePort: self._peer.rawStream.remotePort,
|
|
||||||
remotePublicKey: self._peer.remotePublicKey,
|
|
||||||
write,
|
|
||||||
emulateWebsocket: self._emulateWebsocket,
|
|
||||||
});
|
|
||||||
self._socket.on("end", () => this._channel.close());
|
self._socket.on("end", () => this._channel.close());
|
||||||
let ret = await self._onopen?.(self._socket, m);
|
let ret = await self._onopen?.(self._socket, m);
|
||||||
if (!ret || (ret && ret.connect === false)) {
|
if (!ret || (ret && ret.connect === false)) {
|
||||||
|
|
Loading…
Reference in New Issue