Compare commits

..

No commits in common. "a8419313b50d18860671ab25e715017d40c6c641" and "5fa538524998e5b0c333424fcf6eab5347c6fee7" have entirely different histories.

3 changed files with 10 additions and 23 deletions

View File

@ -1,9 +1,8 @@
/// <reference types="node" /> /// <reference types="node" />
import Proxy, { ProxyOptions } from "../proxy.js"; import Proxy, { ProxyOptions } from "../proxy.js";
import type { TcpSocketConnectOpts } from "net"; import type { TcpSocketConnectOpts } from "net";
import { DataSocketOptions, PeerOptions } from "../peer.js"; import Peer, { DataSocketOptions, PeerOptions } from "../peer.js";
import { PeerEntity } from "./multiSocket/types.js"; import { PeerEntity } from "./multiSocket/types.js";
import Peer from "./multiSocket/peer.js";
export interface MultiSocketProxyOptions extends ProxyOptions { export interface MultiSocketProxyOptions extends ProxyOptions {
socketClass?: any; socketClass?: any;
server: boolean; server: boolean;

View File

@ -10,7 +10,6 @@ const serialize_error_1 = require("serialize-error");
const b4a_1 = __importDefault(require("b4a")); const b4a_1 = __importDefault(require("b4a"));
const util_js_1 = require("../util.js"); const util_js_1 = require("../util.js");
const dummySocket_js_1 = __importDefault(require("./multiSocket/dummySocket.js")); const dummySocket_js_1 = __importDefault(require("./multiSocket/dummySocket.js"));
const peer_js_1 = __importDefault(require("./multiSocket/peer.js"));
const socketEncoding = { const socketEncoding = {
preencode(state, m) { preencode(state, m) {
compact_encoding_1.uint.preencode(state, m.id); compact_encoding_1.uint.preencode(state, m.id);
@ -55,15 +54,7 @@ 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 {
handlePeer({ peer, muxer, ...options }) { handlePeer({ peer, muxer, ...options }) { }
new peer_js_1.default({
...this.socketOptions,
proxy: this,
peer,
muxer,
...options,
});
}
socketClass; socketClass;
_peers = new Map(); _peers = new Map();
_nextPeer = (0, util_js_1.roundRobinFactory)(this._peers); _nextPeer = (0, util_js_1.roundRobinFactory)(this._peers);
@ -71,6 +62,9 @@ class MultiSocketProxy extends proxy_js_1.default {
_allowedPorts = []; _allowedPorts = [];
constructor(options) { constructor(options) {
super(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) { if (options.socketClass) {
this.socketClass = options.socketClass; this.socketClass = options.socketClass;
} }

View File

@ -4,7 +4,7 @@ import { json, raw, uint } from "compact-encoding";
import { deserializeError } from "serialize-error"; import { deserializeError } from "serialize-error";
import b4a from "b4a"; import b4a from "b4a";
import type { TcpSocketConnectOpts } from "net"; import type { TcpSocketConnectOpts } from "net";
import { DataSocketOptions, PeerOptions } from "../peer.js"; import Peer, { DataSocketOptions, PeerOptions } from "../peer.js";
import { roundRobinFactory, idFactory } from "../util.js"; import { roundRobinFactory, idFactory } from "../util.js";
import { import {
CloseSocketRequest, CloseSocketRequest,
@ -14,7 +14,6 @@ import {
WriteSocketRequest, WriteSocketRequest,
} from "./multiSocket/types.js"; } from "./multiSocket/types.js";
import DummySocket from "./multiSocket/dummySocket.js"; import DummySocket from "./multiSocket/dummySocket.js";
import Peer from "./multiSocket/peer.js";
export interface MultiSocketProxyOptions extends ProxyOptions { export interface MultiSocketProxyOptions extends ProxyOptions {
socketClass?: any; socketClass?: any;
@ -70,15 +69,7 @@ const errorSocketEncoding = {
const nextSocketId = idFactory(1); const nextSocketId = idFactory(1);
export default class MultiSocketProxy extends Proxy { 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 socketClass: any;
private _peers: Map<string, PeerEntity> = new Map<string, PeerEntity>(); private _peers: Map<string, PeerEntity> = new Map<string, PeerEntity>();
private _nextPeer = roundRobinFactory(this._peers); private _nextPeer = roundRobinFactory(this._peers);
@ -87,6 +78,9 @@ export default class MultiSocketProxy extends Proxy {
constructor(options: MultiSocketProxyOptions) { constructor(options: MultiSocketProxyOptions) {
super(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) { if (options.socketClass) {
this.socketClass = options.socketClass; this.socketClass = options.socketClass;
} else { } else {