Core
Framework v2.x
2

add() #

Available since 2.22.0

Registers a new realtime subscription on the specified connection.

This method is a backend version of the realtime:subscribe API action.

This connection will then starts to receive realtime messages on the returned roomId.

This method can only be used before the application is started.

add(
  connection: Connection,
  index: string,
  collection: string,
  filters: JSONObject,
  {
    volatile,
    scope,
    users,
  }: {
    volatile?: JSONObject;
    scope?: "in" | "out" | "all" | "none";
    users?: "in" | "out" | "all" | "none";
  }
): Promise<{ roomId: string; channel: string }>

ArgumentTypeDescription
connectionConnectionConnection to register the subscription on
indexstringIndex name
collectionstringCollection name
filtersJSONObjectSubscription filters
optionsJSONObjectSubscription options (volatile, scope and users)

Usage #

const { roomId, channel } = await app.subscription.add(
  request.context.connection,
  "lamaral",
  "windsurf",
  {
    range: { wind: { gte: 20 } },
  },
  {
    users: "all",
    scope: "in",
    volatile: { name: "Aschen" },
  }
);