UNPKG

@smartface/emulator-dispatcher

Version:

Handles Emulator Dispatcher Part of SmartfaceCloud

73 lines (61 loc) 2.69 kB
const getScaleFactor = require("./androidresourcescalefactor"); const iOSMap = require("./iosmap"); /** * Creates a new Device instance from device info * @class * @param {DeviceOptions} options - Device information provided as parameter */ function Device(options) { Object.assign(this, options); if (this.os === "Android") { var firstPreferedFolder = (this.resourceFolderOrder || [])[0]; if (firstPreferedFolder) this.scaleFactor = getScaleFactor(firstPreferedFolder); else { this.scaleFactor = 4; //defaults to Android mdpi factor } } else if (this.os === "iOS") { if (iOSMap[this.brandModel]) this.brandModel = iOSMap[this.brandModel]; var order = [2, 3, 1]; if (/(Plus| XS| X$)(?!XR)/g.test(this.brandModel)) { order = [3, 2, 1]; } else { var nonRetinaDevices = ["iPhone", "iPhone 2G", "iPhone 3G", "iPhone 3GS", "iPod Touch (1 Gen)", "iPod Touch (2 Gen)", "iPod Touch (3 Gen)", "iPad", "iPad 3G", "iPad 2", "iPad Mini" ]; if (nonRetinaDevices.indexOf(this.brandName) > -1) { order = [1, 2, 3]; } } this.imageExtensionOrder = order; this.scaleFactor = order[0]; } } /** * Device info provided as device options * @typedef {Object} DeviceOptions * @property {string} deviceID - Random GUID generated by Emulator once * @property {string} deviceName - Name of the Device * @property {string} brandName - Name of the device manifacturer * @property {string} os - Operating System name of the device (iOS | Android) * @property {string} osVersion - OS version of the device * @property {string} smartfaceVersion - Smartface runtime version such as: 4.4.0.1 * @property {Object} screen - Device screen info * @property {Object} screen.px - Screen pixel values * @property {number} screen.px.height - Screen height pixel value * @property {number} screen.px.width - Screen width pixel value * @property {Object} screen.dp - Screen dp values * @property {number} screen.dp.height - Screen height dp value * @property {number} screen.dp.width - Screen width dp value * @property {Object} screen.pt - Screen pt values * @property {number} screen.pt.height - Screen height pt value * @property {number} screen.pt.width - Screen width pt value * @property {Array.string} resourceFolderOrder - Density based resource folder names given in order * @property {string} cpu - Android CPU type. It can be ARM or x86 * @property {number} scaleFactor - Scale factor for images */ module.exports = Device;