This repository contains a Unity-based SNES game streaming system with the following components:
- Unity headless game server: Runs and streams an SNES emulator (
Assets/EmuServerfolder) - Unity client application: Connects to the game server, receives the stream, and sends user inputs
- Nakama backend: Handles authentication and matchmaking
- WebApp client: Web interface to connect to the server and play games (separate repository)
| Library | Description | Link |
|---|---|---|
| RetroUnity | SNES emulator wrapper for Unity using libretro | GitHub |
| Nakama | Session data sharing (player inputs and signaling) | GitHub |
| WebRTC | Video and audio streaming | GitHub |
| Zenject | Dependency injection for Unity3D | GitHub |
On a Linux VM, install Docker and npm:
apt update
apt install docker docker-compose npm
mkdir /home/admin/_emuInstall Certbot with Nginx update method:
apt-get install certbot python-certbot-nginx
certbot --nginxGenerate SSL certificates:
letsencrypt certonly -a webroot --webroot-path=/var/www/html -d pranafun.orgYour certificates will be located at:
/etc/letsencrypt/live/pranafun.org/fullchain.pem/etc/letsencrypt/live/pranafun.org/privkey.pem
Copy the launcher-worker folder to /home/admin/_emu/launcher-worker:
cd /home/admin/_emu/launcher-worker
npm install
sudo ./run.shCopy the data-sync folder to /home/admin/_emu/data-sync:
cd /home/admin/_emu/data-sync
cp .env.example .env
# Set new POSTGRES_PASSWORD and NAKAMA_SERVER_KEY values in .env.
sudo docker-compose up -dNever commit .env or other deployment credentials. Set serverKey in
Assets/StreamingAssets/emuConfig.json to the same Nakama key when building
the Unity client. A key distributed in a client is public; enforce access
control on the server rather than relying on this key for authorization.
Provide your own legally redistributable game files locally; ROMs are not
included in the public repository. Update envGameFileName for the file used
by your deployment.
Previously committed PostgreSQL and chatbot passwords and the Nakama key
must be replaced in the running services. With an existing PostgreSQL data
volume, changing POSTGRES_PASSWORD in .env alone does not change the
database role password: rotate the role password in PostgreSQL as well.
The original private repository retains its history; do not make it public.
mkdir /home/admin/_emu/workerZip and copy the build output to the worker folder.
Refer to the arcade-room-js repository to build the dist.zip archive:
mkdir /home/admin/_emu/webapp
cd /home/admin/_emu/webapp
unzip dist.zip
mkdir dist/arcaderoom
cp dist/index.html dist/arcaderoom/index.htmlThe streaming uses the WebRTC library (Google Chromium C++) integrated into a C#/Unity application.
- Compile Chromium: Official Documentation
- Create a target in the Ninja build file to compile files in the
unitypluginfolder - Copy the DLL to the Unity application's
Pluginsfolder
File: Assets/EmuServer/Scripts/Core/LibRetroVideoSource.cs
- The
CaptureFramefunction is scheduled to run at 30 FPS - On first call, a byte array is created and pinned in memory using the C# API, ensuring its reference remains constant during runtime
- Every time a frame is available, data is copied from the libretro Unity texture to the pinned array
File: Assets/EmuServer/Scripts/Workflow/ServerGameWorkflow.cs
- Data is converted from ARGB 16-bit to YUV I420 (native WebRTC format)
- The pointer to the YUV array is sent to the C++ WebRTC API and transmitted over the network
From the WebApp:
- Received frames are automatically displayed on a video canvas
From the Unity App:
- Frames must be converted from YUV to ARGB
- Then applied to the Unity texture
- The receive pipeline can also be handled in a shader (for the texture application part)
Server app components definition : Assets\EmuServer\Scripts\Core\EmuServerInstaller.cs Root Game Workflow ServerGameWorkflow.cs (implementation of the game flow, establish the streaming connection with players, push game video frames to players )
App components definition : Assets\Emur\Scripts\Core\AppInstaller.cs Application services, and view workflows (Menu, Load Game Wait Screen, Game Display)