@viviedu/applet-sdk
    Preparing search index...

    Function newApplet

    • Initialise a new Applet<Msg, Params> instance.

      Dynamically creates either a BoxApplet<Msg, Params> or a ClientApplet<Msg, Params> depending on the environment.

      Due to limitations in Typescript, this function needs to be called in two steps so that Msg & Params can be specified explicitly without breaking inferences for the requiredFeatures option.

      • The generic Msg should be set to the type of the applet-messages to send and receive between.
      • The optional generic Params should be set to the type of the custom parameters that were passed to the applet on start. (from the startApplet message).

      The applet.isBox or applet.isClient fields can be used to narrow the type of applet.

      Type Parameters

      • Msg
      • Params extends BaseParams = never

      Returns <
          const ReqBoxFeats extends
              readonly (
                  | "box-captions-text-scaling"
                  | "box-captions"
                  | "box-display-status"
                  | "box-edge-ai"
                  | "box-events"
                  | "box-get-video-announcement-active"
                  | "box-get-vivi-interactive"
                  | "box-headless"
                  | "box-microphone"
                  | "box-play-content-control"
                  | "box-room-code-visibility"
                  | "box-screen-share-control"
                  | "box-stop-applet"
                  | "box-timer-controls"
                  | "box-token"
              )[] = [],
          const ReqClientFeats extends
              readonly (
                  | "client-badge"
                  | "client-can-leave-room"
                  | "client-captions"
                  | "client-clipboard"
                  | "client-cloud-exports"
                  | "client-edge-ai"
                  | "client-download-files"
                  | "client-downloads-images"
                  | "client-downloads"
                  | "client-events"
                  | "client-get-room-student-lock"
                  | "client-ip-discovery"
                  | "client-microphone"
                  | "client-navigate-home"
                  | "client-open-in-browser"
                  | "client-platform-info"
                  | "client-play-content-control"
                  | "client-privacy-mode"
                  | "client-room-access-mode"
                  | "client-screen-share-control"
                  | "client-screen-share-intercept"
                  | "client-signage-lock"
                  | "client-stop-applet"
                  | "client-storage"
                  | "client-student-control"
                  | "client-timer-controls"
                  | "client-token"
                  | "client-tts"
                  | "client-user-name"
                  | "client-user-roles-listing"
                  | "client-view-mode"
              )[] = [],
      >(
          opts?: AppletOptions<ReqBoxFeats, ReqClientFeats>,
      ) => Promise<
          Applet<Msg, Params, ReqBoxFeats[number], ReqClientFeats[number]>,
      >

      const applet = await sdk.newApplet<Msg, Params>()();
      if (applet.isBox) {
      // applet has typeof BoxApplet<Msg, Params>
      } else {
      // applet has typeof ClientApplet<Msg, Params>
      }

      Pass `requiredBoxFeatures`/`requiredClientFeatures` to assert which features the applet needs to function.
      If any of those features are not present, initialisation will throw an error.
      This also narrows the type for gated methods covered by the list, so they become non-nullable.
      const applet = await sdk.newApplet<Msg, Params>()({
      requiredBoxFeatures: ['box-display-status'],
      requiredClientFeatures: ['client-user-roles-listing']
      });
      if (applet.isBox) {
      // requiredBoxFeatures lists 'box-display-status', so getDisplayStatus will not be null
      await applet.getDisplayStatus();
      } else {
      // requiredClientFeatures lists 'client-user-roles-listing', so getUserRoles will not be null
      await applet.getUserRoles();
      }