forked from EpicGamesExt/PixelStreamingInfrastructure
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.bat
More file actions
336 lines (295 loc) · 8.75 KB
/
common.bat
File metadata and controls
336 lines (295 loc) · 8.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@rem Copyright Epic Games, Inc. All Rights Reserved.
@echo off
echo Helper library script. Not to be called directly.
goto :eof
:Init
set SCRIPT_DIR=%~dp0
set /p NODE_VERSION=<"%SCRIPT_DIR%/../../../NODE_VERSION"
set NPM="%SCRIPT_DIR%/node/npm"
set TAR="%SystemRoot%\System32\tar.exe"
set CONTINUE=1
GOTO :eof
:Usage
echo.
echo Usage:
echo %0 [--help] [--publicip ^<IP Address^>] [--turn ^<turn server^>] [--stun ^<stun server^>] [server options...]
echo Where:
echo --help Print this message and stop this script.
echo --publicip Define public ip address (using default port) for turn server, syntax: --publicip ; it is used for
echo Default value: Retrieved from 'curl https://api.ipify.org' or if unsuccessful then set to 127.0.0.1. It is the IP address of the server and the default IP address of the TURN server
echo --turn TURN server to be used, syntax: --turn 127.0.0.1:19303
echo Default value: Retrieved from 'curl https://api.ipify.org' or if unsuccessful then set to 127.0.0.1.
echo --turn-user Sets the turn username when using a turn server.
echo --turn-pass Sets the turn password when using a turn server.
echo --start-turn Will launch the turnserver process.
echo --stun STUN server to be used, syntax: --stun stun.l.google.com:19302
echo Default value: stun.l.google.com:19302
echo --frontend-dir Sets the output path for the fontend build
echo --build Force a rebuild of the typescript frontend even if it already exists
echo --rebuild Force a rebuild of everything
echo --build-libraries Force a rebuild of shared libraries
echo --build-wilbur Force build of wilbur
echo --deps Force reinstall of dependencies
echo Other options: stored and passed to the server.
IF exist "%SCRIPT_DIR%..\..\dist" (
pushd %SCRIPT_DIR%..\..
call %NPM% run start --- --help
popd
)
set CONTINUE=0
exit /b
:ParseArgs
set BUILD_LIBRARIES=0
set BUILD_WILBUR=0
set BUILD_FRONTEND=0
set START_TURN=0
set SERVER_ARGS=
set FRONTEND_DIR=
set TURN_SERVER=
set TURN_USER=
set TURN_PASS=
set STUN_SERVER=
set PUBLIC_IP=
:arg_loop
IF NOT "%1"=="" (
set HANDLED=0
IF "%1"=="--help" (
CALL :Usage
exit /b
)
IF "%1"=="--publicip" (
set HANDLED=1
set PUBLIC_IP=%2
SHIFT
)
IF "%1"=="--turn" (
set HANDLED=1
set TURN_SERVER=%2
SHIFT
)
IF "%1"=="--turn-user" (
set HANDLED=1
set TURN_USER=1
)
IF "%1"=="--turn-pass" (
set HANDLED=1
set TURN_PASS=1
)
if "%1"=="--start-turn" (
set HANDLED=1
set START_TURN=1
)
IF "%1"=="--stun" (
set HANDLED=1
set STUN_SERVER=%2
SHIFT
)
IF "%1"=="--frontend-dir" (
set HANDLED=1
set FRONTEND_DIR=%~2
SHIFT
)
IF "%1"=="--build" (
set HANDLED=1
set BUILD_FRONTEND=1
)
IF "%1"=="--rebuild" (
set HANDLED=1
set BUILD_LIBRARIES=1
set BUILD_FRONTEND=1
set BUILD_WILBUR=1
)
IF "%1"=="--build-libraries" (
set HANDLED=1
set BUILD_LIBRARIES=1
)
IF "%1"=="--build-wilbur" (
set HANDLED=1
set BUILD_WILBUR=1
)
IF "%1"=="--deps" (
set HANDLED=1
set INSTALL_DEPS=1
)
IF NOT "!HANDLED!"=="1" (
set SERVER_ARGS=%SERVER_ARGS% %1
)
SHIFT
GOTO :arg_loop
)
exit /b
:SetupNode
pushd %SCRIPT_DIR%
SET NODE_NAME=node-%NODE_VERSION%-win-x64
if exist node\ (
echo Node directory found...skipping install.
) else (
echo Node directory not found...beginning NodeJS download for Windows.
rem Download nodejs and follow redirects.
curl -L -o ./node.zip "https://nodejs.org/dist/%NODE_VERSION%/%NODE_NAME%.zip"
%TAR% -xf node.zip
ren "%NODE_NAME%\" "node"
del node.zip
set INSTALL_DEPS=1
)
rem NOTE: We want to use our NodeJS (not system NodeJS!) to build the web frontend files.
rem Save our current directory (the NodeJS dir) in a variable
set NODE_DIR=%SCRIPT_DIR%node
set PATH=%NODE_DIR%;%PATH%
rem Print node version
FOR /f %%A IN ('node.exe -v') DO set NODE_VERSION=%%A
echo Node version: %NODE_VERSION%
popd
if "%INSTALL_DEPS%"=="1" (
echo Installing dependencies...
pushd %SCRIPT_DIR%..\..\..
call %NPM% install
popd
)
exit /b
:SetupLibraries
if "%BUILD_LIBRARIES%"=="1" (
set BUILD_COMMON=1
set BUILD_SIGNALLING=1
)
if NOT exist "%SCRIPT_DIR%..\..\..\Common\dist" (
set BUILD_COMMON=1
)
if NOT exist "%SCRIPT_DIR%..\..\..\Signalling\dist" (
set BUILD_SIGNALLING=1
)
IF "%BUILD_COMMON%"=="1" (
pushd %SCRIPT_DIR%..\..\..\Common
echo Building common library
call %NPM% run build:cjs
popd
)
IF "%BUILD_SIGNALLING%"=="1" (
pushd %SCRIPT_DIR%..\..\..\Signalling
echo Building signalling library
call %NPM% run build:cjs
popd
)
exit /b
:SetupFrontend
rem Start in the repo dir
pushd %SCRIPT_DIR%..\..\..\
IF "%FRONTEND_DIR%"=="" (
set FRONTEND_DIR="%SCRIPT_DIR%..\..\www"
) else (
set FRONTEND_DIR="%FRONTEND_DIR%"
)
rem try to make it an absolute path
call :NormalizePath %FRONTEND_DIR%
set FRONTEND_DIR=%RETVAL%
rem Set this for webpack
set WEBPACK_OUTPUT_PATH=%FRONTEND_DIR%
IF NOT exist "%FRONTEND_DIR%" (
set BUILD_FRONTEND=1
)
IF "%BUILD_FRONTEND%"=="1" (
rem We could replace this all with a single npm script that does all this. we do have several build-all scripts already
rem but this does give a good reference about the dependency chain for all of this.
echo Building Typescript frontend...
pushd %CD%\Frontend\library
call %NPM% run build:cjs
popd
pushd %CD%\Frontend\ui-library
call %NPM% run build:cjs
popd
pushd %CD%\Frontend\implementations\typescript
call %NPM% run build:dev
popd
popd
) else (
echo Skipping rebuilding frontend... %FRONTEND_DIR% has content already, use --build to force a frontend rebuild.
)
exit /b
:SetupCoturn
@Rem Look for CoTURN directory next to this script
pushd %SCRIPT_DIR%
if exist coturn\ (
echo CoTURN directory found...skipping install.
) else (
echo CoTURN directory not found...beginning CoTURN download for Windows.
@Rem Download nodejs and follow redirects.
curl -L -o ./turnserver.zip "https://github.com/EpicGamesExt/PixelStreamingInfrastructure/releases/download/v4.5.2-coturn-windows/turnserver.zip"
@Rem Unarchive the .zip to a directory called "turnserver"
mkdir coturn & %TAR% -xf turnserver.zip -C coturn
@Rem Delete the downloaded turnserver.zip
del turnserver.zip
)
popd
goto :eof
:Setup
echo Checking Pixel Streaming Server dependencies
call :SetupNode
call :SetupLibraries
call :SetupFrontend
call :SetupCoturn
exit /b
:SetPublicIP
FOR /f %%A IN ('curl --silent http://api.ipify.org') DO set PUBLIC_IP=%%A
Echo External IP is : %PUBLIC_IP%
exit /b
:SetupTurnStun
IF "%TURN_SERVER%"=="" (
set TURN_SERVER=%PUBLIC_IP%:19303
set TURN_USER=PixelStreamingUser
set TURN_PASS=AnotherTURNintheroad
)
IF "%STUN_SERVER%"=="" (
set STUN_SERVER=stun.l.google.com:19302
)
rem Ping own computer name to get local IP
FOR /F "delims=[] tokens=2" %%A in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set LOCAL_IP=%%A
FOR /F "tokens=1,2 delims=:" %%i in ("%TURN_SERVER%") do (
set TURN_PORT=%%j
)
IF "%TURN_PORT%"=="" ( set TURN_PORT=3478 )
set TURN_PROCESS=turnserver.exe
set TURN_REALM=PixelStreaming
set TURN_ARGS=-c ..\..\..\turnserver.conf --allowed-peer-ip=%LOCAL_IP% -p %TURN_PORT% -r %TURN_REALM% -X %PUBLIC_IP% -E %LOCAL_IP% -L %LOCAL_IP% --no-cli --no-tls --no-dtls --pidfile `"C:\coturn.pid`" -f -a -v -u %TURN_USER%:%TURN_PASS%
if "%START_TURN%"=="1" (
IF NOT "%TURN_SERVER%"=="" (
IF NOT "%TURN_USER%"=="" (
IF NOT "%TURN_PASS%"=="" (
pushd %SCRIPT_DIR%coturn\
IF "%1"=="bg" (
start "%TURN_PROCESS%" %TURN_PROCESS% %TURN_ARGS%
) else (
call "%TURN_PROCESS%" %TURN_ARGS%
)
popd
)
)
)
)
exit /b
:PrintConfig
echo.
echo Running with config:
echo Public IP address : %PUBLIC_IP%
IF NOT "%STUN_SERVER%"=="" ( echo STUN_SERVER : %STUN_SERVER% )
IF NOT "%TURN_SERVER%"=="" ( echo TURN_SERVER : %TURN_SERVER% )
echo Server command line arguments: %SERVER_ARGS%
echo.
exit /b
:BuildWilbur
IF NOT exist "%SCRIPT_DIR%..\..\dist" (
set BUILD_WILBUR=1
)
IF "%BUILD_WILBUR%"=="1" (
pushd %SCRIPT_DIR%\..\..\
echo Building wilbur...
call %NPM% run build
popd
)
exit /b
:StartWilbur
pushd %SCRIPT_DIR%\..\..\
call %NPM% run start -- %SERVER_ARGS%
exit /b
:NormalizePath
set RETVAL=%~f1
exit /b