import Plugge from "plugge"; import MessageNode, { ReferenceManager, IProxyable, ResultMessage } from "./MessageNode"; import IBroadcastChannel, { ChannelEventType, BroadcastChannelType } from "./modules/IBroadcastChannel"; import BaseBroadcastChannel from "./modules/BaseBroadcastChannel"; import { TranelEvent } from "./TranelEvent"; import { isInWorker, isInNode } from "./modules/util"; import TranelError, { ErrorType } from "./modules/Error"; interface ITranelOption { /** * default: BroadcastChannelType.workerLike * * @type {BroadcastChannelType} * @memberof ITranelOption */ messageType?: BroadcastChannelType; /** * channel timeout * * @type {number} * @memberof ITranelOption */ timeout?: number; } export default class Tranel extends Plugge { static Event: typeof TranelEvent; referenceManager: ReferenceManager; channel: IBroadcastChannel; messageNode: MessageNode; targetOrigin: string | undefined; /** * root object access * * @type {IProxyable} * @memberof Tranel */ rootAccess: IProxyable; context: ITranelOption & { messageLogList: any[]; }; /** * Creates an instance of Tranel. * @param {{ messageType: BroadcastChannelType, timeout: number }} [options] * @memberof Tranel */ constructor(options?: ITranelOption); /** * 获取 proxy 对应的值, 可以直接用await获取 * * @param {*} proxy * @returns * @memberof Tranel */ get(proxy: any): Promise; /** * 清理不可序列化的对象引用(对面环境) * * @param {...any[]} args * @memberof Tranel */ clean(...args: any[]): void; /** * 清理除了otherwise之外的不可序列化的对象引用(对面环境) * * @param {...any} otherwise * @returns {void} * @memberof Tranel */ clearOtherwise(...otherwise: any): void; /** * connect & proxy * * @param {IBroadcastChannel} channel * @param {*} [proxyObject] * @param {string} [targetOrigin] * @returns {*} Opposite objectProxy * @memberof Tranel */ connect(channel: IBroadcastChannel, proxyObject?: any, targetOrigin?: string): any; /** * get opposite proxyObject proxy * * @returns {ProxyConstructor} * @memberof Tranel */ private hookOppositeRoot; } export { Plugge, BroadcastChannelType, IBroadcastChannel, ITranelOption, BaseBroadcastChannel, ChannelEventType, TranelEvent, IProxyable, TranelError, ErrorType, ResultMessage, isInWorker, isInNode };