Compare commits

..

No commits in common. "baf0ac31e6962da9a97c8267b9df07bb16e7b8bf" and "c9cfb64c80e47f9a9b120f6376e9ef10fcf2a0c0" have entirely different histories.

3 changed files with 15 additions and 38 deletions

13
dist/peer.d.ts vendored
View File

@ -1,23 +1,14 @@
import Proxy from "./proxy.js"; import Proxy from "./proxy.js";
import Socket from "./socket.js"; import Socket from "./socket.js";
export type OnOpen = (peer: Peer, socket: Socket, data: any) => { export type OnOpen = (socket: Socket, data: any) => {
connect: boolean; connect: boolean;
} | Promise<{ } | Promise<{
connect: boolean; connect: boolean;
}> | Promise<void> | void; }> | Promise<void> | void;
export type OnData = (peer: Peer, data: any) => void; export type OnData = (data: any) => void;
export type OnReceive = OnData; export type OnReceive = OnData;
export type OnClose = OnData; export type OnClose = OnData;
export type OnSend = OnData; export type OnSend = OnData;
export type OnOpenBound = (socket: Socket, data: any) => {
connect: boolean;
} | Promise<{
connect: boolean;
}> | Promise<void> | void;
export type OnDataBound = (data: any) => void;
export type OnReceiveBound = OnDataBound;
export type OnCloseBound = OnDataBound;
export type OnSendBound = OnDataBound;
export interface DataSocketOptions { export interface DataSocketOptions {
onopen?: OnOpen; onopen?: OnOpen;
onreceive?: OnReceive; onreceive?: OnReceive;

8
dist/peer.js vendored
View File

@ -20,10 +20,10 @@ class Peer {
this._proxy = proxy; this._proxy = proxy;
this._peer = peer; this._peer = peer;
this._muxer = muxer; this._muxer = muxer;
this._onopen = onopen?.bind(undefined, this); this._onopen = onopen?.bind(this);
this._onreceive = onreceive?.bind(undefined, this); this._onreceive = onreceive?.bind(this);
this._onsend = onsend?.bind(undefined, this); this._onsend = onsend?.bind(this);
this._onclose = onclose?.bind(undefined, this); this._onclose = onclose?.bind(this);
this._emulateWebsocket = emulateWebsocket; this._emulateWebsocket = emulateWebsocket;
} }
async init() { async init() {

View File

@ -2,7 +2,6 @@ import Proxy from "./proxy.js";
import Socket from "./socket.js"; import Socket from "./socket.js";
import { Buffer } from "buffer"; import { Buffer } from "buffer";
export type OnOpen = ( export type OnOpen = (
peer: Peer,
socket: Socket, socket: Socket,
data: any data: any
) => ) =>
@ -10,24 +9,11 @@ export type OnOpen = (
| Promise<{ connect: boolean }> | Promise<{ connect: boolean }>
| Promise<void> | Promise<void>
| void; | void;
export type OnData = (peer: Peer, data: any) => void; export type OnData = (data: any) => void;
export type OnReceive = OnData; export type OnReceive = OnData;
export type OnClose = OnData; export type OnClose = OnData;
export type OnSend = OnData; export type OnSend = OnData;
export type OnOpenBound = (
socket: Socket,
data: any
) =>
| { connect: boolean }
| Promise<{ connect: boolean }>
| Promise<void>
| void;
export type OnDataBound = (data: any) => void;
export type OnReceiveBound = OnDataBound;
export type OnCloseBound = OnDataBound;
export type OnSendBound = OnDataBound;
export interface DataSocketOptions { export interface DataSocketOptions {
onopen?: OnOpen; onopen?: OnOpen;
onreceive?: OnReceive; onreceive?: OnReceive;
@ -50,10 +36,10 @@ export default class Peer {
private _peer: any; private _peer: any;
private _muxer: any; private _muxer: any;
private _socket?: Socket; private _socket?: Socket;
private _onopen: OnOpenBound; private _onopen: OnOpen;
private _onreceive: OnReceiveBound; private _onreceive: OnReceive;
private _onsend: OnSendBound; private _onsend: OnSend;
private _onclose: OnCloseBound; private _onclose: OnClose;
private _emulateWebsocket: boolean; private _emulateWebsocket: boolean;
private _channel?: any; private _channel?: any;
@ -71,10 +57,10 @@ export default class Peer {
this._proxy = proxy; this._proxy = proxy;
this._peer = peer; this._peer = peer;
this._muxer = muxer; this._muxer = muxer;
this._onopen = onopen?.bind(undefined, this); this._onopen = onopen?.bind(this);
this._onreceive = onreceive?.bind(undefined, this); this._onreceive = onreceive?.bind(this);
this._onsend = onsend?.bind(undefined, this); this._onsend = onsend?.bind(this);
this._onclose = onclose?.bind(undefined, this); this._onclose = onclose?.bind(this);
this._emulateWebsocket = emulateWebsocket; this._emulateWebsocket = emulateWebsocket;
} }