Compare commits
3 Commits
5fa5385249
...
a8419313b5
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | a8419313b5 | |
Derrick Hammer | f11e3fed78 | |
Derrick Hammer | 95d866c69e |
|
@ -1,8 +1,9 @@
|
|||
/// <reference types="node" />
|
||||
import Proxy, { ProxyOptions } from "../proxy.js";
|
||||
import type { TcpSocketConnectOpts } from "net";
|
||||
import Peer, { DataSocketOptions, PeerOptions } from "../peer.js";
|
||||
import { DataSocketOptions, PeerOptions } from "../peer.js";
|
||||
import { PeerEntity } from "./multiSocket/types.js";
|
||||
import Peer from "./multiSocket/peer.js";
|
||||
export interface MultiSocketProxyOptions extends ProxyOptions {
|
||||
socketClass?: any;
|
||||
server: boolean;
|
||||
|
|
|
@ -10,6 +10,7 @@ const serialize_error_1 = require("serialize-error");
|
|||
const b4a_1 = __importDefault(require("b4a"));
|
||||
const util_js_1 = require("../util.js");
|
||||
const dummySocket_js_1 = __importDefault(require("./multiSocket/dummySocket.js"));
|
||||
const peer_js_1 = __importDefault(require("./multiSocket/peer.js"));
|
||||
const socketEncoding = {
|
||||
preencode(state, m) {
|
||||
compact_encoding_1.uint.preencode(state, m.id);
|
||||
|
@ -54,7 +55,15 @@ const errorSocketEncoding = {
|
|||
};
|
||||
const nextSocketId = (0, util_js_1.idFactory)(1);
|
||||
class MultiSocketProxy extends proxy_js_1.default {
|
||||
handlePeer({ peer, muxer, ...options }) { }
|
||||
handlePeer({ peer, muxer, ...options }) {
|
||||
new peer_js_1.default({
|
||||
...this.socketOptions,
|
||||
proxy: this,
|
||||
peer,
|
||||
muxer,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
socketClass;
|
||||
_peers = new Map();
|
||||
_nextPeer = (0, util_js_1.roundRobinFactory)(this._peers);
|
||||
|
@ -62,9 +71,6 @@ class MultiSocketProxy extends proxy_js_1.default {
|
|||
_allowedPorts = [];
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._socketOptions.onchannel = this.handleNewPeerChannel.bind(this);
|
||||
this._socketOptions.onclose = this.handleClosePeer.bind(this);
|
||||
this._socketOptions.onopen = this.handlePeer.bind(this);
|
||||
if (options.socketClass) {
|
||||
this.socketClass = options.socketClass;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { json, raw, uint } from "compact-encoding";
|
|||
import { deserializeError } from "serialize-error";
|
||||
import b4a from "b4a";
|
||||
import type { TcpSocketConnectOpts } from "net";
|
||||
import Peer, { DataSocketOptions, PeerOptions } from "../peer.js";
|
||||
import { DataSocketOptions, PeerOptions } from "../peer.js";
|
||||
import { roundRobinFactory, idFactory } from "../util.js";
|
||||
import {
|
||||
CloseSocketRequest,
|
||||
|
@ -14,6 +14,7 @@ import {
|
|||
WriteSocketRequest,
|
||||
} from "./multiSocket/types.js";
|
||||
import DummySocket from "./multiSocket/dummySocket.js";
|
||||
import Peer from "./multiSocket/peer.js";
|
||||
|
||||
export interface MultiSocketProxyOptions extends ProxyOptions {
|
||||
socketClass?: any;
|
||||
|
@ -69,7 +70,15 @@ const errorSocketEncoding = {
|
|||
const nextSocketId = idFactory(1);
|
||||
|
||||
export default class MultiSocketProxy extends Proxy {
|
||||
handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions) {}
|
||||
handlePeer({ peer, muxer, ...options }: DataSocketOptions & PeerOptions) {
|
||||
new Peer({
|
||||
...this.socketOptions,
|
||||
proxy: this,
|
||||
peer,
|
||||
muxer,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
private socketClass: any;
|
||||
private _peers: Map<string, PeerEntity> = new Map<string, PeerEntity>();
|
||||
private _nextPeer = roundRobinFactory(this._peers);
|
||||
|
@ -78,9 +87,6 @@ export default class MultiSocketProxy extends Proxy {
|
|||
|
||||
constructor(options: MultiSocketProxyOptions) {
|
||||
super(options);
|
||||
this._socketOptions.onchannel = this.handleNewPeerChannel.bind(this);
|
||||
this._socketOptions.onclose = this.handleClosePeer.bind(this);
|
||||
this._socketOptions.onopen = this.handlePeer.bind(this);
|
||||
if (options.socketClass) {
|
||||
this.socketClass = options.socketClass;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue