Device

View source

Describes the detected platform, browser, and rendering capabilities for an application.

Install DevicePlugin to add this world resource to an application. It fills the DeviceCapabilities flags and detects values from PlatformOS and Browser so application code can choose compatible behavior for the current environment. A new instance starts with PlatformOS.Unknown and Browser.Unknown. webAudio remains false until application code changes it.

Examples

import { Device } from '@wimaengine/device'

// With DevicePlugin installed, read the resource from a world.
function chooseRenderer(world) {
  const device = world.getResource(Device)

  if (device.capabilities.webgpu) return 'webgpu'
  if (device.capabilities.webgl) return 'webgl'
  return device.capabilities.canvas ? 'canvas' : 'none'
}

Constructor


constructor()

Properties


platform: number

View source

Detected operating system or platform.

The value starts as PlatformOS.Unknown and remains unknown when no supported platform is detected.

Default: PlatformOS.Unknown

browser: number

View source

Browser detected for the current application environment.

The value starts as Browser.Unknown and remains unknown when no supported browser is detected.

Default: Browser.Unknown

Methods


staticserialize(value: Device): DeviceSerial

View source

Converts a device resource to a plain object.

The result contains capabilities, platform, and browser fields.

Parameters

NameDescriptionDefault
value

Device to convert.

—

Returns

Object containing the device data.

staticdeserialize(value: DeviceSerial, out?: Device): Device

View source

Restores a device from a plain object.

When out is supplied, it is populated and returned. Its existing DeviceCapabilities object is reused, and its platform and browser values are replaced. Otherwise, a new Device is created.

Parameters

NameDescriptionDefault
value——
out?

Device instance to populate.

...