Skip to main content

DeviceInfoSystem

Class

Provides information about the device running the Lens.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Provides information about the device running the Lens. Accessible through global.deviceInfoSystem.

Index

Example

var osType = global.deviceInfoSystem.getOS();
var isMobile = (osType == OS.iOS || osType == OS.Android);

Extends

Properties

onBatteryStateChanged

readonly onBatteryStateChanged: event1<BatteryStateArgs, void>

SPECS

Triggered when battery state changes.

Since

Lens Scripting Version 364

Example

deviceInfoSystem.onBatteryStateChanged.add((batteryState) => {
print(
"Battery state changed. New battery level: " +
batteryState.batteryLevel +
"%, isCharging: " +
batteryState.isCharging
);
});
@component
export class NewScript extends BaseScriptComponent {
onAwake() {
deviceInfoSystem.onBatteryStateChanged.add((batteryState) => {
print(
"Battery state changed. New battery level: " +
batteryState.batteryLevel +
"%, isCharging: " +
batteryState.isCharging
);
});
}
}

onInternetStatusChanged

readonly onInternetStatusChanged: event1<InternetStatusChangedArgs, void>

SPECS

Triggered when internet availability changed.

Since

Lens Scripting Version 301

Example

// @input Component.Text textObject

global.deviceInfoSystem.onInternetStatusChanged.add(function(eventData) {
script.textObject.text = eventData.isInternetAvailable
? "UPDATED: Internet is available"
: "UPDATED: No internet";
});
@component
export class NewScript extends BaseScriptComponent {
@input textObject: Text;

onAwake() {
this.textObject.text = global.deviceInfoSystem.isInternetAvailable()
? "Internet is available"
: "No internet";

global.deviceInfoSystem.onInternetStatusChanged.add((args) => {
this.textObject.text = args.isInternetAvailable
? "UPDATED: Internet is available"
: "UPDATED: No internet";
});
}
}

performanceIndexes

readonly performanceIndexes: PerformanceIndexes

Returns the PerformanceIndexes object, which provides performance information about the device.

Since

Lens Scripting Version 323


screenScale

readonly screenScale: number

Specifies the device pixel ratio. Can be used to set rendering at the real screen resolution.

Since

Lens Scripting Version 271

Methods

getBatteryState()

getBatteryState(): BatteryStateArgs

SPECS

Returns the current battery state of the device.

Returns

BatteryStateArgs

Since

Lens Scripting Version 364

Example

var deviceInfoSystem = global.deviceInfoSystem;
if (!deviceInfoSystem.isEditor()) {
var batteryState = deviceInfoSystem.getBatteryState();
print(
"Current battery level: " +
batteryState.batteryLevel +
"%, isCharging: " +
batteryState.isCharging
);
}
@component
export class NewScript extends BaseScriptComponent {
onAwake() {
const deviceInfoSystem = global.deviceInfoSystem;
if (!deviceInfoSystem.isEditor()) {
const batteryState = deviceInfoSystem.getBatteryState();
print(
"Current battery level: " +
batteryState.batteryLevel +
"%, isCharging: " +
batteryState.isCharging
);
}
}
}

getLensApiVersion()

static getLensApiVersion(): number

Returns the version of the LensCore library.

Returns

number

Since

Lens Scripting Version 364


getOS()

getOS(): OS

Exposes user data

Returns the operating system type of the device.

Returns

OS


getTrackingCamera()

getTrackingCamera(): DeviceCamera

Provides the tracking camera's DeviceCamera.

Returns

DeviceCamera

Since

Lens Scripting Version 148


getTrackingCameraForId()

getTrackingCameraForId(cameraId): DeviceCamera

SPECS

Get the DeviceCamera object for the given camera ID which provides intrinsics/extrinsics of the camera.

Parameters

ParameterType
cameraIdCameraId

Returns

DeviceCamera


getTypeName()

static getTypeName(): TypeName<DeviceInfoSystem>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<DeviceInfoSystem>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isCameraKit()

isCameraKit(): boolean

Returns whether the current Lens is running in CameraKit.

Returns

boolean

Since

Lens Scripting Version 303


isDesktop()

isDesktop(): boolean

Returns whether the current Lens is running in a desktop computer.

Returns

boolean

Since

Lens Scripting Version 148


isEditor()

isEditor(): boolean

Returns whether the current Lens is running in Lens Studio.

Returns

boolean

Since

Lens Scripting Version 148


isFormatSupported()

isFormatSupported(format, usage): boolean

Returns whether the given texture format supports every requested capability on the current device.

usage is a combination of TextureUsage flags; all of the requested capabilities must be supported for the result to be true, and passing no flags returns false. Support depends on both the device and the graphics backend it renders with, so a format available on one device may be unavailable on another.

A format that fails the Render check cannot be used as a render target.

Parameters

ParameterType
formatTextureFormat
usageTextureUsage

Returns

boolean

Since

Lens Scripting Version 375

Example

var deviceInfoSystem = global.deviceInfoSystem;
var format = TextureFormat.RGBA16Float;

if (deviceInfoSystem.isFormatSupported(format, TextureUsage.Render | TextureUsage.Filter)) {
print("RGBA16Float can be rendered to and filtered on this device");
} else {
print("RGBA16Float is unavailable, falling back to RGBA8Unorm");
}

isInternetAvailable()

isInternetAvailable(): boolean

Returns true if the device has access to the internet.

Returns

boolean

Since

Lens Scripting Version 300

Example

// @input Component.Text textObject

script.textObject.text = global.deviceInfoSystem.isInternetAvailable()
? "Internet is available"
: "No internet";
@component
export class NewScript extends BaseScriptComponent {
@input textObject: Text;

onAwake() {
this.textObject.text = global.deviceInfoSystem.isInternetAvailable()
? "Internet is available"
: "No internet";
}
}

isMobile()

isMobile(): boolean

Returns whether the current Lens is running in a mobile device.

Returns

boolean

Since

Lens Scripting Version 148


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


isSpectacles()

isSpectacles(): boolean

Returns whether the current Lens is running in a Spectacles device.

Returns

boolean

Since

Lens Scripting Version 148


supportsDualCamera()

supportsDualCamera(callback): void

Accepts a callback which indicates whether the current device is capable of providing both front and rear camera texture simultaneously.

Parameters

ParameterType
callback(supportsDualCamera) => void

Returns

void

Since

Lens Scripting Version 301