This repository contains the Genymotion device web renderer JavaScript SDK. It provides an easy way to integrate Genymotion devices running in the cloud into any web application. You will be able to display an emulator screen and interact with the device.
It focuses on:
For more information about Genymotion devices, please visit genymotion website.
A Modern, WebRTC compatible, Web browser:
Using yarn:
yarn add @genymotion/device-web-player
Using npm:
npm install @genymotion/device-web-player
Package import (commonJS):
const {DeviceRendererFactory} = require('genymotion/device-web-player');
<style lang="scss">
@import 'genymotion-device-web-renderer/dist/css/device-renderer.min.css';
</style>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@genymotion/device-web-player@4.1.1/dist/css/device-renderer.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/@genymotion/device-web-player@4.1.1/dist/js/device-renderer.min.js"></script>
Use DeviceRendererFactory
to instanciate one or more device renderer.
All you need is an HTML element to use as a container. See example below.
To find your instance WebRTC address, use the SaaS API
or check the PaaS documentation, based on your device provider.
<!-- OPTIONAL: Import google maps library with your API key to enable map positioning feature
<script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxxxxx-yyyyyyyyyyyyyy"></script>
-->
<div id="genymotion"></div>
<script>
// Instance address
const webrtcAddress = 'wss://x.x.x.x';
const container = document.getElementById('genymotion');
// See "Features & options" section for more details about options
const options = {
template: 'renderer', // template defines how renderer is displayed
token: 'i-XXXXXXXXXX', // token is the shared secret to connect to your VM
fileUpload: false, // requires fileUploadUrl
};
// Device renderer instanciation
const {DeviceRendererFactory} = window.genyDeviceWebPlayer;
const deviceRendererFactory = new DeviceRendererFactory();
const rendererAPI = deviceRendererFactory.setupRenderer(
container, // the container element or element ID to use
webrtcAddress, // the websocket address of your instance connector
options, // options object to enable or disable features
);
// Disconnect the device renderer, closing any open data channels.
window.addEventListener('beforeunload', function () {
playerAPI.disconnect();
});
</script>
The Player API provides functionality for managing plugin options and websocket communication. These operations are handled through the API (categorized) object returned by the setupRenderer
function.
VM_communication
disconnect
Disconnects the player from the virtual machine (VM) and cleans up the memory listener.
addEventListener
Registers a listener for messages emitted from the VM.
Parameters:
Example Usage
addEventListener('fingerprint', (msg) => {
console.log(msg);
});
sendData
Sends messages to the VM.
data
(object): An object containing the channel and the messages to be sent.
channel
(string): The channel to send the messages to.messages
(array): An array of messages to be sent.sendData({
channel: 'battery',
messages: ['set state level 10', 'set state status true'],
});
utils
getRegisteredFunctions
Returns a list of available functions with optional descriptions.
keymapping
setConfig
supply a config for keymapping
{
dPad:[{
keys:[
{
key: 'w',
effect: {
initialX: 20,
initialY: 80,
distanceX: 0,
distanceY: -10,
},
name: 'up',
description: 'move up',
},
{
key: 's',
effect: {
initialX: 20,
initialY: 80,
distanceX: 0,
distanceY: 10,
},
name: 'down',
description: 'move down',
},
{
key: 'a',
effect: {
initialX: 20,
initialY: 80,
distanceX: -10,
distanceY: 0,
},
name: 'left',
description: 'move left',
},
{
key: 'd',
effect: {
initialX: 20,
initialY: 80,
distanceX: 10,
distanceY: 0,
},
name: 'up',
description: 'move right',
},
],
name: 'character movement',
description: 'left joystick used to move the character',
}],
tap:[{
key: 'p',
effect: {
initialX: 50,
initialY: 50,
},
name:'Fire'
}],
swipe: [{
key: 'u',
effect: {
initialX: 50,
initialY: 50,
distanceX: -10,
distanceY: 0,
description: 'swipe left',
},
name:'Left dodge',
description: 'Dodge on the left'
}]
}
activeKeyMappingDebug
helper to create the config mapping
isTraceActivate
(boolean) : when true all click on video stream will print x and y coord over the videoisGridActivate
(boolean): when true display a grid over the video stream. Row and column have both a size of 10%.enable
isActive
(boolean) : Optionnal parameter to activate or desactivate keymapping, default falsemedia
mute
unmute
video
fullscreen
Need to be call from an user action, in accordance with browser security rules
A device renderer instance can be configured using the options
argument (object). Possible configuration key / value are described below.
template
String
renderer
PaaS
, SaaS
bootstrap
, fullscreen
, fullwindow
, renderer
, renderer_minimal
, renderer_no_toolbar
, renderer_partial
.token
String
undefined
PaaS
, SaaS
i18n
Object
{}
PaaS
, SaaS
stun
Object
{}
PaaS
, SaaS
{
urls: [
'stun:stun-server1.org:80',
'stun:stun-server2.org:443',
...
],
}
turn
Object
{}
PaaS
, SaaS
{
urls: [],
username: "myUsername",
credential: "myPassword",
default: false // Whether or not we should use the TURN servers by default. Default: false.
}
streamResolution
Boolean
true
SaaS
streamBitrate
Boolean
false
SaaS
touch
Boolean
true
PaaS
, SaaS
mouse
and keyboard
.mouse
Boolean
true
PaaS
, SaaS
touch
and keyboard
.keyboard
Boolean
true
PaaS
, SaaS
keyboardMapping
Boolean
true
PaaS
, SaaS
volume
Boolean
true
PaaS
, SaaS
rotation
Boolean
true
PaaS
, SaaS
navbar
Boolean
true
PaaS
, SaaS
power
Boolean
true
PaaS
, SaaS
fullscreen
Boolean
true
PaaS
, SaaS
camera
Boolean
true
PaaS
, SaaS
microphone
property is also true, then the default audio input will be used as well.microphone
Boolean
false
PaaS
fileUpload
Boolean
true
PaaS
, SaaS
fileUploadUrl
String
undefined
PaaS
, SaaS
fileUpload
is set to true
.clipboard
Boolean
true
PaaS
, SaaS
battery
Boolean
true
PaaS
, SaaS
gps
Boolean
true
PaaS
, SaaS
<!-- OPTIONAL: Import google maps library with your API key to enable map positioning feature -->
<script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxxxxx-yyyyyyyyyyyyyy"></script>
gpsSpeedSupport
Boolean
false
PaaS
, SaaS
capture
Boolean
true
PaaS
, SaaS
identifiers
Boolean
true
PaaS
, SaaS
Enables or disables the identifiers widget. This widget can be used to set the identifiers (Android ID / IMEI) of the Android virtual device.
network
Boolean
true
PaaS
, SaaS
phone
Boolean
true
PaaS
, SaaS
Enables or disables the phone widget. This widget can be used to send SMS or phone call the Android virtual device.
baseband
Boolean
false
PaaS
diskIO
Boolean
true
PaaS
, SaaS
gamepad
Boolean
true
SaaS
, PaaS
biometrics
Boolean
true
SaaS
, PaaS
translateHomeKey
Boolean
false
PaaS
META
+ ENTER
connectionFailedURL
String
undefined
SaaS
, PaaS
giveFeedbackLink
String
giveFeedbackLink
SaaS
, PaaS
Read through our contributing guidelines to learn about our submission process, coding rules and more.