Cloud Phone TypeScript type declarations.
NPM
npm install -D @cloudmosa-inc/cloudphone-typesPNPM
pnpm add @cloudmosa-inc/cloudphone-types --save-devBun
bun add --development @cloudmosa-inc/cloudphone-typesThis document provides a reference for all non-standard APIs specific to Cloud Phone. These are custom APIs that extend standard web APIs to support Cloud Phone's unique features and hardware constraints.
The Feature Detection API allows you to detect specific Cloud Phone client capabilities so your app can offer the best user experience.
navigator.hasFeature(name: string): Promise<boolean>- Available on main thread and Web Workers
- Available on all Cloud Phone client versions
- Feature names are case-sensitive
| Feature | Description |
|---|---|
AudioCapture |
Audio recording using getUserMedia is supported |
AudioPlay |
Audio playback is supported for HTMLAudioElement |
AudioSeek |
Audio seeking is supported via HTMLMediaElement.currentTime |
AudioUpload |
Audio uploads are supported using <input type="file" accept="audio/*"> |
VideoCapture |
Video recording using getUserMedia is supported |
VideoSeek |
Video seeking is supported via HTMLMediaElement.currentTime |
VideoUpload |
Video uploads are supported using <input type="file" accept="video/*"> |
EmbeddedTextInput |
Embedded text input (IME with header/footer) is supported |
FileDownload |
File downloads are supported using <a download> |
FileUpload |
File uploads are supported using <input type="file"> |
ImageUpload |
Image uploads are supported using <input type="file" accept="image/*"> |
SmsScheme |
Links using sms: URI scheme are supported |
TelScheme |
Links using tel: URI scheme are supported |
Vibrate |
Vibration hardware is supported via navigator.vibrate() |
// Check if file downloads are supported
const fileDownloadSupported = await navigator.hasFeature("FileDownload");
if (fileDownloadSupported) {
downloadLink.setAttribute("download", "podcast.mp3");
downloadLink.classList.remove("hidden");
}
// Check if video seeking is supported
if (await navigator.hasFeature("VideoSeek")) {
scrubber.classList.remove("hidden");
}
// Check if vibration is supported
if (await navigator.hasFeature("Vibrate")) {
navigator.vibrate(200); // Vibrate for 200ms
}- Feature names are case-sensitive
- Invalid feature names resolve to
false - This detects software capabilities, not hardware availability or permissions
- Always catch exceptions when using detected features (e.g.,
getUserMediamay throwNotAllowedErrororNotFoundError)
See Feature Detection for complete documentation.
The Volume Manager API allows control of the system volume on Cloud Phone devices. Many Cloud Phone devices lack physical volume rockers, making this API essential for user experience.
interface VolumeManager {
requestUp(): void;
requestDown(): void;
}Available on navigator.volumeManager (may be undefined on non-Cloud Phone browsers).
Displays the volume HUD and immediately raises the system volume by one increment.
navigator.volumeManager.requestUp();Displays the volume HUD and immediately lowers the system volume by one increment.
navigator.volumeManager.requestDown();// Bind volume controls to custom keys
document.addEventListener("keydown", (e) => {
if (e.key === "1" && navigator.volumeManager) {
navigator.volumeManager.requestUp();
} else if (e.key === "2" && navigator.volumeManager) {
navigator.volumeManager.requestDown();
}
});- Controls system volume, not playback volume
HTMLMediaElement.volumedoes not work on Cloud Phone; usevolumeManagerinstead- Volume HUD appearance varies by device (different styles and increment counts)
- While HUD is visible, arrow keys are intercepted for volume control
- Volume HUD automatically dismisses after a few seconds of inactivity
See Multimedia - Volume Manager API for complete documentation.
The Back Event Handler allows you to override the default behavior of the Right Soft Key (RSK), which normally triggers history.back().
window.addEventListener("back", (event: Event) => void);The global "back" event fires when the user presses the Right Soft Key (RSK). By default, this navigates back in history or exits the app. You can intercept this behavior using event.preventDefault().
window.addEventListener("back", (event) => {
event.preventDefault();
// Handle custom back behavior
goToPreviousScreen();
});window.addEventListener("back", (event) => {
if (isSomethingToGoBackTo) {
event.preventDefault();
// Return to previous page
goBackInTime();
} else {
// Quit widget
window.close();
}
});let modalOpen = false;
window.addEventListener("back", (event) => {
if (modalOpen) {
event.preventDefault();
closeModal();
}
// If modal is not open, allow default behavior (exit app)
});- RSK is the physical Right Soft Key on Cloud Phone devices
- Default behavior:
history.back()or exit app if no history - Call
event.preventDefault()to intercept the default behavior - Call
window.close()to explicitly quit the widget - If you don't call
preventDefault(), the app will exit when history is empty
See Cloud Phone Design - Soft Keys for complete documentation.
Cloud Phone provides custom HTML attributes for controlling specific behaviors.
Controls whether text input displays a fullscreen Input Method Editor (IME) dialog.
"off"- Disables fullscreen IME (uses embedded input)- Default - Uses fullscreen IME on devices without embedded input support
<input type="text" x-puffin-entersfullscreen="off" id="customTextInput" />- Creating custom emoji keyboards
- Building custom input interfaces
- Apps that need to maintain visibility of the input element during editing
<input type="text" x-puffin-entersfullscreen="off" id="emojiInput" />const emojiMap = new Map([
["1", "π"],
["2", "π"],
["3", "π"],
]);
const input = document.getElementById("emojiInput");
input.addEventListener("keydown", (e) => {
const emoji = emojiMap.get(e.key);
if (emoji) {
input.value += emoji;
}
});- Only affects devices that support
EmbeddedTextInputfeature - On devices with fullscreen IME, attribute has no effect
- Apps disabling fullscreen IME must manually handle keyboard input
- Check
await navigator.hasFeature("EmbeddedTextInput")to detect support
Disables the default fullscreen display for <video> elements.
HTML Attribute
<video x-puffin-playsinline src="video.mp4" controls></video>JavaScript Property
const video = document.createElement("video");
video.playsInline = true;- Short, small videos (GIF-like clips)
- Inline video previews
- Video thumbnails
- Multi-video layouts
<div class="video-grid">
<video x-puffin-playsinline src="clip1.mp4" autoplay loop muted></video>
<video x-puffin-playsinline src="clip2.mp4" autoplay loop muted></video>
<video x-puffin-playsinline src="clip3.mp4" autoplay loop muted></video>
</div>- By default, Cloud Phone plays all videos in fullscreen
- Use this attribute for videos that should remain inline
- Particularly useful for short, looping clips or animations
- Does not affect video playback controls or functionality
For TypeScript projects, use the companion types.d.ts declaration file to enable type checking and autocompletion for all Cloud Phone APIs.
// Include in your project
/// <reference path="./types.d.ts" />
// Or add to tsconfig.json
{
"include": ["types.d.ts"]
}