generateWebParams method

dynamic generateWebParams(
  1. Datum content,
  2. PackageModel packageModel, {
  3. required bool isDrm,
  4. required PlayState playState,
  5. bool isLive = false,
})

Implementation

generateWebParams(Datum content, PackageModel packageModel,
    {required bool isDrm,
    required PlayState playState,
    bool isLive = false}) async {
  SharedPreferences sharedPreferences = await DeviceStorage().getInstance();
  String sessionToken =
      sharedPreferences.getString(DeviceStorage.sessionToken) ?? "";

  bool renderLogo = !isLive;
  String userEmail = "";
  String profileid = "";
  String subscriberid = "";
  bool renderSecurity = true;
  String shareURL = "";
  if (!isLive) {
    // shareURL = RouteGenerator.generateContentShare(content: content);
    shareURL = "";
  }

  if (sessionToken.isNotEmpty) {
    Map<String, dynamic> decodedToken = JwtDecoder.decode(sessionToken);
    if (decodedToken.containsKey('email')) {
      userEmail = decodedToken['email'];
    } else {
      userEmail = decodedToken['mobileno'];
    }
    subscriberid = decodedToken['subscriberid'];
    profileid = decodedToken['profileid'];
  }

  int position = 1;
  try {
    if (content.watchedDuration != null) {
      position = content.watchedDuration!.toInt();
    }
  } catch (err) {
    //do nothing
  }

  var scrubbing = {};
  try {
    scrubbing = packageModel.packagedfilelist!.scrubbing![0].toMap();
  } catch (nullCheckError) {
    //do nothing
  }
  int clearLead = content.contentdetails![0].clearlead ?? 0;
  if (playState.buttonState == PlayButtonState.play) {
    clearLead = 0;
  }
  String availabilityId = "";
  try {
    availabilityId =
        content.contentdetails![1].availabilityset![0].toString();
  } catch (err) {
    availabilityId =
        content.contentdetails![0].availabilityset![0].toString();
  }
  var skipData = [];
  try {
    var skipObject = content.skip![0].toMap();
    skipData.add(skipObject);
  } catch (indexOutOfBound) {
    //do nothing here
  }

  return {
    "contentId": content.objectid,
    "contenttype": content.objecttype,
    "title": content.title,
    "description": content.shortdescription,
    "thumbnail": content.thumbnail,
    "source": [
      packageModel.streamfilename,
    ],
    "licenseServer": "https://vdrm.mobiotics.com/prod/prodv3/v1/license",
    "packageid": packageModel.packageid,
    "providerid": DeviceRegistration.providerid,
    "drmscheme": packageModel.drmscheme![0],
    "category": content.category ?? "",
    'availabilityid': availabilityId,
    "providerSession": sessionToken,
    "skip": skipData,
    "duration": content.duration,
    "genre": content.genre,
    "position": position,
    "contentTags": ['ct-music'],
    "scrubbing": scrubbing,
    "adversity": {
      "advisory": null,
      "pgrating": "ALL",
      "defaultgenre": "BUSINESS"
    },
    "isDrmContent": isDrm,
    "renderLogo": renderLogo,
    "userEmail": userEmail,
    'profileid': profileid,
    'poster': content.poster,
    'subscriberid': subscriberid,
    "renderSecurity": renderSecurity,
    "should_render_cancel": true,
    "leadTime": clearLead,
    "tokenApiURL":
        "https://vcms.mobiotics.com/prodv3/subscriber/v1/content/drmtoken",
    "shareURL": shareURL,
  };
}