# Desktop Vision for Unity

**Desktop Vision** is a package that allows [Desktop Vision](https://desktop.vision/) to be integrated into Unity applications. 

If you are interested in using Desktop Vision in your application, please contact us <contact@desktop.vision>. 

<br />
<br />
<br />

# Documentation

View our documentation [here](https://unity.desktop.vision)

<br />
<br />
<br />

# Overview

Desktop Vision utilizes webRTC to connect desktops (mac/linux/windows) through the use of a [Streamer App](https://desktop.vision/download). Once the Desktop Vision streamer app is installed and signed in, the computer will appear in your [computers list](https://desktop.vision/app/). You will be able to connect to & control this device from any web browser.

Desktop Vision grants oauth access to device lists with the Desktop Vision API through an oauth code flow. The Desktop Vision Unity Package automatically generates and displays a code through the menu prefab, but as long as you have a valid API key and APP ID, it is possible to create custom oauth flows. 

Ultimately, any generated oauth code will be invalid until it is manually activated by a user from the Desktop Vision platform [here](https://desktop.vision/app/#/authorize). This page will inform users that they are granting temporary access to their devices by activating the oauth code.

After an oauth token has been validated, an access token is requested from the Desktop Vision API, which grants access to the users computers. The menu prefab will automatically use the token to list user computers after the "validate" button is pressed. The computers listed are UI buttons that, when triggered, will spawn a Desktop Vision Computer in the scene.


### Streamer App
<img src="https://desktop-vision-resources.s3.us-west-1.amazonaws.com/Screenshot+2022-11-21+135231.png" alt="drawing" height="100" style=""/>

### Computer select screen
<img src="https://desktop-vision-resources.s3.us-west-1.amazonaws.com/Screenshot+2022-11-21+140001.png" alt="drawing" height="300" style=""/>

### Desktop Vision Menu oauth code
<img src="https://desktop-vision-resources.s3.us-west-1.amazonaws.com/Screenshot+2022-11-21+135407.png" alt="drawing" height="200" style=""/>

### Authorizescreen for oauth code validation
<img src="https://desktop-vision-resources.s3.us-west-1.amazonaws.com/Screenshot+2022-11-21+134527.png" alt="drawing" height="300" style=""/>


### Computer list screen after activating the oauth code
<img src="https://desktop-vision-resources.s3.us-west-1.amazonaws.com/Screenshot+2022-11-21+135750.png" alt="drawing" height="200" style=""/>

### Desktop Vision Computer in Game View
<img src="https://desktop-vision-resources.s3.us-west-1.amazonaws.com/Screenshot+2022-11-21+141640.png" alt="drawing" height="300" style=""/>


<br />
<br />
<br />


# Installation

## From disk

1. Navigate to Window > Package Manager
2. Click `+` button and select `Add package from disk`.
3. Select the `package.json` file

<br />
<br />
<br />

# Requirements

This page lists the Unity version and platform that the package supports.

## Unity Version

It is recommended to use the latest Long-Term Support (LTS) version of Unity, see [the post](https://blog.unity.com/technology/new-plans-for-unity-releases-introducing-the-tech-and-long-term-support-lts-streams) in Unity blog for LTS versions.

This version of the package is confirmed to be compatible with at least the following versions of the Unity Editor:

- **Unity 2019.4**
- **Unity 2020.3**
- **Unity 2021.3**

## Support Platform

- **Windows**
- **Linux**
- **macOS** (**Intel** and **Apple Slicon**)
- **iOS**
- **Android** (**ARM64** only. **ARMv7** is not supported)

## Additional Notes

Please note that there are unsupported platforms below.

- **Windows UWP** platform is not supported.
- Building for **iOS Simulator** is not supported.
- **WebGL** platform is not supported.

### Build on Linux

On Linux, `libc++1` `libc++abi1` packages should be installed.
Please install like command below 

``` 
sudo apt install -y libc++1 libc++abi1 
```

### Build on Android

To build the apk file for **Android platform**, you need to configure player settings below.

- Choose **IL2CPP** for **Scripting backend** in Player Settings Window.
- Set enadle **ARM64** and Set disable **ARMv7** for **Target Architectures** setting in Player Settings Window.

> [!NOTE]
> Set disable **Optimized Frame Pacing** in Player Settings Window. ( Known issues https://github.com/Unity-Technologies/com.unity.webrtc/issues/437)


<br />
<br />
<br />

# Quick Start

## Menu Quick Start from Prefab 

After adding Desktop Vision to your project, drag the Menu Prefab from `Packages > Runtime > Prefabs > Menu` into your scene. Configure your API key & APP ID, then click play. 

- On the menu script & prefab you may set a custom position where the screen will spawn. Alternatively, you can have computers spawn infront of the camera. 
- The menu can track camera movement, or remain fixed.
- Screen Size determines the height of the screen. The width will be determined by the computer aspect ratio.


## Managed Computer Quick Start from Prefab 

After adding Desktop Vision to your project, drag the Menu Prefab from `Packages > Runtime > Prefabs > ManagedComputer` into your scene. Set the z coordinate of the game object to be in front of the camera. Configure your API key & APP ID, then click play. 

- You can reset the screen to a "screensaver" by clicking the refresh button. 
- You can generate a new oauth code by clicking the desktop vision logo button.

## Menu Quick Start from Sample 

1. Navigate to `Window > Package Manager > Packages - Vali Ventures > Desktop Vision`.
2. Expand `Samples`.
3. Import `Desktop Vision Open XR - Menu`.
4. In the Unity Editor, under `Samples/Desktop Vision/1.0.0/Desktop Vision Open XR/Scenes`, open the `Desktop Vision Open XR.unity` file.
5. Click on the menu prefab.
6. Edit the DV Menu script to add your Desktop Vision App Id & Desktop Vision Api key.
7. Click the play button.

## Managed Computer Quick Start from Sample 

1. Navigate to `Window > Package Manager > Packages - Vali Ventures > Desktop Vision`.
2. Expand `Samples`.
3. Import `Desktop Vision Open XR - Computer`.
4. In the Unity Editor, under `Samples/Desktop Vision/1.0.0/Desktop Vision Open XR/Scenes`, open the `Desktop Vision Open XR.unity` file.
5. Click on the Managed Computer prefab.
6. Edit the DV Managed Computer script to add your Desktop Vision App Id & Desktop Vision Api key.
7. Click the play button.

## Managed Computer Quick Start from Fresh Project

1. Enable OpenXR in project settings.
    - `Edit > Project Settings > XR Plug-in Management` 
    - Enable XR Plug-in Management if not already enabled.
    - Under Plugin-in Providers, select Open XR.
2. Add the Desktop Vision Unity Package from `Window > Package Manager`.
3. Enable TMP Pro.
4. In the scene, add an XR Origin Action based.
5. Add the Desktop Vision ManagedComputer prefab from `Packages > Desktop Vision > Runtime > Assets > Prefabs > ManagedComputer`.
6. Select the ManagedComputer and fill in the `App Id` & `Api Key` fields.
7. Set the ManagedComputer Position to `{ x: 0, y: 0, z: 2 }`.
8. Press the play button, a screen with an oauth code should appear. Enter this code at https://desktop.vision/app/#/authorize
9.  You will automatically be connected to the selected computer.
10. Click the refresh button to reset the computer.
11. Click the Desktop Vision logo to generate a new code.

## Menu Quick Start from Fresh Project

1. Enable OpenXR in project settings.
    - `Edit > Project Settings > XR Plug-in Management` 
    - Enable XR Plug-in Management if not already enabled.
    - Under Plugin-in Providers, select Open XR.
2. Add the Desktop Vision Unity Package from `Window > Package Manager`.
3. Enable TMP Pro.
4. In the scene, add an XR Origin Action based.
5. Add the Desktop Vision Menu prefab from `Packages > Desktop Vision > Runtime > Assets > Prefabs > Menu`.
6. Select the menu and fill in the `App Id` & `Api Key` fields.
7. Set the Screen Position to `{ x: 0, y: 0, z: 2 }`.
8. Press the play button, a menu with an oauth code should appear. Enter this code at https://desktop.vision/app/#/authorize
9. A confirmation note will appear at the bottom of https://desktop.vision/app/#/authorize
10. Back in our unity application, click the validate button.
11. Select a desktop to control from the list of computers.
12. The desktop will appear in the game view. It can also be viewed from the scene view.
13. Click the refresh button to remove the computer.

Additional notes:
- 
-  In order to use Desktop Vision in XR, you may need to set up the XR origin again, and apply left/right controller filters to the project.
 


<br />
<br />
<br />

# Demo

You can find various videos and demonstrations of Desktop Vision on our [YouTube Channel](https://www.youtube.com/channel/UCYpXzAhoP_Lip01XY9Z__PQ).


## Demo of the Unity Package
[![Demo Video](https://yt-embed.herokuapp.com/embed?v=3Qqqik8EnzM)](https://www.youtube.com/watch?v=3Qqqik8EnzM?t=35s)
