From eb65f9d6b2db12cc8fe2d2139bebc30697928fe7 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Thu, 1 Aug 2024 17:03:29 +0200 Subject: [PATCH 1/4] Added typing --- index.d.ts | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..33af7214 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,102 @@ +declare module '@genymotion/device-web-player' { + interface KeyEffect { + initialX: number; + initialY: number; + name?: string; + description?: string; + } + + type Distance = { + distanceX: number; + distanceY: number; + }; + + interface KeyMap { + keys: Record; + name?: string; + description?: string; + } + + interface KeyMappingConfig { + dpad?: KeyMap[]; + tap?: KeyMap[]; + swipe?: KeyMap[]; + } + 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 Options { + token?: string; + template?: + | 'bootstrap' + | 'fullscreen' + | 'fullwindow' + | 'renderer' // Default + | 'renderer_minimal' + | 'renderer_no_toolbar' + | 'renderer_partial'; + i18n?: Record; + stun?: { urls?: Record }; + 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; + } +} + From c395c4ec556bf15079f690c4022a13419c61e0c7 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Thu, 1 Aug 2024 17:34:16 +0200 Subject: [PATCH 2/4] better typing --- index.d.ts | 201 ++++++++++++++++++++++++++++------------------------- 1 file changed, 105 insertions(+), 96 deletions(-) diff --git a/index.d.ts b/index.d.ts index 33af7214..60ca46f6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 { - keys: Record; - name?: string; - description?: string; - } +interface KeyMap { + keys: Record; + name?: string; + description?: string; +} - interface KeyMappingConfig { - dpad?: KeyMap[]; - tap?: KeyMap[]; - swipe?: KeyMap[]; - } - 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[]; + tap?: KeyMap[]; + swipe?: KeyMap[]; +} + +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; + stun?: { urls?: Record }; + 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; - stun?: { urls?: Record }; - 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 } From f419c1ed43805179138ea9624b668fd2c9a23204 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Thu, 1 Aug 2024 17:35:29 +0200 Subject: [PATCH 3/4] "types": "dist/index.d.ts", --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 661c3298..6f036e69 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "files": [ "dist" ], + "types": "dist/index.d.ts", "engines": { "node": ">=16" }, From 182b8a26270ab328f4467566dcf788038a974fc8 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Fri, 2 Aug 2024 12:25:52 +0200 Subject: [PATCH 4/4] fixed typing --- README.md | 2 +- index.d.ts | 101 +++++++++++++++++++++++++++++------------------------ 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 79b23ae8..7f08df9d 100644 --- a/README.md +++ b/README.md @@ -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` ... diff --git a/index.d.ts b/index.d.ts index 60ca46f6..137247f3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -type Distance = { +type KeyEffectDistance = { distanceX: number; distanceY: number; }; @@ -17,27 +17,32 @@ interface KeyMap { } interface KeyMappingConfig { - dpad?: KeyMap[]; + dpad?: KeyMap[]; tap?: KeyMap[]; - swipe?: KeyMap[]; + swipe?: KeyMap[]; } type DeviceRendererKeyMapping = { enable(isEnable: boolean): void; setConfig(config: KeyMappingConfig): void; - activeKeyMappingDebug(isTraceActivate: boolean, isGridActivate: boolean): void; + activeKeyMappingDebug(isTraceActivate?: boolean, isGridActivate?: boolean): void; }; -type VmEvent = 'beforeunload' | 'fingerprint' | 'gps' | 'BATTERY_LEVEL' +type VmEvent = 'beforeunload' | 'fingerprint' | 'gps' | 'BATTERY_LEVEL' | string // TODO Provide an exhaustive list type VmCommunication = { disconnect(): void; - addEventListener(event: VmEvent, callback: (msg: unknown) => void): void; - sendData(data: { channel: string; messages: string[] }); + 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(): unknown[]; + getRegisteredFunctions(): RegisteredFunctionDoc[]; }; type Media = { @@ -45,6 +50,10 @@ type Media = { unmute(): void; }; +type Video = { + fullscreen: () => void; +}; + type Template = 'bootstrap' | 'fullscreen' | 'fullwindow' @@ -54,58 +63,60 @@ type Template = 'bootstrap' | 'renderer_partial'; interface Options { - token?: string; - template?: Template; // Default: 'renderer' - i18n?: Record; - stun?: { urls?: Record }; - 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 + baseband?: boolean; // Default: false + battery?: boolean; // Default: true + biometrics?: boolean; // Default: true camera?: boolean; // Default: true - microphone?: boolean; // Default: false + capture?: boolean; // Default: true + clipboard?: boolean; // Default: true + connectionFailedURL?: string; + diskIO?: boolean; // Default: true fileUpload?: boolean; // Default: true fileUploadUrl?: string; - clipboard?: boolean; // Default: true - battery?: boolean; // Default: true + fullscreen?: boolean; // Default: true + gamepad?: boolean; // Default: true + giveFeedbackLink?: string; gps?: boolean; // Default: true gpsSpeedSupport?: boolean; // Default: false - capture?: boolean; // Default: true + i18n?: Record; 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 - Baseband?: boolean; // Default: false - diskIO?: boolean; // Default: true - gamepad?: boolean; // Default: true - biometrics?: 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 - connectionFailedURL?: string; - giveFeedbackLink?: string; + turn?: { + urls?: string[]; + username?: string; + credential?: string; + default?: boolean; // Default: false + }; + volume?: boolean; // Default: true } -type DeviceRenderer = { - VM_communication: VmCommunication; - utils: Utils; - keyMapping: DeviceRendererKeyMapping; +type DeviceRendererApi = { + keyMapping: true extends O['keyboardMapping'] ? DeviceRendererKeyMapping : undefined; // TODO Check media: Media; - video: HTMLVideoElement; + utils: Utils; + video?: Video; // Available if any plugin (e.g. fullscreen) using it is enabled. + VM_communication: VmCommunication; }; declare class DeviceRendererFactory { constructor(); - setupRenderer(targetElement: HTMLDivElement, webrtcAddress: string, options?: Options): DeviceRenderer; + setupRenderer(targetElement: HTMLDivElement, webrtcAddress: string, options?: O): DeviceRendererApi; } -export { DeviceRenderer, DeviceRendererFactory, KeyMappingConfig } +export { DeviceRendererApi, DeviceRendererFactory, KeyMappingConfig }