DRM API

The VIVEPORT DRM API provides a function to verify if the content should be launched for the current user.

/** Language: C# for Unity*/
namespace Viveport
{
   public abstract class LicenseChecker
   {
      public abstract void OnSuccess(long issueTime,
                                     long expirationTime,
                                     int latestVersion,
                                     bool updateRequired);
      public abstract void OnFailure(int errorCode,
                                     string errorMessage);
   }

   class Api
   {
      public static void GetLicense(LicenseChecker checker, string appId, string appKey);
   }
}

How to Use DRM API

Note

Remember that you should call Top Level API - Api.Init() to setup the SDK library and client runtime before you call GetLicense(). And please remember to call Top Level API - Api.Shutdown() to teardown the library runtime after you finish using VIVEPORT SDK.

The API GetLicense() is used to get the user’s content license, which is issued from VIVEPORT to verify if the current user has permission to launch the content. The verification should be done with 3 parameters - an VIVEPORT ID, an VIVEPORT Key, and a LicenseChecker.

You need to implement a subclass of LicenseChecker to decide what to do if user’s license verification is successful or failed.

Important

Please see the Error Codes and Trouble Shooting pages to know what to do when you got problems using the VIVEPORT SDK.

DRM for Android

To use the DRM API in Android, your application must request com.viveport.CHECK_LICENSE permission. Please declare a <uses-permission android:name=”com.viveport.CHECK_LICENSE” /> element as a child of <manifest> in AndroidManifest.xml. For example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...">
<... />
<uses-permission android:name="com.viveport.CHECK_LICENSE" />
<... />
</manifest>

Detailed Example in Unity

using UnityEngine;
using System;
using Viveport;

public class ViveportDemo : MonoBehaviour
{
   static string VIVEPORT_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";
   static string VIVEPORT_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFypCg0OHf"
                         + "BC+VZLSWPbNSgDo9qg/yQORDwGy1rKIboMj3IXn4Zy6h6bgn"
                         + "8kiMY7VI0lPwIj9lijT3ZxkzuTsI5GsK//Y1bqeTol4OUFR+"
                         + "47gj+TUuekAS2WMtglKox+/7mO6CA1gV+jZrAKo6YSVmPd+o"
                         + "FsgisRcqEgNh5MIURQIDAQAB";


   // Use this for initialization
   void Start ()
   {
       Api.Init(InitStatusHandler, VIVEPORT_ID);
   }

   private static void InitStatusHandler(int nResult)
   {
       Viveport.Core.Logger.Log("Init(): " + nResult);
       if (nResult == 0)
       {
          Api.GetLicense(new MyLicenseChecker(), VIVEPORT_ID, VIVEPORT_KEY);
       }
       else if (nResult != 0)
       {
          Viveport.Core.Logger.Log("Init setup error ...");
          // Handle error and close your game.
       }
   }

   class MyLicenseChecker : Api.LicenseChecker
   {
       public override void OnSuccess(long issueTime, long expirationTime, int latestVersion,
                                      bool updateRequired)
       {
           Viveport.Core.Logger.Log("[MyLicenseChecker] issueTime: " + issueTime);
           Viveport.Core.Logger.Log("[MyLicenseChecker] expirationTime: " + expirationTime);
           Viveport.Core.Logger.Log("[MyLicenseChecker] latestVersion: " + latestVersion);
           Viveport.Core.Logger.Log("[MyLicenseChecker] updateRequired: " + updateRequired);
           // Do more things
       }

       public override void OnFailure(int errorCode, string errorMessage)
       {
           Viveport.Core.Logger.Log("[MyLicenseChecker] errorCode: " + errorCode);
           Viveport.Core.Logger.Log("[MyLicenseChecker] errorMessage: " + errorMessage);
           Application.Quit();
       }
   }
}

Detailed Example in Unreal

ViveportApiDemo.h

#include "Components/ActorComponent.h"
#include "ViveportApiDemo.generated.h"
#include "ViveportApi.h"


UCLASS( ClassGroup=(Viveport), meta=(BlueprintSpawnableComponent) )
class VIVEPORTSDK_API UViveportApiDemo : public UActorComponent
{
    GENERATED_BODY()

 public:
    // Sets default values for this component's properties
    UViveportApiDemo();

    // Called when the game starts
    void BeginPlay() override;

    // Called every frame
    void TickComponent(
                        float DeltaTime,
                        ELevelTick TickType,
                        FActorComponentTickFunction* ThisTickFunction
                      ) override;

    /** The APP ID for auth verify */
    FString VIVEPORT_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";

    /** Public key for auth verify */
    FString VIVEPORT_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFypCg0OHf"
                       + "BC+VZLSWPbNSgDo9qg/yQORDwGy1rKIboMj3IXn4Zy6h6bgn"
                       + "8kiMY7VI0lPwIj9lijT3ZxkzuTsI5GsK//Y1bqeTol4OUFR+"
                       + "47gj+TUuekAS2WMtglKox+/7mO6CA1gV+jZrAKo6YSVmPd+o"
                       + "FsgisRcqEgNh5MIURQIDAQAB";
 private:
    // callback interface
    class MyLicenseChecker : public UViveportApi::LicenseChecker
    {
    public:
        void OnSuccess(
                        long long issue_time,
                        long long expiration_time,
                        int latest_version,
                        bool update_required
                      ) override;
        void OnFailure(
                        int errorCode,
                        const FString& errorMessage
                      ) override;
    };

    MyLicenseChecker myLicenseChecker;
};

ViveportApiDemo.cpp

#include "ViveportSDKPrivatePCH.h"
#include "ViveportApiDemo.h"

UViveportApiDemo::UViveportApiDemo()
{
    bWantsBeginPlay = true;
    PrimaryComponentTick.bCanEverTick = true;
}

// Called when the game starts
void UViveportApiDemo::BeginPlay()
{
    Super::BeginPlay();
    FString fstring = UViveportApi::Version();
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);

    UViveportApi::GetLicense(&myLicenseChecker, VIVEPORT_ID, VIVEPORT_KEY);
}

// Called every frame
void UViveportApiDemo::TickComponent(float DeltaTime, ELevelTick TickType,
                                     FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
}

void UViveportApiDemo::MyLicenseChecker::OnSuccess(long long issue_time, long long expiration_time,
                                                   int latest_version, bool update_required)
{
    char result[256] = { '\0' };
    sprintf_s(result, "Verify OK!\n issue_time=%lld,\n expiration_time=%lld,\n latest_version=%d,\n
              update_required=%d", issue_time, expiration_time, latest_version, update_required);
    FString fstring(result);
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
}

void UViveportApiDemo::MyLicenseChecker::OnFailure(int error_code, const FString& error_message)
{
    char result[256] = { '\0' };
    sprintf_s(result, "Verify failed!\n error_code=%d,\n error_message=%s", error_code,
              TCHAR_TO_UTF8(*error_message));
    FString fstring(result);
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
    // DRM fail, close the content.
}