Genymobile / genymotion-device-web-player

Genymotion Virtual Device Web Player
https://www.genymotion.com/
MIT License
91 stars 31 forks source link
android android-emulator emulator webrtc

Genymotion device web renderer

npm GitHub

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.

Table of contents

  1. Requirements
  2. Getting started
    1. With NPM/Yarn
    2. With CDN
  3. Usage
  4. Player API
  5. Features & options
  6. Features notes
    1. Key mapping

Requirements

A Modern, WebRTC compatible, Web browser:

Getting started

With NPM/Yarn

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>

With CDN

<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>

Usage

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>

Player API

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

sendData({
    channel: 'battery',
    messages: ['set state level 10', 'set state status true'],
});

utils

keymapping

media

video

Features & options

A device renderer instance can be configured using the options argument (object). Possible configuration key / value are described below.

template

token

i18n

stun

{
    urls: [
        'stun:stun-server1.org:80',
        'stun:stun-server2.org:443',
        ...
    ],
}

turn

{
    urls: [],
    username: "myUsername",
    credential: "myPassword",
    default: false  // Whether or not we should use the TURN servers by default. Default: false.
}

streamResolution

...

streamBitrate

touch

mouse

keyboard

keyboardMapping

volume

...

rotation

...

navbar

... ... ...

power

...

fullscreen

... ...

camera

...

microphone

...

fileUpload

...

fileUploadUrl

clipboard

...

battery

...

gps

...

<!-- 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

capture

...

identifiers

...

Enables or disables the identifiers widget. This widget can be used to set the identifiers (Android ID / IMEI) of the Android virtual device.

network

...

phone

...

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

baseband

...

diskIO

...

gamepad

biometrics

translateHomeKey

connectionFailedURL

giveFeedbackLink

Contributing

Read through our contributing guidelines to learn about our submission process, coding rules and more.