@grabjs/superapp-sdk
    Preparing search index...

    Class CameraModule

    JSBridge module for accessing the device camera.

    Provides access to native camera functionality including QR code scanning. This code must run on the Grab SuperApp's WebView to function correctly.

    ES Module:

    import { CameraModule } from '@grabjs/superapp-sdk';
    const cameraModule = new CameraModule();

    CDN (UMD):

    <script src="https://cdn.jsdelivr.net/npm/@grabjs/superapp-sdk/dist/index.js"></script>
    <script>
    const cameraModule = new SuperAppSDK.CameraModule();
    </script>

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Opens the native camera to scan a QR code.

      Parameters

      • request: ScanQRCodeRequest

        Configuration for the QR code scanning, including the title to display.

      Returns Promise<ScanQRCodeResponse>

      The QR code scanning result, containing the scanned code on success or status information.

      Simple usage

      import { CameraModule, isSuccess, isErrorResponse } from '@grabjs/superapp-sdk';

      // Initialize the camera module
      const camera = new CameraModule();

      // Scan the QR code
      const response = await camera.scanQRCode({ title: 'Scan Payment QR' });

      // Handle the response
      if (isSuccess(response)) {
      switch (response.status_code) {
      case 200:
      console.log('QR code scanned:', response.result.qrCode);
      break;
      case 204:
      console.log('User cancelled QR code scanning');
      break;
      }
      } else if (isErrorResponse(response)) {
      switch (response.status_code) {
      case 403:
      console.log('Camera permission not enabled');
      // Advise user to enable camera permission in device settings
      break;
      default:
      console.error(`Error ${response.status_code}: ${response.error}`);
      }
      } else {
      console.error('Unhandled response');
      }