ts-event-bus
Version:
Distributed messaging in Typescript
104 lines • 4.07 kB
TypeScript
import { Handler } from './Handler';
import { Channel } from './Channel';
export type PendingRequest = {
resolve: (data?: any) => void;
reject: (e: Error) => void;
};
export type PendingRequests = {
[slotName: string]: {
[requestId: string]: PendingRequest;
};
};
export declare class Transport {
private _channel;
private _localHandlers;
private _localHandlerRegistrations;
/**
* Handlers created by the Transport. When an event is triggered locally,
* these handlers will make a request to the far end to handle this event,
* and store a PendingRequest
*/
private _remoteHandlers;
/**
* Callbacks provided by each slot allowing to register remote handlers
* created by the Transport
*/
private _remoteHandlerRegistrationCallbacks;
/**
* Callbacks provided by each slot allowing to unregister the remote handlers
* created by the Transport, typically when the remote connection is closed.
*/
private _remoteHandlerDeletionCallbacks;
/**
* Callbacks provided by each slot allowing to remove blacklisted events
* declaration from the remote handlers.
*/
private _remoteIgnoredEventsCallbacks;
/**
* Requests that have been sent to the far end, but have yet to be fulfilled
*/
private _pendingRequests;
private _channelReady;
constructor(_channel: Channel, ignoredEvents?: string[]);
/**
* This event is triggered when events have been listed as ignored by the far
* end. It will call onRegister on ignored events' handlers to fake their
* registration so this end doesn't wait on the far end to have registered
* them to be able to trigger them.
*/
private _remoteIgnoredEventsReceived;
/**
* When a request is received from the far end, call all the local subscribers,
* and send either a response or an error mirroring the request id,
* depending on the status of the resulting promise
*/
private _requestReceived;
/**
* When a response is received from the far end, resolve the pending promise
* with the received data
*/
private _responseReceived;
/**
* When an error is received from the far end, reject the pending promise
* with the received data
*/
private _errorReceived;
/**
* When the far end signals that a handler has been added for a given slot,
* add a handler on our end. When called, this handler will send a request
* to the far end, and keep references to the returned Promise's resolution
* and rejection function
*
*/
private _registerRemoteHandler;
private _unregisterRemoteHandler;
private _unregisterAllRemoteHandlers;
private _rejectAllPendingRequests;
addRemoteHandlerRegistrationCallback(slotName: string, addLocalHandler: (p: string, h: Handler<any, any>) => void): void;
addRemoteHandlerUnregistrationCallback(slotName: string, removeHandler: (p: string, h: Handler<any, any>) => void): void;
addRemoteEventListChangedListener(slotName: string, eventListChangedListener: () => void): void;
/**
* Called when a local handler is registered, to send a `handler_registered`
* message to the far end.
*/
registerHandler(slotName: string, param: string, handler: Handler<any, any>): void;
/**
* Called when a local handler is unregistered, to send a `handler_unregistered`
* message to the far end.
*/
unregisterHandler(slotName: string, param: string, handler: Handler<any, any>): void;
/**
* Allows to know the transport status and to perform a reconnection
*
* @returns {boolean} Transport's channel connection status, true if disconnected, otherwise false
*/
isDisconnected(): boolean;
/**
* Auto-reconnect the channel
* see Slot.trigger function for usage
*
* @returns {Promise} A promise resolving when the connection is established
*/
autoReconnect(): Promise<void>;
}
//# sourceMappingURL=Transport.d.ts.map