@applicaster/zapp-react-dom-app
Version:
Zapp App Component for Applicaster's Quick Brick React Native App
124 lines (115 loc) • 4.2 kB
JavaScript
/**
* These are the keys we want to load into session storage
* if you want to convert the name of the key just write the name you want to use as the value.
* This object is also used to pick the keys we want from device info, quickbrickcommunication module, and more.
* i.e. { keyToPick: new_name_of_key } value is how you want the key to be stored in session storage
* NOTE: Keys such as riversConfigurationId, rivers_configuration_id, and layoutId have been removed
* from the desiredKeysMap they are being loaded into the session store by the riversLoader middleware
* https://github.com/applicaster/QuickBrick/blob/main/packages/zapp-react-native-redux/middlewares/riversLoader.js#L4
*/
export const desiredKeysMap = {
accountsAccountId: "accountsAccountId",
appFamilyId: "app_family_id",
applicaster2: "applicaster2",
application_environment: "application_environment",
appName: "app_name",
buildVersion: "build_version",
bundleIdentifier: "bundleIdentifier",
bver: "ver",
countryCode: "countryCode",
countryLocale: "countryLocale",
device_make: "deviceMake",
deviceHeight: "deviceHeight",
deviceMake: "deviceMake",
deviceModel: "deviceModel",
deviceName: "deviceName",
deviceType: "deviceType",
deviceWidth: "deviceWidth",
isDebug: "isDebug",
is_rtl: "is_rtl",
languageCode: "languageCode",
languageLocale: "languageLocale",
languages: "languages",
locale: "locale",
modelName: "deviceModel",
network_type: "network_type",
networkType: "network_type",
osVersion: "osVersion",
platform: "platform",
quickBrickVersion: "quickBrickVersion",
sdkVersion: "sdk_version",
store: "store",
timeZoneOffset: "timeZoneOffset",
userAgent: "userAgent",
uuid: "uuid",
uiLanguage: "uiLanguage",
urlSchemePrefix: "urlSchemePrefix",
versionId: "version_id",
versionName: "version_name",
};
/**
* Platforms found in userAgent string, please note that simulators
* might not have the same agents that the devices have
*/
export const PLATFORMS = {
webos: "Web0S",
tizen: "Tizen",
samsung: "SMART-TV",
mac: "Mac",
win: "Win",
linux: "Linux",
iphone: "iPhone",
android: "Android",
mobile: "Mobile",
vizio: "VIZIO",
smartcast: "SmartCast",
conjure: "Conjure",
};
/**
* Helps us identify the device makes when using web browsers
*/
/**
* Simple way of identifying if we have access to the tizen APIs
*/
export const hasTizen = typeof window?.tizen !== "undefined";
/**
* Simple way of identifying if we have access to the webOS
*/
export const hasWebOS = typeof window?.webOS !== "undefined";
/**
* Simple way of identifying if we are on a web based platform
*/
export const isWebBased = typeof window !== "undefined";
const { platform, userAgent, languages, language, appVersion } =
(isWebBased && window?.navigator) || {};
const height = isWebBased && window?.screen?.height;
const width = isWebBased && window?.screen?.width;
const deviceMake = hasWebOS ? "LG" : hasTizen ? "Samsung" : platform;
const deviceType = hasWebOS || hasTizen ? "tv" : "web";
const devicePlatform = hasWebOS ? "lg_tv" : hasTizen ? "samsung_tv" : platform;
/**
* These are the default values we would like to fallback to, keys that we may not get when running on a browser
* or keys we may not get if we are running on the device without the necessary device APIs
* One of the important keys to note here is the platform key, here we are generating a default
* value without using any of the utils we have created throughout the app. We may want to use
* one of the utils instead of the devicePlatform value created here, if so do that outside of the const
* as importing any dependencies here could cause circular dependencies.
* See more about the keys we support in our docs here https://docs.applicaster.com/integrations/available-context-keys
*/
export const DEFAULT = {
deviceHeight: height,
deviceMake,
deviceModel: appVersion,
deviceName: platform,
deviceType,
deviceWidth: width,
is_rtl: "false",
languages,
locale: language,
modelName: appVersion,
name: deviceMake,
networkType: "N/A",
osVersion: appVersion,
platform: devicePlatform,
userAgent: userAgent,
};