|
1 | | -# EmulatorJS Netplay Server |
| 1 | +# Running Your Own Netplay Server |
2 | 2 |
|
3 | | -Working netplay server for https://github.com/EmulatorJS/emulatorJS |
| 3 | +This guide explains how to run the Netplay server designed specifically for Emulatorjs.org |
4 | 4 |
|
5 | | -Instructions on how to set up with EmulatorJS are located [here](https://emulatorjs.org/docs4devs/Netplay.html) |
| 5 | +--- |
6 | 6 |
|
7 | | -Bugs may exist - open an [issue](https://github.com/EmulatorJS/EmulatorJS-Netplay/issues) if you find one |
| 7 | +## 1. Prerequisites |
8 | 8 |
|
9 | | -Supports: |
10 | | -* [Windows](#windows) |
11 | | -* [Linux](#linux) |
12 | | -* [Docker](#docker) |
13 | | -* [Docker Compose](#docker-compose) |
| 9 | +Before you begin, ensure you have the following installed on your system: |
14 | 10 |
|
15 | | -Development instructions are located [here](#development) |
| 11 | +- **Node.js** (v16 or later recommended) |
| 12 | + 👉 [Download Node.js](https://nodejs.org/) |
16 | 13 |
|
17 | | -Configurating the server is located [here](#configurating-the-server) |
| 14 | +- **npm** (comes with Node.js) or **yarn** package manager |
18 | 15 |
|
19 | | -Building instructions are located [here](#building) |
| 16 | +- **Git** |
| 17 | + 👉 [Download Git](https://git-scm.com/) |
20 | 18 |
|
21 | | -License is located [here](#license) |
| 19 | +--- |
22 | 20 |
|
23 | | -## To use: |
| 21 | +## 2. Clone the Repository |
24 | 22 |
|
25 | | -### Windows: |
| 23 | +```bash |
| 24 | +git clone https://github.com/EmulatorJS/EmulatorJS-Netplay |
| 25 | +cd EmulatorJS-Netplay |
| 26 | +``` |
| 27 | + |
| 28 | +--- |
26 | 29 |
|
27 | | -Go to the releases tab and download the [latest release](https://github.com/EmulatorJS/EmulatorJS-Netplay/releases/tag/latest) for windows and open the exe file. |
| 30 | +## 3. Install Dependencies |
28 | 31 |
|
29 | | -The GUI version is recommended for most users. |
| 32 | +The `server.js` file depends on a few Node.js packages: |
30 | 33 |
|
31 | | -You can also download the source code and run `npm i` to install packages and then `npm start` to start the server. |
| 34 | +- `express` |
| 35 | +- `socket.io` |
| 36 | +- `cors` |
32 | 37 |
|
33 | | -### Linux: |
| 38 | +Install them using **npm**: |
34 | 39 |
|
35 | | -Go to the releases tab and download the [latest release](https://github.com/EmulatorJS/EmulatorJS-Netplay/releases/tag/latest) for linux and open the AppImage file (you may need to make it executable). |
| 40 | +```bash |
| 41 | +npm install express socket.io cors |
| 42 | +``` |
36 | 43 |
|
37 | | -The AppImage version is recommended for most users. |
| 44 | +Or using **yarn**: |
38 | 45 |
|
39 | | -You can also download the source code and run `npm i` to install packages and then `npm start` to start the server. |
| 46 | +```bash |
| 47 | +yarn add express socket.io cors |
| 48 | +``` |
40 | 49 |
|
41 | | -### Docker: |
| 50 | +--- |
42 | 51 |
|
43 | | -You can also use docker to run the server this is recomended for production use you can also follow [these](#development) steps for a server. |
| 52 | +## 4. Run the Server |
44 | 53 |
|
45 | | -Download the docker image: |
46 | | -``` |
47 | | -docker pull ghcr.io/emulatorjs/emulatorjs-netplay/emulatorjs-netplay-server:latest |
48 | | -``` |
49 | | -Run the docker image: |
| 54 | +To start the server: |
| 55 | + |
| 56 | +```bash |
| 57 | +node server.js |
50 | 58 | ``` |
51 | | -docker run -p 3000:3000 -e NETPLAY_PASSWORD=admin123 -e NETPLAY_PORT=3000 -e NETPLAY_DEV=false ghcr.io/emulatorjs/emulatorjs-netplay/emulatorjs-netplay-server:latest |
| 59 | + |
| 60 | +If you want to run it in development mode with auto-restart on file changes, install `nodemon`: |
| 61 | + |
| 62 | +```bash |
| 63 | +npm install -g nodemon |
| 64 | +nodemon server.js |
52 | 65 | ``` |
53 | 66 |
|
54 | | -### Docker Compose: |
| 67 | +--- |
55 | 68 |
|
56 | | -To run the server with docker compose you can use this docker-compose.yml file: |
| 69 | +## 5. Access the Server |
57 | 70 |
|
58 | | -``` |
59 | | -version: "3.9" |
60 | | -services: |
61 | | - emulatorjs-netplay-server: |
62 | | - image: ghcr.io/emulatorjs/emulatorjs-netplay/emulatorjs-netplay-server:latest |
63 | | - ports: |
64 | | - - 3000:3000 |
65 | | - environment: |
66 | | - - NETPLAY_PASSWORD=admin123 |
67 | | - - NETPLAY_PORT=3000 |
68 | | - - NETPLAY_DEV=false |
69 | | -``` |
| 71 | +By default, the server runs on: |
70 | 72 |
|
71 | | -Then run: |
72 | 73 | ``` |
73 | | -docker-compose up |
| 74 | +http://localhost:3000 |
74 | 75 | ``` |
75 | 76 |
|
76 | | -### Development: |
| 77 | +If you want to change the port, set the `PORT` environment variable. |
77 | 78 |
|
78 | | -Clone the repo: |
| 79 | +**Linux / macOS (bash / zsh):** |
79 | 80 |
|
80 | | -``` |
81 | | -git clone https://github.com/EmulatorJS/EmulatorJS-Netplay.git |
| 81 | +```bash |
| 82 | +PORT=4000 node server.js |
82 | 83 | ``` |
83 | 84 |
|
84 | | -Install packages: |
85 | | -``` |
86 | | -npm i |
87 | | -``` |
88 | | -Start the server: |
89 | | -``` |
90 | | -npm start |
91 | | -``` |
92 | | -You can also use the flags `-p` for port and `-a` for password: |
93 | | -``` |
94 | | -npm start -- -p 8080 -a admin |
95 | | -``` |
96 | | -You can add the flag `-d` to run the server in dev mode. |
97 | | -``` |
98 | | -npm start -- -p 3000 -a admindev -d |
| 85 | +**Windows PowerShell:** |
| 86 | + |
| 87 | +```powershell |
| 88 | +$env:PORT=4000; node server.js |
99 | 89 | ``` |
100 | | -You can also run the dev version with: |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## 6. Test Endpoints |
| 94 | + |
| 95 | +### List Available Rooms |
| 96 | + |
| 97 | +The server provides a REST endpoint: |
| 98 | + |
101 | 99 | ``` |
102 | | -npm run dev |
| 100 | +GET /list?game_id=<gameId> |
103 | 101 | ``` |
104 | | -You can run the GUI version with: |
| 102 | + |
| 103 | +Example: |
| 104 | + |
105 | 105 | ``` |
106 | | -npm run app |
| 106 | +http://localhost:3000/list?game_id=123 |
107 | 107 | ``` |
108 | | -You can run the help with the flag `-h` |
109 | 108 |
|
110 | | -## Configurating the server |
| 109 | +This returns a JSON list of available rooms for the given game ID. |
| 110 | + |
| 111 | +### WebSocket Features |
| 112 | + |
| 113 | +Clients can connect via **Socket.IO** to: |
| 114 | + |
| 115 | +- Open rooms (`open-room`) |
| 116 | +- Join rooms (`join-room`) |
| 117 | +- Leave rooms (`leave-room`) |
| 118 | +- Exchange WebRTC signals (`webrtc-signal`) |
| 119 | +- Send messages (`data-message`, `snapshot`, `input`) |
| 120 | +- Receive updates when users join/leave (`users-updated`) |
| 121 | + |
| 122 | +--- |
111 | 123 |
|
112 | | -Notes: |
113 | | -* Changing the password is recommended. |
| 124 | +## 7. (Optional) Run in Background with PM2 |
114 | 125 |
|
115 | | -Config priority: |
116 | | -* Flags |
117 | | -* Environment variables |
118 | | -* Config file |
| 126 | +For production, use **PM2** to keep the server running in the background. |
119 | 127 |
|
120 | | -**Editing the password:** |
| 128 | +Install PM2 globally: |
121 | 129 |
|
122 | | -The username is `admin` and the defalt password is `admin123` you can change the password in the *config.json* `password` value. |
| 130 | +```bash |
| 131 | +npm install -g pm2 |
| 132 | +``` |
| 133 | + |
| 134 | +Start the server with a name: |
| 135 | + |
| 136 | +```bash |
| 137 | +pm2 start server.js --name my-server |
| 138 | +``` |
| 139 | + |
| 140 | +View logs: |
123 | 141 |
|
124 | | -```json |
125 | | -{ |
126 | | - "password" : "admin123" |
127 | | -} |
| 142 | +```bash |
| 143 | +pm2 logs my-server |
128 | 144 | ``` |
129 | | -You can also change the password by setting environment variable `NETPLAY_PASSWORD` to the password you want to use. |
130 | 145 |
|
131 | | -**Editing the port:** |
| 146 | +Restart the server: |
132 | 147 |
|
133 | | -The default port is `3000` you can change the port in the *config.json* `port` value. |
| 148 | +```bash |
| 149 | +pm2 restart my-server |
| 150 | +``` |
| 151 | + |
| 152 | +Stop the server: |
134 | 153 |
|
135 | | -```json |
136 | | -{ |
137 | | - "port" : 3000 |
138 | | -} |
| 154 | +```bash |
| 155 | +pm2 stop my-server |
139 | 156 | ``` |
140 | | -You can also change the port by setting environment variable `NETPLAY_PORT` to the port you want to use. |
141 | 157 |
|
142 | | -**Running in dev mode:** |
| 158 | +--- |
| 159 | + |
| 160 | +## 8. (Optional) Keep Server Running After Reboot |
143 | 161 |
|
144 | | -You can run the server in dev mode by setting the `dev` value to `true` in the *config.json* file. |
| 162 | +To make PM2 auto-start after reboot: |
145 | 163 |
|
146 | | -```json |
147 | | -{ |
148 | | - "dev" : true |
149 | | -} |
| 164 | +```bash |
| 165 | +pm2 startup |
150 | 166 | ``` |
151 | | -You can also run the server in dev mode by setting the environment variable `NETPLAY_DEV` to `true`. |
152 | 167 |
|
153 | | -### Building |
| 168 | +Follow the instructions it gives you, then save the current process list: |
| 169 | + |
| 170 | +```bash |
| 171 | +pm2 save |
| 172 | +``` |
154 | 173 |
|
155 | | -You can build: |
156 | | -* Windows: `npm run build-win` |
157 | | -* Linux: `npm run build-linux` |
158 | | -* Docker: `npm run build-docker` |
159 | | -# LICENSE |
| 174 | +--- |
160 | 175 |
|
161 | | -Licenced under the Apache License 2.0 |
| 176 | +## ✅ Done |
162 | 177 |
|
163 | | -Read the whole license [here](LICENSE) |
| 178 | +You now have the server running locally! |
| 179 | + |
| 180 | +- For **production**, use PM2 to keep it running and restart automatically. |
0 commit comments