Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LanDiscovery

Represents the LAN searching for games area in Among Us.

Binds a UDP socket to 47777 and waits for messages containing a game name and the number of players in the game.

Prevents duplicate games from repeated broadcast messages.

See LanDiscoveryEvents for events to listen to.

example
(async () => {
  const lanDiscovery = new LanDiscovery;
  const client = new SkeldjsClient("2021.4.25");

  client.on("client.disconnect", disconnect => {
    console.log("Client disconnected: %s", DisconnectReason[disconnect.reason]);
  });

  lanDiscovery.begin();
  const foundGame = await lanDiscovery.wait("discovery.foundgame");

  await client.connect(foundGame.ip, "weakeyes");

  await client.joinGame(foundGame.gameCode);

  await client.me?.control?.setName("weakeyes");
  await client.me?.control?.setColor(Color.Blue);
})();

Hierarchy

Index

Methods

begin

  • begin(): Promise<void>
  • Start listening for games hosted locally, binds to 47777. Clears the LanDiscovery.foundGames array.

    example

    const lanDiscovery = new LanDiscovery;

    lanDiscovery.begin();

    lanDiscovery.on("discovery.foundgame", foundGame => { console.log(Found game: ${foundGame.name} at ${foundGame.ip}:${foundGame.port}); });

    Returns Promise<void>

emit

  • emit<Event>(event: Event): Promise<Event>

emitSerial

  • emitSerial<Event>(event: Event): Promise<Event>

emitSync

  • emitSync<Event>(event: Event): Event

end

  • end(): Promise<void>

getListeners

  • getListeners<Event>(event: string): Listener<Event>[]

off

  • off<EventName>(event: EventName, listener: Listener<LanDiscoveryEvents[EventName]>): void
  • off<K>(event: string, listener: Listener<K>): void

on

  • on<EventName>(event: EventName, listener: Listener<LanDiscoveryEvents[EventName]>): () => void
  • on<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "discovery.foundgame"

    Parameters

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

onMessage

  • onMessage(buffer: Buffer, rinfo: RemoteInfo): Promise<void>

once

  • once<EventName>(event: EventName, listener: Listener<LanDiscoveryEvents[EventName]>): () => void
  • once<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "discovery.foundgame"

    Parameters

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

removeAllListeners

  • removeAllListeners(): void

removeListeners

  • removeListeners(event: string): void

searchFor

  • searchFor(numSeconds: number): Promise<DiscoveryFoundGameEvent[]>
  • Search for games for a specified amount of time. Clears the current LanDiscovery.foundGames array.

    Properly cleans up with LanDiscovery.end afterwards.

    example
    const lanDiscovery = new LanDiscovery;
    const games = await lanDiscovery.searchFor(5); // search for 5 seconds.
    
    console.log(games); // => [ DiscoveryFoundGameEvent, DiscoveryFoundGameEvent, ...]
    

    Parameters

    • numSeconds: number

      The number of seconds to search for games for.

    Returns Promise<DiscoveryFoundGameEvent[]>

    The games that were found.

wait

waitf

  • waitf<EventName>(event: EventName, filter: (ev: LanDiscoveryEvents[EventName]) => boolean | Promise<boolean>): Promise<LanDiscoveryEvents[EventName]>
  • waitf<K>(event: string, filter: (ev: K) => boolean | Promise<boolean>): Promise<BasicEvent>

Constructors

constructor

Properties

foundGames

foundGames: DiscoveryFoundGameEvent[]

All games that have been found so far, cleared on LanDiscovery.begin.

Optional socket

socket: Socket

The UDP socket used.

Generated using TypeDoc