CallDeclaration

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The CallDeclaration interface of the Room API is one call as call() declares it: the fields of its args, and the type of its reply. Pass it to defineCalls().

Instance properties

CallDeclaration.fields
The fields of the args, as call() was given them. Read only.

Instance methods

CallDeclaration.returns()
Declares the reply’s type, returns<T>(), and returns the declaration typed with it. Without it, the reply is void. It’s only a type: the room doesn’t check what a handler returns.

Examples

Typing a reply

// lookup.ts
import { call, defineCalls, defineRoom, defineSchema } from "@irtio/room";

const schema = defineSchema({
  calls: defineCalls({ whois: call({ player: "string" }).returns<{ online: boolean }>() }),
});

export default defineRoom({
  schema,
  calls: {
    whois: ({ player }, { room }) => ({ online: room.presence.get(player)?.connected ?? false }),
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
CallDeclaration0.10.10.10.1