Compare commits

..

No commits in common. "10a7b4ebc63f60fd622dd4621cc46b17276cadb2" and "8b678e81e899cac598cd7a7947a57a2ee5cc80d2" have entirely different histories.

6 changed files with 10 additions and 24 deletions

View File

@ -10,7 +10,7 @@ export interface MultiSocketProxyOptions extends ProxyOptions {
allowedPorts?: number[]; allowedPorts?: number[];
} }
export default class MultiSocketProxy extends Proxy { export default class MultiSocketProxy extends Proxy {
handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions): Promise<void>; handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions): void;
private socketClass; private socketClass;
private _peers; private _peers;
private _nextPeer; private _nextPeer;

View File

@ -55,16 +55,14 @@ const errorSocketEncoding = {
}; };
const nextSocketId = (0, util_js_1.idFactory)(1); const nextSocketId = (0, util_js_1.idFactory)(1);
class MultiSocketProxy extends proxy_js_1.default { class MultiSocketProxy extends proxy_js_1.default {
async handlePeer({ peer, muxer, ...options }) { handlePeer({ peer, muxer, ...options }) {
const conn = new peer_js_1.default({ new peer_js_1.default({
...this.socketOptions, ...this.socketOptions,
proxy: this, proxy: this,
peer, peer,
muxer, muxer,
...options, ...options,
}); }).init();
await conn.init();
this.emit("peer", conn);
} }
socketClass; socketClass;
_peers = new Map(); _peers = new Map();

4
dist/proxy.d.ts vendored
View File

@ -1,13 +1,11 @@
/// <reference types="node" />
import { DataSocketOptions, PeerOptions } from "./peer.js"; import { DataSocketOptions, PeerOptions } from "./peer.js";
import EventEmitter from "events";
export interface ProxyOptions extends DataSocketOptions { export interface ProxyOptions extends DataSocketOptions {
swarm: any; swarm: any;
protocol: string; protocol: string;
listen?: boolean; listen?: boolean;
autostart?: boolean; autostart?: boolean;
} }
export default abstract class Proxy extends EventEmitter { export default abstract class Proxy {
protected _listen: any; protected _listen: any;
protected _autostart: boolean; protected _autostart: boolean;
constructor({ swarm, protocol, onopen, onreceive, onsend, onclose, onchannel, listen, autostart, emulateWebsocket, }: ProxyOptions); constructor({ swarm, protocol, onopen, onreceive, onsend, onclose, onchannel, listen, autostart, emulateWebsocket, }: ProxyOptions);

4
dist/proxy.js vendored
View File

@ -4,12 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const protomux_1 = __importDefault(require("protomux")); const protomux_1 = __importDefault(require("protomux"));
const events_1 = __importDefault(require("events")); class Proxy {
class Proxy extends events_1.default {
_listen; _listen;
_autostart; _autostart;
constructor({ swarm, protocol, onopen, onreceive, onsend, onclose, onchannel, listen = false, autostart = false, emulateWebsocket = false, }) { constructor({ swarm, protocol, onopen, onreceive, onsend, onclose, onchannel, listen = false, autostart = false, emulateWebsocket = false, }) {
super();
this._swarm = swarm; this._swarm = swarm;
this._protocol = protocol; this._protocol = protocol;
this._listen = listen; this._listen = listen;

View File

@ -70,20 +70,14 @@ const errorSocketEncoding = {
const nextSocketId = idFactory(1); const nextSocketId = idFactory(1);
export default class MultiSocketProxy extends Proxy { export default class MultiSocketProxy extends Proxy {
async handlePeer({ handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions) {
peer, new Peer({
muxer,
...options
}: DataSocketOptions & PeerOptions) {
const conn = new Peer({
...this.socketOptions, ...this.socketOptions,
proxy: this, proxy: this,
peer, peer,
muxer, muxer,
...options, ...options,
}); }).init();
await conn.init();
this.emit("peer", conn);
} }
private socketClass: any; private socketClass: any;
private _peers: Map<string, PeerEntity> = new Map<string, PeerEntity>(); private _peers: Map<string, PeerEntity> = new Map<string, PeerEntity>();

View File

@ -1,6 +1,5 @@
import Protomux from "protomux"; import Protomux from "protomux";
import { DataSocketOptions, PeerOptions } from "./peer.js"; import { DataSocketOptions, PeerOptions } from "./peer.js";
import EventEmitter from "events";
export interface ProxyOptions extends DataSocketOptions { export interface ProxyOptions extends DataSocketOptions {
swarm: any; swarm: any;
@ -9,7 +8,7 @@ export interface ProxyOptions extends DataSocketOptions {
autostart?: boolean; autostart?: boolean;
} }
export default abstract class Proxy extends EventEmitter { export default abstract class Proxy {
protected _listen: any; protected _listen: any;
protected _autostart: boolean; protected _autostart: boolean;
@ -25,7 +24,6 @@ export default abstract class Proxy extends EventEmitter {
autostart = false, autostart = false,
emulateWebsocket = false, emulateWebsocket = false,
}: ProxyOptions) { }: ProxyOptions) {
super();
this._swarm = swarm; this._swarm = swarm;
this._protocol = protocol; this._protocol = protocol;
this._listen = listen; this._listen = listen;