SongGuess
    Preparing search index...

    Handles API requests to the /api/{endpoint} endpoints.

    Hierarchy

    • Server<Env>
      • SongGuessAPI
    Index

    Constructors

    Properties

    __DURABLE_OBJECT_BRAND: never
    axiosClient: AxiosInstance | null = null

    Client used for communication with Apple Music API.

    env: Env
    soundCloud: SoundCloudAPI = ...

    Client used for communication with SoundCloud API.

    options: { hibernate?: boolean }

    Accessors

    • get name(): string

      The name for this server.

      Resolves from this.ctx.id.name — the native DO id name, populated whenever the stub was created via idFromName() or getByName(). This is available inside every entry point (including the constructor, alarms, and hibernating websocket handlers).

      For alarm handlers firing on stale on-disk alarm records from older workerd versions that didn't persist name into the alarm record, the name is recovered from a storage fallback record.

      Throws if neither source is available — typically this means the DO was addressed via idFromString() or newUniqueId(), which is not supported by PartyServer.

      Returns string

    Methods

    • Returns Promise<void>

    • Send a message to all connected clients, except connection ids listed in without

      Parameters

      • msg: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike>
      • Optionalwithout: string[]

      Returns void

    • Parameters

      Returns void | Promise<void>

    • Handle incoming requests to the server.

      Parameters

      Returns Promise<Response>

    • Get a connection by connection id

      Type Parameters

      • TState = unknown

      Parameters

      • id: string

      Returns Connection<TState> | undefined

    • Get all connections. Optionally, you can provide a tag to filter returned connections. Use Server#getConnectionTags to tag the connection on connect.

      Type Parameters

      • TState = unknown

      Parameters

      • Optionaltag: string

      Returns Iterable<Connection<TState>>

    • You can tag a connection to filter them in Server#getConnections. Each connection supports up to 9 tags, each tag max length is 256 characters.

      Parameters

      • connection: Connection
      • context: ConnectionContext

      Returns string[] | Promise<string[]>

    • Returns void | Promise<void>

    • Called when a connection is closed.

      Parameters

      • connection: Connection
      • code: number
      • reason: string
      • wasClean: boolean

      Returns void | Promise<void>

    • Called when a new connection is made to the server.

      Parameters

      • connection: Connection
      • ctx: ConnectionContext

      Returns void | Promise<void>

    • Called when an error occurs on a connection.

      Parameters

      • connection: Connection
      • error: unknown

      Returns void | Promise<void>

    • Called when an exception occurs.

      Parameters

      • error: unknown

        The error that occurred.

      Returns void | Promise<void>

    • Called when a message is received from a connection.

      Parameters

      • connection: Connection
      • message: WSMessage

      Returns void | Promise<void>

    • Called when the server is started for the first time.

      Parameters

      • Optionalprops: Record<string, unknown>

      Returns void | Promise<void>

    • Establish this server's name and trigger onStart().

      Use cases:

      1. Framework-level bootstrap of DOs where ctx.id.name is undefined — e.g. DOs addressed via idFromString() / newUniqueId(). setName() stashes the name in memory and persists it under __ps_name so cold-wake invocations recover it via #ensureInitialized()'s legacy fallback.
      2. Delivering initial props to onStart() via the optional second argument.

      For DOs addressed via idFromName() / getByName(), calling setName() is redundant — this.name is available automatically from ctx.id.name. The normal initialization path also persists a fallback record so old-compat alarm handlers can recover the name. Throws if name does not match ctx.id.name.

      Not appropriate for facets. Cloudflare Agents and any other framework using ctx.facets.get(...) should pass an explicit id in FacetStartupOptions so the facet has its own ctx.id.name:

      const stub = ctx.facets.get(facetKey, () => ({
      class: ChildClass,
      id: ctx.exports.SomeBoundDOClass.idFromName(facetName),
      }));

      Without an explicit id, the facet inherits the parent DO's ctx.id (including ctx.id.name), and setName() will throw the ctx.id.name-mismatch error because the facet's intended name differs from the parent's. See https://developers.cloudflare.com/dynamic-workers/usage/durable-object-facets/ for the FacetStartupOptions.id semantics.

      Parameters

      • name: string
      • Optionalprops: Record<string, unknown>

      Returns Promise<void>

      for callers that address DOs via idFromName() / getByName(). Still the supported API for framework-level bootstrap of header/newUniqueId-addressed DOs and for delivering initial props to onStart().

    • Execute SQL queries against the Server's database

      Type Parameters

      • T = Record<string, string | number | boolean | null>

        Type of the returned rows

      Parameters

      • strings: TemplateStringsArray

        SQL query template strings

      • ...values: (string | number | boolean | null)[]

        Values to be inserted into the query

      Returns T[]

      Array of query results

    • Parameters

      • ws: WebSocket
      • code: number
      • reason: string
      • wasClean: boolean

      Returns Promise<void>

    • Parameters

      Returns Promise<void>

    • Parameters

      Returns Promise<void>