This should not be confused with the official WebRTC for Unity.
This folder contains the preconfigured Unity project which can be opened with Unity (or added via UnityHub). Open the scene Scenes/SignalerExample, check the Launcher GameObject and the attached RTCServer component to configure the video stream resolution and signaler. This should be all that is needed to test it in the Unity Editor. Building and export requires you to change the build target in the build settings from Standalone to Universal Windows Platform.
The project uses Microsoft Mixed Reality Toolkit (MRTK), Microsoft Mixed Reality WebRTC and Newtonsoft.Json for Unity which are configured as UPM packages.
Make sure to copy the scoped registries and dependencies from Packages/manifest.json when you use this code in your project. Additionally, the project includes WebSocketSharp source code in the Assets/WebSocketSharp folder.
Before you run the Unity project, you need to create an SSL certificate. Modern browsers do not allow video and/or audio streaming over insecure connections. The whole process is described here but for this project can be summarized as:
- switch into the project folder
<git_repo>/UnityWebRTC/Assets/StreamingAssets/Certs - the file
req.confis used to configure the certificate. You need to adaptCNandsubjectAltNameif you want to access the stream from somewhere else thanlocalhost. - in this folder execute
openssl req -config req.conf -x509 -newkey rsa:4096 -keyout localhost_key.pem -out localhost.pem -nodes -days 3650openssl pkcs12 -export -in localhost.pem -inkey localhost_key.pem -out localhost.pfx.bin -nodes- if you have paid close attention, you will have realized that the resulting key hasn't been saved as a
*.pfxkey file (as done in the referenced instruction) but*.pfx.bin! It seems that*.pfxkey files inStreamingAssetsare not exported into UWP packages. By changing the file ending we can workaround that. - currently, the unity app expects the name to be
localhost.pfx.bin. Use that name even if the certificate was generated for another domain and/or IP (or change it inAssets/Scripts/WebSocketSignaler.cs)
- If you have chosen the default configuration, you can make Chrome/Chromium accept self-signed certificates for localhost by typing
chrome://flags/#allow-insecure-localhostinto the address bar and enabling that option. - Alternatively, you can access the
WebSocketSignalerviahttpsinstead ofwss(eg. typehttps:\\localhost:9999into your browser while the project is running) and manually accept the certificate.
As of 2020-10-16, Mixed Reality WebRTC does not support HoloLens 2 builds targeting ARM64 (ref). ARM (32-bit) seems to be supported though.
Open Assets/Scenes/SignalerExample in Unity and check the Launcher GameObject. The RTCServer features some settings which can be adjusted:
NeedVideo-- whether the video stream should be sentNeedAudio-- whether an audio track should be sendVideoWidth,VideoHeightandVideoFpsshould be set to values your WebCam/HoloLens camera is actually supporting. Otherwise the stream might not be initialized successfully.VideoFpscan be set to 0 to ignore that option.VideoProfileId-- Some HoloLens2 resolutions are only available via a profile. This project will prompt all found profiles and resolutions when initialized. WhenVideoProfileIdis empty, it will be ignored.ConnectionType-- Should be set toTCPorWebSocket, depending on the client (TCP: Python, WebSocket: browser) you plan to useUseRemoteStun-- when enabled, the serverstun.l.google.com:19302will be promoted to thePeerConnection. This might help in cases where server and client cannot reach each other directly.
1280x720@30fps896x504@24fps
896x504@15fpsProfile '{6B52B017-42C7-4A21-BFE3-23F009149887},120': 640x360@30fps