This guide focuses on the Unity asset WebRTC Video Chat but most also applies to WebRTC Network which is a part of it but is also available separately.
Important folders and files
Please note the structure changed in V0.983.
- scripts/UnityCallFactory.cs – Main access for Networ/Video/Audio call functionality
- chatapp – contains the text only ChatApp example using a star topology
- callapp – contains a fully functional 1-to-1 video chat app
- examples – contains a few simple examples to learn how to use the API
- extras – contains experimental features that are not fully supported
- server.zip – Contains an open source node.js signaling server. More at Server side info / Tutorials
- Contains C# libraries that provide the API
- The subfolders contain wrappers that map the API to platform and processor architecture specific code
- Never move or rename this folder
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.
MacOS – Common problems
If a Unity project is updated from or to versions 2017.02, 2017.03 and higher Unity might fail to properly read its own configuration file for MacOS native plugins. This causes unity to ignore the plugin on builds.
Here is a workaround to let unity rebuild a proper meta file:
Move the folder webrtccsharpwrap.bundle via the finder or bash (not via unity itself it might move its broken meta file as well)
Do not move the webrtccsharpwrap.bundle.meta. You can delete the x64 folder.
After that start unity / switch to the unity window and it should regenerate a properly working meta file.
Minimum API Level: 4.1 or higher
Starting V0.982 the android plugin should work immediately after import without any special setup.
The android specific plugin now comes in .aar format and Unity should be able to automatically merge its AndroidManifest.xml with the one used for your final application. During the first start of the applications unity should request microphone and camera permissions from the user.
This setup is only required for V0.981 and earlier but the information below might also be helpful for debugging purposes.
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!
Android specific behaviour and API
The android version of the asset requires you to ensure that all permissions it needs are granted before use. In some cases multiple plugins or a custom AndroidManifest.xml might interfere with the plugin. To fix issues related to this please read “manual setup” above and check the app permission within the Android settings.
Received audio streams in Android are treated as an incoming call. This means based on the device settings the audio might be unusual quiet (assuming the users hold the device on their ears). To turn on the speaker call UnityCallFactory.Instance.SetLoudspeakerStatus(true). V0.983 and later will switch android into “Communication mode” allowing the audio buttons to control the call volume. You can turn this off via a flag in UnityCallFactory.ANDROID_SET_COMMUNICATION_MODE.
Video devices also behave differently on Android due to their fixed location. An easy way to get the device name of the front facing camera is by using “string GetDefaultVideoDevice()” or by checking a known device via “bool IsFrontFacing(string deviceName)” via UnityCallFactory.Instance. Unlike other platforms Android allows only access to a single video device at a time. External video devices are not supported.
For other android specific methods feel free to check out the file AndroidHelper.cs. It contains calls to the android API for several tasks such as ways to increase, decrease the call audio, changing the audio mode, checking permissions or opening the permission view.
- Minimum iOS Version to 9.3
- 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
- The simulator is not supported. iPad and iPhone are supported
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.
Crash during start. Either “webrtccsharpwrap not found” or a crash during call to “GetVersion()”: This error can have many different reasons. Please see the iOS section of the FAQ
V0.982 only: Not working on old armv7 devices if downloaded via TestFlight or the AppStore: Search for the folder webrtccsharpwrap.framework and open the file Info.plist in xcode. Remove the entry “Required device capabilities” completely
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 who 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).