Javascript API
All functions needed for custom application interfaces
Our phone injects multiple functions into your custom application's window, thus allowing you to access various functions and events.
Initialization
To initialize your custom application, you can access the global hphone
variable in the window context.
Events
The event system on our phone is based on mitt.
Event List
Name | Description | Argument |
---|---|---|
general.PHONE_OPEN | Fires when the phone is opened | - |
general.PHONE_CLOSED | Fires when the phone is opened | - |
general.CHANGED_STATE | Fires when the phone state changes | 'booting' | 'off' | 'screen_off' | 'locked' | 'unlocked' |
general.SETTING_UPDATED | Fires when a phone setting is updated | { name: string, value: any, oldValue: any } |
lockScreen.LOCK | Fires when the phone is locked | - |
lockScreen.UNLOCK | Fires when the phone is unlocked | - |
notificationManager.ADD | Fires when a new notification is sent | NotificationData |
Example
Functions
All functions provided in the window.hphone
variable
getSettings
Get all settings of the current phone
Example
useApplication
Gets current application functions and data
Example
useI18n
Gets i18n context of the phone. Useful in case you're using our built-in locale system, or need to get some locales.
Example
emitNui
Emits an NUI callback to your app's resource, asynchronous.
Arguments
Name | Type | Description |
---|---|---|
name | string | Callback name |
payload? | any | Payload, can be undefined, an object, a stringified object, etc. |
options? | { debounce: number } | Options, can use local debounce |
Example
openModal
Open a box modal with text and buttons
Arguments
Name | Type | Description |
---|---|---|
data | ModalData | Modal data |
Example
openModalSheet
Open a modal sheet, this is what's used for full screen modals, such as media selection, contact selection, etc.
Arguments
Name | Type | Description |
---|---|---|
data | ModalSheetData | Modal data |
Example
Types
ModalData
Name | Type | Description |
---|---|---|
title | string | Title |
description | string | Description |
buttons | ModalButton[] | Modal buttons |
ModalButton
Name | Type | Description |
---|---|---|
type | 'confirm' | 'cancel' | Button type |
label | string | Button label |
callback | () => void | Callback function |
ModalSheetData
Name | Type | Description |
---|---|---|
name | ModalSheetName | Modal name |
data? | any | Modal data, can be an array / proxy and it will be mutated on finish by default |
description? | string | Modal description |
callback | (data: any) => void | Callback function |
NotificationData
Name | Type | Description |
---|---|---|
title? | string | Notification title |
content | string | Notification content |
duration | number | Notification duration |
application? | { name: string } | Notification application |
Modal Sheets
select_media
Example
Options
Name | Type | Description |
---|---|---|
limit | number | Limit of media to be selected |
allowCustomUrl | boolean | Allow custom URL input? |
allowTake | boolean | Allow taking media in camera? |
allowedTypes | ('video' | 'image')[] | Allowed types of media |
select_contact
Example
Options
Name | Type | Description |
---|---|---|
limit | number | Limit of contacts to be selected |
new_contact
Example
Data (optional)
Name | Type | Description |
---|---|---|
number | string | Pre entered phone number |
new_chat
Example
Data (optional)
Name | Type | Description |
---|---|---|
number | string | Pre entered phone number |
content | string | Pre entered content |
attachments | Attachment[] | Pre added attachments |
gif
Example
Shared options
Name | Type | Description |
---|---|---|
disableMutation | boolean | Disable mutation of the original data object / array? |
liveChanges | boolean | Enable live mutation of the original data array when selecting / deselecting stuff? |
disableGradient | boolean | Disable gradient background on the modal |
noDimming | boolean | Disable dimming above / under the modal |
hideButton | boolean | Disable the default 'Done' button |
fullScreen | boolean | Should the modal be fullscreen |
compact | boolean | Compact size of the modal |
closeAfterCallback | boolean | Close the modal after callback? E.g. when a picture is selected |
Last updated on