SongGuess
    Preparing search index...

    Manages the connection and state of a room.

    Index

    Constructors

    • Creates a new RoomController instance and initializes the socket connection.

      Parameters

      • host: string

        the host used when creating the socket connection.

      • roomID: string

        The ID of the room to connect to.

      • getCookies: CookieGetter

        What cookies are currently set.

      • setCookies: CookieSetter

        A function to allow updating cookies.

      • setIsReady: (ready: boolean) => void

        A function called when the connection was opened the first time.

      Returns RoomController

    Properties

    config: BaseConfig = ...

    The config of this room

    currentPingMs: number = -1

    The current ping in milliseconds.

    filteredSongsCount: number = 0

    The amount of filtered songs

    getCookies: CookieGetter

    What cookies are currently set.

    host: string

    the host used when creating the socket connection.

    pingInterval?: number

    The interval of the ping function.

    pingSeq: number = 0

    The current ping sequence number.

    pingStart: number = 0

    The performance.now() timestamp when the last ping was sent.

    playedSongs: (
        | {
            artist: string;
            audioURL: string;
            cover: string
            | null;
            hrefURL: string;
            name: string;
        }
        | undefined
    )[] = []

    The list of songs played in the last round.

    Type Declaration

    • {
          artist: string;
          audioURL: string;
          cover: string | null;
          hrefURL: string;
          name: string;
      }
      • artist: string

        The name of the song artist.

      • audioURL: string

        A URL to the audio file of the song. Currently only audio previews from Apple Music and SoundCloud are allowed.

      • cover: string | null

        Cover URL of the song.

      • hrefURL: string

        The URL users will be redirected to when clicking.

      • name: string

        The name of the song.

    • undefined
    playlists: {
        cover: string | null;
        hrefURL: string;
        name: string;
        songs: {
            artist: string;
            audioURL: string;
            cover: string | null;
            hrefURL: string;
            name: string;
        }[];
        subtitle?: string;
    }[] = []

    The current list of playlists selected for the game.

    Type Declaration

    • cover: string | null

      Cover URL of the playlist.

    • hrefURL: string

      The URL users will be redirected to when clicking.

    • name: string

      Name of the playlist

    • songs: {
          artist: string;
          audioURL: string;
          cover: string | null;
          hrefURL: string;
          name: string;
      }[]

      A list of song names and music urls

    • Optionalsubtitle?: string

      An optional subtitle with additional information about the playlist

    pongSeq: number = 0

    The last received sequence number by the server.

    questionData: QuestionData = ...

    The currently cached ingame data

    reconnecting: boolean = false

    Whether the WebSocket is currently reconnecting

    roomID: string

    The ID of the room to connect to.

    setCookies: CookieSetter

    A function to allow updating cookies.

    setIsReady: (ready: boolean) => void

    A function called when the connection was opened the first time.

    Accessors

    • get playerMessages(): {
          answerData?: {
              answer?: string;
              answerIndex?: number;
              answerSpeed: number;
              answerTimestamp: number;
              questionPoints: number;
          };
          color: string;
          isHost: boolean;
          isSpectator: boolean;
          points: number;
          username: string;
      }[]

      The current list of just player messages of this room.

      Returns {
          answerData?: {
              answer?: string;
              answerIndex?: number;
              answerSpeed: number;
              answerTimestamp: number;
              questionPoints: number;
          };
          color: string;
          isHost: boolean;
          isSpectator: boolean;
          points: number;
          username: string;
      }[]

      • OptionalanswerData?: {
            answer?: string;
            answerIndex?: number;
            answerSpeed: number;
            answerTimestamp: number;
            questionPoints: number;
        }

        The current answer of this player.

        • Optionalanswer?: string

          Provided only for PlayerPicksGame. The answer the player selected.

        • OptionalanswerIndex?: number

          Provided only for MultipleChoiceGame. The index of the question the player selected.

        • answerSpeed: number

          The relative time in ms a player took to answer a round question.

        • answerTimestamp: number

          The absolute time in ms where the player answered a round question.

        • questionPoints: number

          The points the player got for the current question.

      • color: string

        The player's color

      • isHost: boolean

        True, if the receiver is the host

      • isSpectator: boolean

        True, if this player is just spectating

      • points: number

        How many points the player had in the last round.

      • username: string

        The player's username

    • get players(): Map<
          string,
          {
              answerData?: {
                  answer?: string;
                  answerIndex?: number;
                  answerSpeed: number;
                  answerTimestamp: number;
                  questionPoints: number;
              };
              color: string;
              isHost: boolean;
              isSpectator: boolean;
              points: number;
              username: string;
          },
      >

      The current list of players in the room.

      Returns Map<
          string,
          {
              answerData?: {
                  answer?: string;
                  answerIndex?: number;
                  answerSpeed: number;
                  answerTimestamp: number;
                  questionPoints: number;
              };
              color: string;
              isHost: boolean;
              isSpectator: boolean;
              points: number;
              username: string;
          },
      >

    Methods

    • Requests the server to add a playlist

      Parameters

      • ...playlists: {
            cover: string | null;
            hrefURL: string;
            name: string;
            songs: {
                artist: string;
                audioURL: string;
                cover: string | null;
                hrefURL: string;
                name: string;
            }[];
            subtitle?: string;
        }[]

        the playlists to add

        • cover: string | null

          Cover URL of the playlist.

        • hrefURL: string

          The URL users will be redirected to when clicking.

        • name: string

          Name of the playlist

        • songs: {
              artist: string;
              audioURL: string;
              cover: string | null;
              hrefURL: string;
              name: string;
          }[]

          A list of song names and music urls

        • Optionalsubtitle?: string

          An optional subtitle with additional information about the playlist

      Returns void

    • Imports playlists from a validated PlaylistsFile object.

      Parameters

      • playlistsFile: {
            playlists: {
                cover: string | null;
                hrefURL: string;
                name: string;
                songs: {
                    artist: string;
                    audioURL: string;
                    cover: string | null;
                    hrefURL: string;
                    name: string;
                }[];
                subtitle?: string;
            }[];
            version: "1.0";
        }

        The validated PlaylistsFile object containing playlist data.

        • playlists: {
              cover: string | null;
              hrefURL: string;
              name: string;
              songs: {
                  artist: string;
                  audioURL: string;
                  cover: string | null;
                  hrefURL: string;
                  name: string;
              }[];
              subtitle?: string;
          }[]

          The playlists of this export.

        • version: "1.0"

          Version of this export. Only used for validation.

      Returns void

    • Sends the picked song to the server for PlayerPicksGame.

      Parameters

      • song: {
            artist: string;
            audioURL: string;
            cover: string | null;
            hrefURL: string;
            name: string;
        }

        The song the player picked.

        • artist: string

          The name of the song artist.

        • audioURL: string

          A URL to the audio file of the song. Currently only audio previews from Apple Music and SoundCloud are allowed.

        • cover: string | null

          Cover URL of the song.

        • hrefURL: string

          The URL users will be redirected to when clicking.

        • name: string

          The name of the song.

      • startPos: number

        The start position for the audio.

      Returns void

    • (Re)connect to the PartyKit server.

      Parameters

      • OptionalnewUsername: string

        optionally request a new username when reconnecting.

      • spectator: boolean = false

        whether the player wants to spectate the game.

      Returns void

    • Requests the server to remove a playlist from the list.

      Parameters

      • index: number | null

        the index of the playlist to remove. null to remove all playlists.

      Returns void

    • Sends the selected answer to the server for MultipleChoiceGame.

      Parameters

      • answerIndex: number

        The index of the selected answer (0-3).

      Returns void

    • Sends the text answer (song guess) to the server for PlayerPicksGame.

      Parameters

      • answer: string

        The song name the player guessed.

      Returns void

    • Requests a host transfer from the server.

      Parameters

      • player: string

        The name of the player that should get host.

      Returns void

    • Updates the username of the current player.

      Parameters

      • newName: string

        The new username to set.

      Returns void