Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added typing #87

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ Enables or disables the identifiers widget. This widget can be used to set the i

Enables or disables the phone widget. This widget can be used to send SMS or phone call the Android virtual device.

### `Baseband`
### `baseband`

<img align="right" src="./doc/assets/ic_baseband_active_black.svg" alt="..."></img>

Expand Down
122 changes: 122 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
type KeyEffectDistance = {
distanceX: number;
distanceY: number;
};

interface KeyEffect {
initialX: number;
initialY: number;
name?: string;
description?: string;
}

interface KeyMap<E> {
keys: Record<string, E>;
name?: string;
description?: string;
}

interface KeyMappingConfig {
dpad?: KeyMap<KeyEffect & KeyEffectDistance>[];
tap?: KeyMap<KeyEffect>[];
swipe?: KeyMap<KeyEffect & KeyEffectDistance>[];
}

type DeviceRendererKeyMapping = {
enable(isEnable: boolean): void;
setConfig(config: KeyMappingConfig): void;
activeKeyMappingDebug(isTraceActivate?: boolean, isGridActivate?: boolean): void;
};

type VmEvent = 'beforeunload' | 'fingerprint' | 'gps' | 'BATTERY_LEVEL' | string // TODO Provide an exhaustive list

type VmCommunication = {
disconnect(): void;
addEventListener(event: VmEvent, callback: (msg: string) => void): void; // TODO Verify if msg is always string
sendData(data: { channel: string; messages: string[] }): void; // TODO Verify typing
};

type RegisteredFunctionDoc = {
apiName: string,
apiDescription: string,
}

type Utils = {
getRegisteredFunctions(): RegisteredFunctionDoc[];
};

type Media = {
mute(): void;
unmute(): void;
};

type Video = {
fullscreen: () => void;
};

type Template = 'bootstrap'
| 'fullscreen'
| 'fullwindow'
| 'renderer'
| 'renderer_minimal'
| 'renderer_no_toolbar'
| 'renderer_partial';

interface Options {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small question on the Options type: will we be able to override it from the Shadow repo? There are a few more options that are set in the Shadow player compared to the Geny player.

baseband?: boolean; // Default: false
battery?: boolean; // Default: true
biometrics?: boolean; // Default: true
camera?: boolean; // Default: true
capture?: boolean; // Default: true
clipboard?: boolean; // Default: true
connectionFailedURL?: string;
diskIO?: boolean; // Default: true
fileUpload?: boolean; // Default: true
fileUploadUrl?: string;
fullscreen?: boolean; // Default: true
gamepad?: boolean; // Default: true
giveFeedbackLink?: string;
gps?: boolean; // Default: true
gpsSpeedSupport?: boolean; // Default: false
i18n?: Record<string, string>;
identifiers?: boolean; // Default: true
keyboard?: boolean; // Default: true
keyboardMapping?: boolean; // Default: true
microphone?: boolean; // Default: false
mobilethrottling?: boolean; // Default: false
mouse?: boolean; // Default: true
navbar?: boolean; // Default: true
network?: boolean; // Default: true
phone?: boolean; // Default: true
power?: boolean; // Default: true
rotation?: boolean; // Default: true
streamBitrate?: boolean; // Default: false
streamResolution?: boolean; // Default: true
stun?: { urls?: string[] };
template?: Template; // Default: 'renderer'
token?: string;
touch?: boolean; // Default: true
translateHomeKey?: boolean; // Default: false
turn?: {
urls?: string[];
username?: string;
credential?: string;
default?: boolean; // Default: false
};
volume?: boolean; // Default: true
}

type DeviceRendererApi<O extends Options> = {
keyMapping: true extends O['keyboardMapping'] ? DeviceRendererKeyMapping : undefined; // TODO Check
media: Media;
utils: Utils;
video?: Video; // Available if any plugin (e.g. fullscreen) using it is enabled.
VM_communication: VmCommunication;
};

declare class DeviceRendererFactory {
constructor();
setupRenderer<O extends Options>(targetElement: HTMLDivElement, webrtcAddress: string, options?: O): DeviceRendererApi;
}

export { DeviceRendererApi, DeviceRendererFactory, KeyMappingConfig }
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"files": [
"dist"
],
"types": "dist/index.d.ts",
"engines": {
"node": ">=16"
},
Expand Down
Loading