This guide focuses on the Unity asset WebRTC Video Chat but most also applies to WebRTC Network which is a part of it but also available separately.
Important folders and files
- WebRtcNetwork/scripts/WebRtcNetworkFactory.cs – Main access for the pure network functionality.
- WebRtcNetwork/server.zip – Contains an open source node.js signaling server. More at Server side info / Tutorials
- WebRtcNetwork/example – contains the ChatApp example. A application creating a simple ChatApp (more below).
- WebRtcNetwork/Plugins and WebRtcVideoChat/Plugins
- Contains C# libraries that provide the API
- The subfolders contain wrappers that map the API to platform and processor architecture specific code
- WebRtcVideoChat/scripts/UnityCallFactory.cs – Main access for Video/Audio call functionality
- WebRtcVideoChat/callapp – contains a fully functional 1-to-1 video chat app (see below)
- WebRtcVideoChat/examples – contains a few simple examples to learn how to use the API
Project setup for Windows, Mac OS, WebGL
In general these platforms should work right out of the box. To avoid problems you should set the flag “Run In Background” in the Player Settings to ensure your network code will keep working even if the application is in the background.
Project setup – Android
Minimum API Level: 4.1 or higher
Android requires your application to request permissions. This can be done via placing an AndroidManifest.xml file in your asset folder at this exact location:
You need at least following permission:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> <uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
Please also read the Unity Documentation for Android permissions. Half of all bug reports lead back to a wrongly configured Manifest file!
Project setup – iOS
- Minimum iOS Version to 9.3 (lower might work but isn’t tested)
- Backend should be IL2CPP
- Make sure to set Camera and Microphone Usage Description. If those fields are empty newer iOS versions will crash once a device is accessed
Building for iOS:
- The script IosPostBuild.cs will automatically change some values in your XCode project e.g. making sure the framework folder is embedded in your project
- only needed for versions below Unity 2017.2: You still need to set a flag by yourself in xcode:
“Project settings -> Build phases -> Copy Frameworks -> set the flag Code Sign On Copy
- Depending on your personal setup you might then still need to setup signing / other unity and ios specific build settings. Please check with Unity and iOS documentation first before requesting support.
Running the examples
The chat app allows a user to create or join a chat room. After entering a room the users can send chat messages to everyone in the room. The user that created the room will act as a server
and relay the messages to all connected users.
To run the example start the scene at: WebRtcNetwork\example\chatscene. The file ChatApp.cs contains
most of the code and is fully documented. Use this example to learn how to use the library to send any data across the network.
Note that the example contains two instances of the ChatApp. This is done so you can test it locally on a single machine. Simply open a room with the one app and then join it with the second. You can also run the example on multiple machines inside your LAN or using two different internet connections and open / join rooms. Internet is always required as long as the default signaling server is used.
The scene at WebRtcVideoChat/callapp/callscene contains two instances of the CallApp allowing you to test the video and audio library within a single application or run the same program on two different systems and connect. It supports streaming audio, video and sending text messges to the other side. Simply enter a shared text or password on both sides and press the join button. Both apps will be connected and start streaming audio and video (if available). Note that if testing on a single system that video devices can only be accessed by a single app at the same time. Using audio to connect locally will cause an echo (make sure your speakers aren’t set to high volume).