Truvideo Core SDK

This Plugin demonstrates the integration of the TruvideoCoreSdk for authentication and platform-specific functionality. It includes features such as authentication, authentication status checking, and clearing authentication.

Supported Platforms

  • Android
  • iOS

Features

  • Authenticates using API Key and Secret Key
  • Checks authentication status
  • Clears authentication

Requirements

  • API Key & Secret Key: Required for authentication
  • TruvideoCoreSdk Plugin: Must be properly installed and configured in your Flutter project

Setup

  1. Add TruvideoCoreSdk Plugin to your project.
  2. Install dependencies using:
    flutter pub get
    
  3. Replace the placeholders with actual API keys:
    final String apiKey = "YOUR_API_KEY"; // Replace with your API Key
    final String secretKey = "YOUR_SECRET_KEY"; // Replace with your Secret Key
    
  4. Run the app:
    flutter run
    

Authentication Process

  1. Generates a payload for authentication
  2. Uses SHA256 HMAC to sign the payload
  3. Authenticates using TruvideoCoreSdk.authenticate()
  4. Initializes authentication with TruvideoCoreSdk.initAuthentication()
  5. Updates authentication status

Code Overview

Ckeck Authentication Status

isAuthenticated()

  • Returns true or false indicating whether the client is authenticated. Please note that authentication may be expired.

isAuthenticationExpired()

  • Return true or false indicating whether the authentication is expired. If the client is not authenticated, it always returns false.
Future<(bool, bool)> checkAuthenticationStatus() async{
  bool isAuthenticated = await TruvideoCoreSdk.isAuthenticated();
  bool isAuthExpired = await TruvideoCoreSdk.isAuthenticationExpired();
  return (isAuthenticated, isAuthExpired);
}

Authentication process

Future<void> authenticate() async {
  try {
    bool isAuthenticated = await TruvideoCoreSdk.isAuthenticated();
    bool isAuthExpired = await TruvideoCoreSdk.isAuthenticationExpired();
    String payload = await TruvideoCoreSdk.generatePayload();
    String signature = toSha256String(secret: secretKey, payload: payload) ?? '';

    // Authenticate with generated payload and signature
    if (!isAuthenticated || isAuthExpired ) {
      await TruvideoCoreSdk.authenticate(
        apiKey: apiKey,
        signature: signature,
        payload: payload,
        externalId: "",
      );
    }
    await TruvideoCoreSdk.initAuthentication();
  } catch (e) {
    print('Authentication failed: $e');
  }
}

Clear Authentication

  • To delete the current session and erase all associated authentication data, utilize the clearAuthentication method
Future<void> clearAuthentication() async {
  await TruvideoCoreSdk.clearAuthentication();
}

License

MIT

Support

If you have any questions or suggestions regarding the SDK, please contact us at [email protected].