Compare commits
2 Commits
8b678e81e8
...
10a7b4ebc6
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 10a7b4ebc6 | |
Derrick Hammer | 1c9a430d5e |
|
@ -10,7 +10,7 @@ export interface MultiSocketProxyOptions extends ProxyOptions {
|
|||
allowedPorts?: number[];
|
||||
}
|
||||
export default class MultiSocketProxy extends Proxy {
|
||||
handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions): void;
|
||||
handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions): Promise<void>;
|
||||
private socketClass;
|
||||
private _peers;
|
||||
private _nextPeer;
|
||||
|
|
|
@ -55,14 +55,16 @@ const errorSocketEncoding = {
|
|||
};
|
||||
const nextSocketId = (0, util_js_1.idFactory)(1);
|
||||
class MultiSocketProxy extends proxy_js_1.default {
|
||||
handlePeer({ peer, muxer, ...options }) {
|
||||
new peer_js_1.default({
|
||||
async handlePeer({ peer, muxer, ...options }) {
|
||||
const conn = new peer_js_1.default({
|
||||
...this.socketOptions,
|
||||
proxy: this,
|
||||
peer,
|
||||
muxer,
|
||||
...options,
|
||||
}).init();
|
||||
});
|
||||
await conn.init();
|
||||
this.emit("peer", conn);
|
||||
}
|
||||
socketClass;
|
||||
_peers = new Map();
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
/// <reference types="node" />
|
||||
import { DataSocketOptions, PeerOptions } from "./peer.js";
|
||||
import EventEmitter from "events";
|
||||
export interface ProxyOptions extends DataSocketOptions {
|
||||
swarm: any;
|
||||
protocol: string;
|
||||
listen?: boolean;
|
||||
autostart?: boolean;
|
||||
}
|
||||
export default abstract class Proxy {
|
||||
export default abstract class Proxy extends EventEmitter {
|
||||
protected _listen: any;
|
||||
protected _autostart: boolean;
|
||||
constructor({ swarm, protocol, onopen, onreceive, onsend, onclose, onchannel, listen, autostart, emulateWebsocket, }: ProxyOptions);
|
||||
|
|
|
@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const protomux_1 = __importDefault(require("protomux"));
|
||||
class Proxy {
|
||||
const events_1 = __importDefault(require("events"));
|
||||
class Proxy extends events_1.default {
|
||||
_listen;
|
||||
_autostart;
|
||||
constructor({ swarm, protocol, onopen, onreceive, onsend, onclose, onchannel, listen = false, autostart = false, emulateWebsocket = false, }) {
|
||||
super();
|
||||
this._swarm = swarm;
|
||||
this._protocol = protocol;
|
||||
this._listen = listen;
|
||||
|
|
|
@ -70,14 +70,20 @@ const errorSocketEncoding = {
|
|||
const nextSocketId = idFactory(1);
|
||||
|
||||
export default class MultiSocketProxy extends Proxy {
|
||||
handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions) {
|
||||
new Peer({
|
||||
async handlePeer({
|
||||
peer,
|
||||
muxer,
|
||||
...options
|
||||
}: DataSocketOptions & PeerOptions) {
|
||||
const conn = new Peer({
|
||||
...this.socketOptions,
|
||||
proxy: this,
|
||||
peer,
|
||||
muxer,
|
||||
...options,
|
||||
}).init();
|
||||
});
|
||||
await conn.init();
|
||||
this.emit("peer", conn);
|
||||
}
|
||||
private socketClass: any;
|
||||
private _peers: Map<string, PeerEntity> = new Map<string, PeerEntity>();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import Protomux from "protomux";
|
||||
import { DataSocketOptions, PeerOptions } from "./peer.js";
|
||||
import EventEmitter from "events";
|
||||
|
||||
export interface ProxyOptions extends DataSocketOptions {
|
||||
swarm: any;
|
||||
|
@ -8,7 +9,7 @@ export interface ProxyOptions extends DataSocketOptions {
|
|||
autostart?: boolean;
|
||||
}
|
||||
|
||||
export default abstract class Proxy {
|
||||
export default abstract class Proxy extends EventEmitter {
|
||||
protected _listen: any;
|
||||
protected _autostart: boolean;
|
||||
|
||||
|
@ -24,6 +25,7 @@ export default abstract class Proxy {
|
|||
autostart = false,
|
||||
emulateWebsocket = false,
|
||||
}: ProxyOptions) {
|
||||
super();
|
||||
this._swarm = swarm;
|
||||
this._protocol = protocol;
|
||||
this._listen = listen;
|
||||
|
|
Loading…
Reference in New Issue