libhyperproxy/dist/peer.d.ts

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-01-12 17:50:38 +00:00
import Proxy from "./proxy.js";
import Socket from "./socket.js";
2023-03-02 10:37:30 +00:00
export type OnOpen = (peer: Peer, socket: Socket, data: any) => {
2023-01-12 17:50:38 +00:00
connect: boolean;
} | Promise<{
connect: boolean;
}> | Promise<void> | void;
2023-03-02 10:37:30 +00:00
export type OnData = (peer: Peer, data: any) => void;
2023-01-12 17:50:38 +00:00
export type OnReceive = OnData;
export type OnClose = OnData;
export type OnSend = OnData;
2023-03-03 10:22:55 +00:00
export type OnChannel = (peer: Peer, channel: any) => void;
2023-03-02 10:37:30 +00:00
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;
2023-03-03 10:22:55 +00:00
export type OnChannelBound = (channel: any) => void;
2023-01-12 17:50:38 +00:00
export interface DataSocketOptions {
onopen?: OnOpen;
onreceive?: OnReceive;
onsend?: OnSend;
onclose?: OnClose;
2023-03-03 10:22:55 +00:00
onchannel?: OnChannel;
2023-02-26 03:16:59 +00:00
emulateWebsocket?: boolean;
2023-03-15 12:14:29 +00:00
createDefaultMessage?: boolean;
2023-01-12 17:50:38 +00:00
}
export interface PeerOptions {
peer: any;
muxer: any;
}
export interface PeerOptionsWithProxy extends PeerOptions {
proxy: Proxy;
}
export default class Peer {
private _proxy;
private _peer;
private _muxer;
private _onopen;
private _onreceive;
private _onsend;
private _onclose;
2023-03-03 10:22:55 +00:00
private _onchannel;
2023-02-26 03:16:59 +00:00
private _emulateWebsocket;
2023-03-15 12:14:29 +00:00
private _createDefaultMessage;
constructor({ proxy, peer, muxer, onopen, onreceive, onsend, onclose, onchannel, emulateWebsocket, createDefaultMessage, }: PeerOptionsWithProxy & DataSocketOptions);
2023-03-05 08:00:28 +00:00
private _socket?;
get socket(): Socket;
2023-03-02 10:41:30 +00:00
private _channel?;
get channel(): any;
2023-01-12 17:50:38 +00:00
init(): Promise<void>;
}