
SimpleWebRTC is a Unity-based WebRTC wrapper that facilitates peer-to-peer audio, video, and data communication over WebRTC using Unitys WebRTC package and websockets.SimpleWebRTC is a Unity-based WebRTC wrapper that facilitates peer-to-peer audio, video, and data communication over WebRTC using Unitys WebRTC package https://docs.unity3d.com/Packages/com.unity.webrtc@3.0/manual/index.html. It leverages WebSockets for signaling and supports both video and audio streaming.A tutorial YouTube video can be found here: https://www.youtube.com/watch?v=-CwJTgt_Z3MSimple InstallationMake sure, that the required dependencies are installed (TextMeshPro, Unity WebRTC, NativeWebSocket (https://github.com/endel/NativeWebSocket)).Go to the Unity AssetStore page: https://assetstore.unity.com/packages/slug/309727Install the package via Unity AssetStore.Installation using the releases pageGot to the releases page and download the latest release from https://github.com/FireDragonGameStudio/SimpleWebRTC/releasesMake sure, that the required dependencies are installed (TextMeshPro, Unity WebRTC, NativeWebSocket (https://github.com/endel/NativeWebSocket)).Import the package into your Unity project.Installation using Unity Package ManagerCreate a new Unity projectOpen the Package Manager, click on the + sign in the upper left/right cornerSelect "Add package from git URL"Enter URL: https://github.com/endel/NativeWebSocket.git#upm and click in InstallAfter the installation finished, click on the + sign in the upper left/right corner againEnter URL https://github.com/FireDragonGameStudio/SimpleWebRTC.git?path=/Assets/SimpleWebRTC#upm and click on InstallManual InstallationClone the repository: git clone https://github.com/FireDragonGameStudio/SimpleWebRTCOpen the Unity project in the Unity Editor.Ensure that the required dependencies (such as TextMeshPro, Unity WebRTC and NativeWebSocket) are installed.Usage of WebRTCConnection ComponentThe WebRTCConnection component manages the WebRTC connection and can be attached to a GameObject in Unity.Following sample scenes are included in the pacakge:WebSocket-TestConnection: For testing the wecksocket connection separately.WebRTC-SingleClient-STUNConnection: Testing STUN connection for a single client. Works standalone and can be deployed to clients. Make sure to set the LocalPeerId for each client individually.WebRTC-SingleClient-wLobby-STUNConnection: A simple Lobby example for handling multiple STUN WebRTC clients. SimpleLobbyManager.cs shows an example, how to use SimpleWebRTC via C#.WebRTC-MultipleClients-STUNConnection: Shows how multiple clients can be connected via peer-to-peer connections and share data, video and audio transmissions.WebRTC-SingleClient-STUNConnection-PhotonFusion: Testing STUN connection for a single client. Works standalone and can be deployed to clients. Make sure to set the LocalPeerId for each client individually.Photon Fusion 2 IntegrationInstall Photon Fusion 2 from Unity AssetStore -> Photon Fusion 2Import the Photon Fusion sample scene via Unity Package Manager.Use the _Generic scripts and PhotonSignalServer to setup the WebRTC connection.A tutorial/explanation YouTube video can be found here: https://www.youtube.com/watch?v=z1F_cqfdU6oWebRTC Web ClientMake sure your WebSocket signaling server is reachable, up and running.Checkout the SimpleWebRTC Web ClientRun npm install in the web client directory, to get everything readyStart the web client either locally (npm run dev or npx vite) or deploy it to a webspace(Optional) Start your Unity application and make sure the WebRTC logic is up and running.Connect all clients to your WebSocket signaling server and wait until the signaling procedure is completed.Stream your video, audio and/or data to every connected client.Example codeWebRTCConnection connection = gameObject.GetComponent();connection.Connect(); // Establish WebSocket connection// after a WebRTC peer-to-peer connection is establishedconnection.StartVideoTransmission(); // Begin video streamingconnection.SendDataChannelMessage("Hello Peer!"); // Send a message over the data channelFor further information check https://github.com/FireDragonGameStudio/SimpleWebRTCWebRTC peer-to-peer connection managementWebSocket-based signalingVideo and audio streamingData channel communicationLogging and debugging toolsPhoton Fusion 2 IntegrationStreaming to web via SimpleWebRTC web client