channelProxy.d.ts 1.3 KB

123456789101112131415161718192021222324252627282930
  1. import { CommonDataTypes, Script } from '../../../protocol/protocol.js';
  2. import type { IEventManager } from '../events/EventManager.js';
  3. import type { Realm } from './realm.js';
  4. import Handle = CommonDataTypes.Handle;
  5. /**
  6. * Used to send messages from realm to BiDi user.
  7. */
  8. export declare class ChannelProxy {
  9. #private;
  10. constructor(channel: Script.ChannelProperties);
  11. /**
  12. * Creates a channel proxy in the given realm, initialises listener and
  13. * returns a handle to `sendMessage` delegate.
  14. */
  15. init(realm: Realm, eventManager: IEventManager): Promise<Handle>;
  16. /** Gets a ChannelProxy from window and returns its handle. */
  17. startListenerFromWindow(realm: Realm, eventManager: IEventManager): Promise<void>;
  18. /**
  19. * String to be evaluated to create a ProxyChannel and put it to window.
  20. * Returns the delegate `sendMessage`. Used to provide an argument for preload
  21. * script. Does the following:
  22. * 1. Creates a ChannelProxy.
  23. * 2. Puts the ChannelProxy to window['${this.#id}'] or resolves the promise
  24. * by calling delegate stored in window['${this.#id}'].
  25. * This is needed because `#getHandleFromWindow` can be called before or
  26. * after this method.
  27. * 3. Returns the delegate `sendMessage` of the created ChannelProxy.
  28. */
  29. getEvalInWindowStr(): string;
  30. }