Scripting API Reference

API reference for developing scripts in Skylight Application Builder.

Common Terms

Promise

Many functions run asynchronously, such as the creation of a session. These asynchronous functions return a promise, which means that the function can be awaited (see here for more details) in order to pause execution of the code until that function has completed its operation.

Configuration Object

Instead of passing in multiple arguments into a function, a dictionary with the parameters as keys and the arguments as values is used instead for functions with two or more parameters. This dictionary is called the configuration object. This paradigm allows us to create code that is both resilient in changes to method signatures as well as provide and/or remove optional arguments more easily.

Global

The other objects (e.g. Session, Application) on this page are accessed through the skylight object (i.e. skylight.session.create()). The global object exists at the root level as its own object.

The global object can be written to and read from all scripts. This enables the ability for scripts to share functions and objects.

One typical use case for this is to define shared constants and functions in the Application Open script, which will then be accessible by all other scripts.

Session

session.create()

(method) SessionApi.create({ name: string, description: string, properties: object, participants: [Participant] }: NewSession): Promise<any>

Creates a new application session and automatically makes the creator a participant. You can also pass this an object of properties that match the session data model to set things like “title” and “status”.

Parameters
Return Value
Usage
Parameters

Parameters

Type

Description

name

string

A human-friendly name for the session.

description

string

A short description of the new session.

properties

object

Custom indexable and filterable properties.

participants

array

Users and groups participating in the session.

Return Value

Promise.<object> Session object

Usage
// Create a session with name and description:
await skylight.session.create({
name: 'Hello',
description: 'World',
properties: {
propertyA: "valueA",
propertyB: "valueB",
propertyC: "valueC" } })
// Create a session and assign it to another user:
await skylight.session.create({
name: 'Bob',
participants: [{
type: 'user',
id: 'af24d58b-0e91-4777-80bc-3218acde50a7'}]

session.set()

(method) SessionApi.set(sessionId: string): Promise<any>

Sets the current session. All session properties such as name, data, participants, media, etc are updated to match those in the specified session.

Parameters
Return Value
Parameters

Parameters

Type

Description

sessionID

string

A valid UUID representing an active Session.

Return Value

Promise.<object> Session object

session.unset()

(method) SessionApi.unset(sessionId: string): Promise<void>

Unsets the current session.

Parameters
Return Value
Parameters

Parameters

Type

Description

sessionID

string

A valid UUID representing an active Session.

Return Value

None

sessions

(property) Skylight.sessions: [Session]

Returns an array of “open” session objects according to this user’s permission.

Parameters
Return Value
Parameters

None

Return Value

array Session objects

session.update()

(method) SessionApi.update({ name: string, description: string, properties: object, participants: [Participant] }: UpdateSession): Promise<void>

Updates current session properties.

Parameters
Return Value
Parameters

Parameters

Type

Description

name

string

Session name

description

string

Session description

properties

object

Custom indexable and filterable properties

participant

array

Users and groups participating in the session

Return Value

None

session.data.<dataprops>

(property) Session.data: object

Returns the current snapshot of data for the session as known by this local state of the session.

Parameters
Return Value
Parameters

None

Return Value

object Session data

session.name

(property) SessionBase.name: string

Returns the session name.

Parameters
Return Value
Parameters

None

Return Value

string Session name

session.description

(property) SessionBase.description: string

Returns the session description.

Parameters
Return Value
Parameters

None

Return Value

string Session description

session.participants

(property) SessionBase.participants: [Participant]

Returns the session participants.

Parameters
Return Value
Parameters

None

Return Value

array Participants

session.properties

(property) SessionBase.properties: any

Returns any custom properties set on the session.

Parameters
Return Value
Parameters

None

Return Value

object Session properties

session.status

(property) Session.status: SessionStatus

Returns the session status.

Parameters
Return Value
Parameters

None

Return Value

string Session status (open|closed)

session.sessionId

(property) Session.sessionId: string

Returns a valid UUID representing an active Session.

Parameters
Return Value
Parameters

None

Return Value

string UUID for the active session

session.saveData()

(method) SessionApi.saveData(data: object): Promise<void>

Queues a patch to the new portion of the session data. Also, creates an event of type session_data_updated. If offline this data change will reflect on the local client session data structure.

Parameters
Return Value
Usage
Parameters

Parameters

Type

Description

data

object

An object representing an atomic data change

Return Value

None

Usage
//Create a new session
let newSession = await skylight.session.create({
name: skylight.application.data.processName })
//Set the session
await skylight.session.set(newSession.sessionId)
let newData = {
"stepStatus": {
"1": "incomplete",
"2": "incomplete",
"3": "incomplete"
}
}
//Save data to the sessioin
await skylight.session.saveData(newData)

session.createEvent()

(method) SessionApi.createEvent({ eventType: string, data: object, properties: Properties }: SessionEvent): Promise<void>

Creates a custom event for this session.

Parameters
Return Value
Parameters

Parameters

Type

Description

eventType

string

Custom name for the event, e.g. product_selected

data

object

Custom event data object

properties

object

Custom indexable and filterable properties

Return Value

None

session.media

(property) Session.media: [MediaItem]

Returns an array of all media captured during the session.

Parameters
Return Value
Parameters

None

Return Value

array <media Object>

session.addParticipant()

(method) SessionApi.addParticipant({ id: string, type: ParticipantType }: Participant): Promise<void>

Adds a participant to the session.

Parameters
Return Value
Parameters

Parameters

Type

Description

id

string

user or group id

type

string

user or group

Return Value

None

session.removeParticipant()

(method) SessionApi.removeParticipant({ id: string, type: ParticipantType }: Participant): Promise<void>

Removes participant from the session.

Parameters
Return Value
Parameters

Parameters

Type

Description

id

string

user or group id

type

string

user or group

Return Value

None

Application

application.applicationId

(property) ApplicationInfo.applicationId: string

Returns the application's unique id.

Parameters
Return Value
Parameters

None

Return Value

string applicationId

application.comment

(property) Application.comment: string

Returns the application comment.

Parameters
Return Value
Parameters

None

Return Value

string Application comment

application.compatibilityVersion

(property) Application.compatibilityVersion: number

Returns the application's compatibility version number.

Parameters
Return Value
Parameters

None

Return Value

integer Application's compatibility version number

application.configuration

(property) Application.compatibilityVersion: number

Returns the application compatibility version.

Parameters
Return Value
Parameters

None

Return Value

number Application compatibility version

application.data.<dataprops>

(property) Application.data: object

Returns the application data object. This is read only data that is built and downloaded at app install time.

Parameters
Return Value
Parameters

None

Return Value

object Application data

application.description

(property) Application.description: string

Returns the application description.

Parameters
Return Value
Parameters

None

Return Value

string Application description

application.name

(property) Application.name: string

Returns the application name.

Parameters
Return Value
Parameters

None

Return Value

string Application name

application.participants

(property) Application.participants: [ParticipantFull]

Returns an array participants visible to the user as defined by the role:read:self or role:read:any permission. The participant object includes user/group metadata.

If a user is given a role in the application as part of a group (and not explicitly as a user), they will not appear in the participants list as a user. See application.users below for a full list of user participants.

If the participant is of type user, then the participant will have a field named status which will have a string value of either active or away. If the participant's status is active, it means that they have recently been active on a Skylight Client or within the Skylight Web Portal.

Parameters
Return Value
Parameters

None

Return Value

array Participant object

application.stage

(property) Application.stage: ApplciationStage

Returns the application stage: draft or published.

Parameters
Return Value
Parameters

None

Return Value

string Application stage (draft or published)

application.users

(property) Application.users: [User]

Returns a list of users that have a role in this application, including those who are explicitly assigned a role, as well as those who are given a role through a group role assignment.

These user objects will also include a status field which will have a string value of either active or away. If the user's status is active, it means that they have recently been active on a Skylight Client or within the Skylight Web Portal.

Parameters
Return Value
Parameters

None

Return Value

[User] Application users

application.version

(property) ApplicationInfo.version: number

Returns the application version number.

Parameters
Return Value
Parameters

None

Return Value

number Application version

User

user.firstName

(property) UserProfile.firstName: string

Returns the user's first name.

Parameters
Return Value
Parameters

None

Return Value

string User's first name

user.lastName

(property) UserProfile.lastName: string

Returns the user's last name.

Parameters
Return Value
Parameters

None

Return Value

string User's last name

user.id

(property) UserProfile.id: string

Returns the user's unique identifier.

Parameters
Return Value
Parameters

None

Return Value

string User's unique identifier

user.locale

(property) UserProfile.locale: string

Returns the user's preferred language.

Parameters
Return Value
Parameters

None

Return Value

string Language code

user.permissions

(property) User.permissions: [string]

Returns an array of permission names for the user for the application that is currently open..

Parameters
Return Value
Parameters

None

Return Value

array Permission names

user.roles

(property) User.roles: [string]

Returns an array of role names for this user for the application that is currently open.

Parameters
Return Value
Parameters

None

Return Value

array Role names

getUsers()

(method) Skylight.getUsers(): Promise<[UserProfile]>

Returns a promise for a list of users.

This list of users does not contain information about users' presences (i.e., the status field that is available on user-type participants in the application.participants list).

Parameters
Return Value
Parameters

None

Return Value

Promise.<array> User objects

Network

network.connected

(property) Network.connected: boolean

Indicates if device is connected to the network.

Parameters
Return Value
Parameters

None

Return Value

boolean True if connected.

Environment

environment.application

(property) EnvironmentInfo.application: EnvironmentApplication

Returns an object for the current application.

Parameters
Return Value
Parameters

None

Return Value

object Application

environment.application.compatibilityVersion

(property) EnvironmentApplication.compatibilityVersion: number

Returns the compatibility version number of the Skylight client installed on the device.

Parameters
Return Value
Parameters

None

Return Value

number Skylight client compatibility version

environment.device

(property) EnvironmentInfo.device: Device

Returns on object with device information.

Parameters
Return Value
Parameters

None

Return Value

object Device

environment.deviceId

(property) EnvironmentInfo.deviceId: string

Returns the device's unique id.

Parameters
Return Value
Parameters

None

Return Value

string deviceId

environment.os

property) EnvironmentInfo.os: string

Returns the operating system for the current device.

Parameters
Return Value
Parameters

None

Return Value

string Device operating system

Local

local.data.<dataprops>

(property) Local.data: object

Returns the local data object. Local data is an ephemeral data store that you can use to track data across a single use of your application. It’s helpful for storing temporary information and application state that doesn’t need to make it to the back end and doesn’t need to survive for longer than a single use of the application.

Parameters
Return Value
Parameters

None

Return Value

object Local data

local.saveData()

(method) LocalApi.saveData(newData: any): void

Save new portion of the local data and refreshes the view.

Parameters
Return Value
Parameters

Parameters

Type

Description

data

object

An object representing an atomic data change

Return Value

None

Client Interfaces

openView()

(method) SkylightNative.openView({ viewId: string, cardId: string, root: boolean }: OpenViewOptions): Promise<void>

Open a new view on the client.

Parameters
Return Value
Parameters

Parameters

Type

Description

viewId

string

Identifier for the view to open

cardId

string

Optional identifier for the card to be focused upon opening the view

root

boolean

Optional flag for whether the view to be opened should be set as the root view

Return Value

None

closeView()

(method) SkylightNative.closeView(): any

Closes the current view to reveal the next view in the activity stack. If the current view is the application's root view then the user will be navigated to the applications list.

Parameters
Return Value
Parameters

None

Return Value

None

showNotification()

(method) SkylightNative.showNotification({ body: string, icon: Icon, backgroundColor: string, duration: number }: NotificationOptions): any

Show a non blocking notification.

Parameters
Return Value
Usage
Parameters

Parameters

Type

Description

body

string

The text content for the notification.

icon

object

Optional icon object:

  • uri: Must be a resource:// named icon

  • color: Must be a non-alpha Hex string color (#RRGGBB)

  • visible: Whether or not this icon should be shown

backgroundColor

string

Non-alpha Hex string color (#RRGGBB)

duration

number

The amount of time in milliseconds to show the notification

Return Value

None

Usage
const exIcon = {
'uri': 'resource://ic_misc_confirm_yes_01',
'color': '#27be89',
'visible': false}
let notification = {
'body': "Beep boop, I'm a message!",
'icon': exIcon,
'backgroundColor': '#ff0000',
'duration': 3000}
skylight.showNotification(notification)

startMediaViewer()

(method) SkylightNative.startMediaViewer({ mediaIds: [string] }: MediaViewerOptions): any

Starts a media viewer activity

Parameters
Return Value
Parameters

Parameters

Type

Description

mediaIds

array

An array of Media ids to view

Return Value

None

startTextInput()

(method) SkylightNative.startTextInput({ type: TextInputType, icon: Icon, label: string, helpText: string, placeholder: string, maxChar: number, characterConfig: CharacterConfig, preferSpeech: boolean }: StartTextInputOptions): Promise

Displays an activity for inputting text and returns a promise with the text that was input.

Parameters
Return Value
Usage
Parameters

Parameters

Type

Description

type

string

Type of keyboard to show (generic or numeric)

icon

object

Optional icon object:

  • uri: Must be a resource:// named icon

  • color: Must be a non-alpha Hex string color (#RRGGBB)

  • visible: Whether or not this icon should be shown

label

string

Optional label for the text field

helpText

string

Optional field for helper message that is displayed below the field

placeholder

string

Optional text that will be displayed in the field before text is entered

maxChar

number

Optional limit for the maximum allowed characters to be input

characterConfig

object

Optional configuration object for the text input field:

  • string characters: A string that defines which characters can be input into the text input field. These characters will be displayed on the Skylight character picker on smart glasses.

  • boolean backspace: Shows the backspace button on the Skylight character picker on smart glasses

  • boolean cancel: Shows the cancel button on the Skylight character picker on smart glasses

  • boolean confirm: Shows the confirm button on the Skylight character picker on smart glasses

preferSpeech

boolean

Optional flag to indicate that speech-to-text is the preferred method of input if supported on a wearable device. On Glass EE2 and RealWear HMT-1 the speech-to-text activity will be presented in place of the Skylight character picker.

Return Value

Promise.<string> Inputted text

Usage
const exIcon = {
'uri': 'resource://ic_misc_confirm_yes_01',
'color': '#27be89',
'visible': true}
const charConf = {
characters: '1123456abc',
backspace: true,
cancel: false,
confirm: true}
const resultString = await skylight.startTextInput({
type: 'generic',
icon: exIcon,
label: 'Confirm the quantity of effort in these examples',
helpText: 'No help',
placeholder: "1",
maxChar: 100,
preferSpeech: false,
charConf})
console.log("You input: ", resultString)

startScanner()

(method) SkylightNative.startScanner({ timeout: number, scanMode: ScanMode }: StartScannerOptions): Promise<string>

Launches an activity for scanning barcodes and returns a promise with the value of the barcode that was scanned.

Parameters
Return Value
Usage
Parameters

Parameters

Type

Description

timeout

number

Amount of time in milliseconds that the notification should be shown

scanMode

object

Type of scan to perform. Possible values:

  • skylight.SCAN_TYPE.PRODUCT_MODE (UPC/EAN/ “barcodes”)

  • skylight.SCAN_TYPE.ONE_D_MODE

    (One-dimension code types)

  • skylight.SCAN_TYPE.QR_CODE_MODE

    (QR Codes only)

  • skylight.SCAN_TYPE.AZTEC_MODE

    (Aztec symbology)

  • skylight.SCAN_TYPE.PDF_417_MODE

    (PDF417 symbology)

  • skylight.SCAN_TYPE.DEFAULT_MODE

    (Everything that the device supports in its default scanning mode)

Return Value

Promise.<string> Scanned value

Usage
const foo = await skylight.startScanner({
3000,
skylight.SCAN_TYPE.DEFAULT_MODE})
console.log("You scanned:", foo)

startPhotoCapture()

(method) SkylightNative.startPhotoCapture({ delay: number, properties: Properties, labels: [string], galleryFilter: [string] }: PhotoCaptureOptions): Promise<void>

Launches an activity for capturing photos.

Parameters
Return Value
Parameters

Parameters

Type

Description

delay

number

Amount of time in seconds that is displayed in a countdown before the photo is captured. Setting the value to 0 will enable manual capture mode.

properties

object

A dictionary of key-value pairs that is added to the captured media object. This is accessible when working with captured media objects from the skylight.session.media array.

labels

array

A list of strings that is added to the media object of the photo that is captured by the startPhotoCapture call. This list is used in future startPhotoCapture calls by the galleryFilter parameter, described below.

galleryFilter

array

This is a list of strings used to determine which previously-captured photos are shown in the gallery that appears when startPhotoCapture is called. Specifically, if any of the strings in this galleryFilter list matches any of the labels of a previously-captured photo, then that photo will appear in the gallery.

Return Value

None

startVideoCapture()

(method) SkylightNative.startVideoCapture({ properties: Properties, labels: [string], galleryFilter: [string] }: VideoCaptureOptions): Promise<void>

Launches an activity for capturing videos.

Parameters
Return Value
Parameters

Parameters

Type

Description

properties

object

A dictionary of key-value pairs that is added to the captured media object. This is accessible when working with captured media objects from the skylight.session.media array.

labels

array

A list of strings that is added to the media object of the photo that is captured by the startPhotoCapture call. This list is used in future startPhotoCapture calls by the galleryFilter parameter, described below.

galleryFilter

array

This is a list of strings used to determine which previously-captured photos are shown in the gallery that appears when startPhotoCapture is called. Specifically, if any of the strings in this galleryFilter list matches any of the labels of a previously-captured photo, then that photo will appear in the gallery.

Return Value

None

startVideoCall()

startVideoCall({ sessionId: string, notifyUser: boolean }: VideoCallOptions): Promise<void>

Starts a video call.

Parameters
Return Value
Parameters

Parameters

Type

Description

sessionId

string

A valid UUID representing an active session id. If sessionId is not set a new session is created.

notifyUser

boolean

Sends an incoming call notification to all other participants in the session.

Return Value

None

Bluetooth

bluetooth.devices

(property) Bluetooth.devices: [BluetoothDevice]

An array of currently connected bluetooth devices.

Parameters
Return Value
Parameters

None

Return Value

array Objects for currently connected Bluetooth devices, which is structured as: { "deviceMac": [address] "deviceName": [name as it is reported by the device] }

As long as Skylight is opened prior to connecting to any Bluetooth devices, the devices field will contain a list of all currently connected devices, including HID devices.

If you accidentally connect a HID device prior to entering Skylight, power-cycling the HID device will cause it to show up in skylight.bluetooth.devices. This is due to a platform limitation by which we cannot access the currently connected HID device, but we can pull info on the device whose connection state changed.