Skip to content

About

Unity-based emulation streaming server and Nakama backend (source only, no game ROMs)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Emulation Streaming Server

Description

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/EmuServer folder)
  • 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)

Unity Dependencies

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

Installation

Prerequisites

On a Linux VM, install Docker and npm:

apt update
apt install docker docker-compose npm
mkdir /home/admin/_emu

1. SSL Certificates (Let's Encrypt)

Install Certbot with Nginx update method:

apt-get install certbot python-certbot-nginx
certbot --nginx

Generate SSL certificates:

letsencrypt certonly -a webroot --webroot-path=/var/www/html -d pranafun.org

Your certificates will be located at:

  • /etc/letsencrypt/live/pranafun.org/fullchain.pem
  • /etc/letsencrypt/live/pranafun.org/privkey.pem

2. Launcher Installation

Copy the launcher-worker folder to /home/admin/_emu/launcher-worker:

cd /home/admin/_emu/launcher-worker
npm install
sudo ./run.sh

3. Multiplayer Data Synchronization Server Installation

Copy 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 -d

Never 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.

4. Unity Headless Game Server Installation

mkdir /home/admin/_emu/worker

Zip and copy the build output to the worker folder.

5. WebApp Installation

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.html

Streaming Format Details

WebRTC Streaming Pipeline Architecture

The streaming uses the WebRTC library (Google Chromium C++) integrated into a C#/Unity application.

1. Native DLL Creation

  • Compile Chromium: Official Documentation
  • Create a target in the Ninja build file to compile files in the unityplugin folder
  • Copy the DLL to the Unity application's Plugins folder

2. Send Frames Pipeline

File: Assets/EmuServer/Scripts/Core/LibRetroVideoSource.cs

  • The CaptureFrame function 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

3. Receive Frames Pipeline

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)

Game Server Application initialisation (using Dependency Injection)

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 )

Unity client Dependency Injection (using Dependency Injection)

App components definition : Assets\Emur\Scripts\Core\AppInstaller.cs Application services, and view workflows (Menu, Load Game Wait Screen, Game Display)

About

Unity-based emulation streaming server and Nakama backend (source only, no game ROMs)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages