Skip to content

Commit

Permalink
better typing
Browse files Browse the repository at this point in the history
  • Loading branch information
OoDeLally committed Aug 1, 2024
1 parent eb65f9d commit c395c4e
Showing 1 changed file with 105 additions and 96 deletions.
201 changes: 105 additions & 96 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,111 @@
declare module '@genymotion/device-web-player' {
interface KeyEffect {
initialX: number;
initialY: number;
name?: string;
description?: string;
}
type Distance = {
distanceX: number;
distanceY: number;
};

type Distance = {
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 KeyMap<E> {
keys: Record<string, E>;
name?: string;
description?: string;
}

interface KeyMappingConfig {
dpad?: KeyMap<KeyEffect & Distance>[];
tap?: KeyMap<KeyEffect>[];
swipe?: KeyMap<KeyEffect & Distance>[];
}
type DeviceRendererKeyMapping = {
enable(isEnable: boolean): void;
setConfig(config: KeyMappingConfig): void;
activeKeyMappingDebug(isTraceActivate: boolean, isGridActivate: boolean): void;
};
type VmCommunication = {
disconnect(): void;
addEventListener(event: string, callback: (msg: unknown) => void): void;
sendData(data: { channel: string; messages: string[] });
};
type Utils = {
getRegisteredFunctions(): unknown[];
};
type Media = {
mute(): void;
unmute(): void;
};
type DeviceRenderer = {
VM_communication: VmCommunication;
utils: Utils;
keyMapping: DeviceRendererKeyMapping;
media: Media;
video: HTMLVideoElement;
interface KeyMappingConfig {
dpad?: KeyMap<KeyEffect & Distance>[];
tap?: KeyMap<KeyEffect>[];
swipe?: KeyMap<KeyEffect & Distance>[];
}

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

type VmEvent = 'beforeunload' | 'fingerprint' | 'gps' | 'BATTERY_LEVEL'

type VmCommunication = {
disconnect(): void;
addEventListener(event: VmEvent, callback: (msg: unknown) => void): void;
sendData(data: { channel: string; messages: string[] });
};

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

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

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

interface Options {
token?: string;
template?: Template; // Default: 'renderer'
i18n?: Record<string, unknown>;
stun?: { urls?: Record<string, string> };
turn?: {
urls?: string[];
username?: string;
credential?: string;
default?: boolean; // Default: false
};
interface Options {
token?: string;
template?:
| 'bootstrap'
| 'fullscreen'
| 'fullwindow'
| 'renderer' // Default
| 'renderer_minimal'
| 'renderer_no_toolbar'
| 'renderer_partial';
i18n?: Record<string, unknown>;
stun?: { urls?: Record<string, string> };
turn?: {
urls?: string[];
username?: string;
credential?: string;
default?: boolean; // Default: false
};
streamResolution?: boolean; // Default: true
streamBitrate?: boolean; // Default: false
touch?: boolean; // Default: true
mouse?: boolean; // Default: true
keyboard?: boolean; // Default: true
volume?: boolean; // Default: true
rotation?: boolean; // Default: true
navbar?: boolean; // Default: true
power?: boolean; // Default: true
fullscreen?: boolean; // Default: true
camera?: boolean; // Default: true
microphone?: boolean; // Default: false
fileUpload?: boolean; // Default: true
fileUploadUrl?: string;
clipboard?: boolean; // Default: true
battery?: boolean; // Default: true
gps?: boolean; // Default: true
gpsSpeedSupport?: boolean; // Default: false
capture?: boolean; // Default: true
identifiers?: boolean; // Default: true
network?: boolean; // Default: true
phone?: boolean; // Default: true
Baseband?: boolean; // Default: false
diskIO?: boolean; // Default: true
gamepad?: boolean; // Default: true
biometrics?: boolean; // Default: true
translateHomeKey?: boolean; // Default: false
connectionFailedURL?: string;
giveFeedbackLink?: string;
}
declare class DeviceRendererFactory {
constructor();
setupRenderer(targetElement: HTMLDivElement, vmUrl: string, options?: Options): DeviceRenderer;
}
streamResolution?: boolean; // Default: true
streamBitrate?: boolean; // Default: false
touch?: boolean; // Default: true
mouse?: boolean; // Default: true
keyboard?: boolean; // Default: true
volume?: boolean; // Default: true
rotation?: boolean; // Default: true
navbar?: boolean; // Default: true
power?: boolean; // Default: true
fullscreen?: boolean; // Default: true
camera?: boolean; // Default: true
microphone?: boolean; // Default: false
fileUpload?: boolean; // Default: true
fileUploadUrl?: string;
clipboard?: boolean; // Default: true
battery?: boolean; // Default: true
gps?: boolean; // Default: true
gpsSpeedSupport?: boolean; // Default: false
capture?: boolean; // Default: true
identifiers?: boolean; // Default: true
network?: boolean; // Default: true
phone?: boolean; // Default: true
Baseband?: boolean; // Default: false
diskIO?: boolean; // Default: true
gamepad?: boolean; // Default: true
biometrics?: boolean; // Default: true
translateHomeKey?: boolean; // Default: false
connectionFailedURL?: string;
giveFeedbackLink?: string;
}

type DeviceRenderer = {
VM_communication: VmCommunication;
utils: Utils;
keyMapping: DeviceRendererKeyMapping;
media: Media;
video: HTMLVideoElement;
};

declare class DeviceRendererFactory {
constructor();
setupRenderer(targetElement: HTMLDivElement, webrtcAddress: string, options?: Options): DeviceRenderer;
}

export { DeviceRenderer, DeviceRendererFactory, KeyMappingConfig }

0 comments on commit c395c4e

Please sign in to comment.