Listen-only voice audio resource.

Opens a dedicated WebSocket to the shard in serviceListen mode, receives Opus audio frames and PTT events, and supports dynamic net add/remove without reconnecting.

const client = new StarCommsClient({ baseUrl, ownerApiKey, serviceKey: "scsk_..." });

client.audio.on("audio", (frame) => {
console.log(`Net ${frame.netId}${frame.userId} transmitting ${frame.opus.byteLength} bytes`);
});
client.audio.on("ptt.start", (evt) => {
console.log(`${evt.displayName} keyed up on net ${evt.netId}`);
});

await client.audio.listen({ guildId: "123456", nets: [1, 2] });
await client.audio.addNet(3);
await client.audio.removeNet(1);
await client.audio.stop();

Constructors

Accessors

  • get guildId(): string

    The guild ID this listener is connected to (empty if not connected).

    Returns string

  • get listening(): boolean

    Whether the audio listener is currently connected.

    Returns boolean

Methods

  • Add a net to listen on (without reconnecting). Calls the assignments API to assign the service listener to the net.

    Parameters

    • netId: number

    Returns Promise<void>

  • Register an event handler.

    Type Parameters

    Parameters

    Returns this

    client.audio.on("audio", (frame) => { ... });
    client.audio.on("ptt.start", (evt) => { ... });
    client.audio.on("ptt.stop", (evt) => { ... });
    client.audio.on("connected", (data) => { ... });
    client.audio.on("disconnected", ({ reason }) => { ... });
    client.audio.on("reconnected", ({ attempt }) => { ... });
    client.audio.on("error", ({ reason }) => { ... });
  • Remove a net from listening (without reconnecting). Calls the assignments API to unassign the service listener from the net.

    Parameters

    • netId: number

    Returns Promise<void>

  • Stop the audio listener. Unassigns from all nets and closes the WebSocket. Will not trigger reconnection.

    Returns Promise<void>