import { Observable } from 'rxjs'; import { RPCChannel } from './channel'; import { AnyConstructor, Constructor } from './internal'; import { Proxied, RemoteSubscription } from './proxied'; import { RemoteRef } from './remote-ref'; import { Request } from './request'; export interface InFlightRequest { /** * It is important that we hold the request, because we must not garbage collect any objects referenced by * the request in the mean time. Normally this isn't possible because there's a hard reference within our * localObjectMap, but if a proxy for this object on the remote side is garbage collected in the mean time, * we may receive a finalizeProxy() request which will cause us to remove it. Holding the request will ensure * that it's not possible for the included remotables to be garbage collected as long as the request is in flight. */ request: Request; returnValue?: any; error?: any; responseHandler: (response: any) => void; } export declare type ServiceFactory = (session: RPCSession) => T; export declare class RPCSession { readonly channel: RPCChannel; constructor(channel: RPCChannel); /** * Connect via WebSocket to the given URL and create a new RPCSession using * the socket as the underlying channel. * @param url */ static connect(url: string): Promise; private _remote; get remote(): Proxied; getRemoteService(serviceIdentity: AnyConstructor): Promise>; getRemoteService(serviceIdentity: string): Promise>; private rawSend; private encodeMessage; private decodeMessage; private _requestMap; tag: string; call(receiver: any, method: string, parameters: any[], metadata?: Record): Promise; protected performCall(request: Request): Promise; /** * Retrieve the RPCSession that is being served by the current remote method call. * This is only available when Zone.js is loaded. * @returns */ static current(): RPCSession; static currentRequest(): any; private onReceiveMessage; /** * Returns true if there are no outstanding requests or remotely held references. */ get idle(): boolean; /** * The number of in-flight requests */ get pendingRequestCount(): number; /** * The number of remotely held references */ get remoteReferenceCount(): number; private _becameIdle; private _becameIdle$; /** * Fired when the session has become idle (no pending requests or remote references). */ get becameIdle(): Observable; /** * Called when a request is finished processing. * @param request */ onRequestCompleted(request: InFlightRequest): void; /** * Close the related channel, if it supports such an operation. */ close(): void; private serviceRegistry; /** * This map tracks individual objects which we've exported via RPC via object ID. */ private localObjectRegistry; /** * This map tracks individual *references* sent over the wire. Each time an object is sent over the wire, * a new hard reference is created for it on the sender side. Those references must be cleaned up by the remote side * using finalizeProxy. Think of each entry in this array as a distinct RPCProxy created on the remote side. * The keys here are `.`. */ private remoteRefRegistry; /** * Tracks the known RPCProxy objects allocated on this side of the connection for objects that exist on the remote * side. */ private proxyRegistry; private proxyFinalizer; countReferencesForObject(id: string): number; /** * How long to wait after an RPCProxy is finalized before notifying the other side * about it. If a new RPCProxy is created before the finalization delay timeout, then * the remote finalization will be cancelled. This helps to avoid a situation where the * old local proxy can go out of scope and be collected at the same time that a new request * is coming in which will revive it (via a new proxy). */ finalizationDelay: number; private registerProxy; private registerLocalObject; /** * Returns a RemoteRef for the given object. The object can be a Remotable object * or an RPCProxy object (representing an object remoted from the other side). * @param object * @returns */ remoteRef(object: any): RemoteRef; /** * Retrieve the local object for the given RemoteRef. The RemoteRef may represent * a Remotable local object or an RPCProxy object for an object remoted from the other side. * @param ref * @returns */ getObjectByRemoteRef(ref: RemoteRef): any; loggingEnabled: boolean; private log; private logObject; getLocalObjectById(id: string): any; registerService(klass: Constructor, factory?: ServiceFactory): void; /** * @internal */ getLocalService(identity: string): Promise; getObjectId(object: any): any; getReferenceId(object: any): string; isLocalObjectPresent(id: string): boolean; /** * Called by the remote when a proxy has been garbage collected. * @param id */ finalizeRef(refID: string): Promise; subscribeToEvent(eventSource: any, eventName: string, eventReceiver: any): Promise; /** * This is used for testing. * @internal */ getRequestMap(): Map; /** * This is used for testing. * @internal */ finalizeProxy(proxy: any): void; }