import type { Envelope } from '@devvit/protos/types/devvit/runtime/envelope.js';
import type { Disposable } from '@devvit/shared-types/Disposable.js';
import type { Namespace } from '@devvit/shared-types/Namespace.js';
import type { EnvelopeDispatcher } from './dispatcher/EnvelopeDispatcher.js';
/**
 * An EnvelopeRecipient can receive envelopes on post() and may also send them.
 * Local client hostnames are not unique but servers, some ports (which may
 * route to clients remotely), and dispatchers are.
 */
export type EnvelopeRecipient = Disposable & Namespace & {
    readonly type?: 'client';
    /**
     * EnvelopeDispatcher.bind() subscribes a recipient to envelopes and invokes
     * onBind() so that the recipient may also post envelopes. Implicitly, every
     * EnvelopeRecipient may be an envelope poster as well but this type only
     * assumes the ability to receive envelopes.
     *
     * By design, a recipient is only intended to be bound to one dispatcher.
     */
    onBind(dispatcher: Readonly<EnvelopeDispatcher>): void;
    /**
     * Unsubscribe from envelopes and free any references held to the dispatcher.
     */
    onUnbind(dispatcher: Readonly<EnvelopeDispatcher>): void;
    /**
     * Post an envelope to the recipient. If the recipient is a server, the
     * envelope is a request. If the recipient is a client, it's a response. If
     * the recipient is a dispatcher, it may be either.
     *
     * Caller is always the post() method invoker and may be used by the recipient
     * for streaming subsequent envelopes. If in doubt, ask yourself who should
     * receive a response. The caller may be any EnvelopeRecipient (server,
     * client, dispatcher).
     *
     * Local clients are indistinguishable by hostname. When a client issues
     * `dispatcher.post(this, request)`, the dispatcher can open a new stream
     * associated with the passed in client allowing responses to route back to
     * the client by stream ID.
     */
    post(caller: Readonly<EnvelopeRecipient>, envelope: Envelope): void;
};
//# sourceMappingURL=EnvelopeRecipient.d.ts.map