@playlive/tiltify-phoenix
    Preparing search index...

    Class TiltifyWebSocket

    Wraps the Tiltify Phoenix Channels gateway with the same surface playlive-console-v2's LiveEventsProvider (and legacy callers) already use:

    • Lifecycle: construct → join channels → consume events (addEventListener) → disconnect() on unmount.
    • Channel ack: addChannelListener for per-channel ok / error / timeout from Channel.join().
    • Name cache: getCampaignName / getFundraisingEventName / getCauseName — populated as facts are looked up.

    REST lookups for FindCampaign, GetCampaign, GetFundraiser, GetCause, and GetFundraisingEventsSupportingCampaigns are delegated to the @playlive/tiltify-core tiltify singleton with tiltify.UseProxy() enforced — the proxy URL is configured via that singleton's setup, this class does not touch it.

    import { TiltifyWebSocket } from "@playlive/tiltify-phoenix";

    const ws = new TiltifyWebSocket(
    (isInitial) => console.log("open", { isInitial }),
    (err) => console.error("ws error", err),
    (isDisc) => console.log("close", { isDisc }),
    );

    ws.addEventListener((factID, event, type, payload) => {
    console.log("event", { factID, event, type, payload });
    });

    await ws.startListeningToCampaignBySlug("@playliver", "campaign-slug");

    // …later, on teardown:
    ws.disconnect();
    Index
    • Subscribe to per-channel ack events (ok, error, timeout) for every channel this client opens. Add the listener BEFORE calling startListeningToFact / startListeningToCampaignBySlug — listeners added afterwards only fire for subsequent channels.

      Parameters

      Returns void

    • Subscribe to every Phoenix event across every fact this client is listening to. The firehose form of on.

      Parameters

      • listener: (
            factID: string,
            event:
                | "donation"
                | "donation_updated"
                | "match"
                | "fact"
                | "reward"
                | "milestone"
                | "challenge"
                | "poll"
                | "poll_option",
            type: FactType,
            payload: unknown,
        ) => void

      Returns void

    • Re-arm + re-open the underlying socket. Resets the initial- connection flag so the next onOpen reports true.

      Useful for callers that want explicit "reconnect now" behavior — Phoenix's built-in auto-reconnect is normally sufficient.

      Returns void

    • Tear down every joined channel and close the underlying socket. Sets the isDisconnecting flag so the next onClose reports true.

      Returns void

    • Cached display name for a campaign fact, or undefined.

      Parameters

      • campaignID: string

      Returns string | undefined

    • Cached display name for a cause fact, or undefined.

      Parameters

      • causeID: string

      Returns string | undefined

    • Convenience: look up the cached display name for any fact type in one call.

      Parameters

      Returns string | undefined

    • Cached display name for a fundraising-event fact, or undefined.

      Parameters

      • eventID: string

      Returns string | undefined

    • Subscribe to a single Phoenix event across every fact this client is listening to. Use addEventListener for the unfiltered firehose.

      Parameters

      • event:
            | "donation"
            | "donation_updated"
            | "match"
            | "fact"
            | "reward"
            | "milestone"
            | "challenge"
            | "poll"
            | "poll_option"
      • callback: (factID: string, type: FactType, payload: unknown) => void

      Returns void

      ws.on("donation", (factID, type, payload) => { ... });
      
    • High-level: resolve @user/campaign-slug (or +team/...) via the Tiltify REST API, then start listening to the resolved campaign + its parent fundraising event + parent cause.

      Throws Error("Could not find campaign with the provided slugs") if the lookup fails. Network errors bubble up as-is.

      Parameters

      • teamUserSlug: string

        @username for individuals or +teamname for teams. The leading sigil is stripped before lookup.

      • campaignSlug: string

        Campaign URL slug.

      • events: (
            | "donation"
            | "donation_updated"
            | "match"
            | "fact"
            | "reward"
            | "milestone"
            | "challenge"
            | "poll"
            | "poll_option"
        )[] = EVENTS_TO_WATCH

        Optional narrowed event list. Defaults to EVENTS_TO_WATCH.

      Returns Promise<void>

    • Low-level: subscribe to every events channel for the given fact. Idempotent — subsequent calls with the same factID are no-ops, even if the requested events list differs.

      Parameters

      • factID: string

        Tiltify fact UUID.

      • events: (
            | "donation"
            | "donation_updated"
            | "match"
            | "fact"
            | "reward"
            | "milestone"
            | "challenge"
            | "poll"
            | "poll_option"
        )[] = EVENTS_TO_WATCH

        Defaults to EVENTS_TO_WATCH.

      • type: FactType

        One of "campaign", "fundraising-event", "cause". Routed into the right REST lookup when lookup === true.

      • lookup: boolean = true

        When true (default), look up the fact's name

        • parent facts via REST and cache them. Pass false to skip the round-trip — the channel subscription happens immediately and getXxxName(factID) returns undefined until the cache is populated some other way.

      Returns Promise<void>