Server sync response

Hello,

The docs says that:

  • Periodically invokes the Cryptlex API endpoints in a separate thread to sync the server license data with the client.

How can I get the response of each periodic API call so that if the licence expired I can stop the process?

Or I have to call IsLicenseGenuine() manually every specific time period?

Note: licenseCallback is not invoked, I check the last sync date on the dashboard and the function is never invoked.

I’m using Node.js v14.18.0 and “@cryptlex/lexactivator”: “^3.18.0”

Hi Omran,

IsLicenseGenuine() periodically invokes the server sync and when the server sync is completed, it invokes the licenseCallback. Please make sure the callback function is defined before ActivateLicense().

Regards,
Ahmad.

Hi Ahmad,

It’s already defined before calling ActivateLicense() and it’s also never been invoked,
kindly check the snippet

function licenseCallback(status) {
  console.log('Invoked!');
  try {
    switch (status) {
      case LexStatusCodes.LA_EXPIRED:
      case LexStatusCodes.LA_SUSPENDED:
        console.log('License is genuinely activated but has expired!', status);
        throw new Error(status);
      case LexStatusCodes.LA_OK:
        console.log('License is genuinely activated!', status);
        break;
      default:
        throw new LexActivatorException(status);
    }
  } catch (error) {
    console.log(error.code, error.message);
  }
}

init();
LexActivator.SetLicenseCallback(licenseCallback);
activate();
const status = LexActivator.IsLicenseGenuine();

Thanks for support.

It should be defined as below:

function licenseCallback(status) {
	try {
		switch (status) {
		case LexStatusCodes.LA_OK:
		case LexStatusCodes.LA_EXPIRED:
		case LexStatusCodes.LA_SUSPENDED:
			console.log('License is genuinely activated!', status);
			break;
		default:
			throw new LexActivatorException(status);
		}
	} catch (error) {
		console.log(error.code, error.message);
	}
}

function main() {
	try {
		init();
		activate();
		LexActivator.SetLicenseCallback(licenseCallback);
		const status = LexActivator.IsLicenseGenuine();
		if (LexStatusCodes.LA_OK == status) {
			console.log('License is genuinely activated!');

Please refer to the sample available on GitHub:

@ahmad-kemsan
I already tried the example from github and same issue it’s never invoked.

    init();
    activate();
    LexActivator.SetLicenseCallback(licenseCallback);
    const status = LexActivator.IsLicenseGenuine();

And I just tried to re-order the lines in 3/4 reply after your advice in the 2/4 reply that

Please make sure the callback function is defined before ActivateLicense().

both didn’t work, callback isn’t invoked.

Please remove the activate function in your code. It is only needed once. When you remove this function then IsLicenseGenuine() will trigger the callback in few seconds.

But we use the floating licence in docker containers, hence the activate must be called every time a docker container is created.

As I know this is the idea of a floating licence, every app instance calls activate() to activate its licence, and I’m following the github example which already call activate(), IsLicenseGenuine() and SetLicenseCallback()

Then you need to remove the IsLicenseGenuine() function as ActivateLicense() function is already validating the license.

LexActivator.SetLicenseKey("XYZ");
LexActivator.SetLicenseCallback(licenseCallback);
const status = LexActivator.ActivateLicense();

After this the callback will be invoked after server sync interval duration, which may be set to 1 hour in your license.

Unfortunately this didn’t work

Here is what I did

image

and here is the server last sync date
Mar 22, 2022 1:07 PM

And the licenseCallback wasn’t invoked

What is the server sync interval set for this license key?

Your application should remain open for at least that interval (value set for the server sync) to invoke the license callback.

What is the server sync interval set for this license key?

180 sec, which is the minimum.

And I kept the application running for more than 8 hours.

What is the value of lease duration?

1798 sec (I didn’t change it from 1800 I think while scrolling it changes to 1798 :"D)

@ahmad-kemsan @adnan-kamili Any suggestion here please?

We are on the trial now and want to use Cryptlex to be our licensing solution and need to finalize this issue before buying the subscription and go production.

Thanks,

Please try to run the sample attached below to see if the callback gets triggered:

Note: All the necessary information is hardcoded. You only need to run the sample code and wait for the time till the server sync gets completed which in this example is set to be equal to 180 sec.

I tried the sample and as you see, even after almost 11 mins the callback wan’t invoked.

Note: I’m using node v14.18.0

Which OS are you using?

Linux Ubuntu 20.04.1

And this happens when the script is run inside a container?

No, on the system directly.