File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " emulatorjs-netplay-server" ,
33 "productName" : " EmulatorJS Netplay Server" ,
4- "version" : " 0.3.9 " ,
4+ "version" : " 0.4.0 " ,
55 "main" : " app.js" ,
66 "bin" : " server.js" ,
77 "description" : " A Netplay Server For EmulatorJS" ,
Original file line number Diff line number Diff line change @@ -37,6 +37,16 @@ function startserver() {
3737 res . sendStatus ( 401 )
3838 }
3939 } ) ;
40+ app . post ( '/status' , ( req , res ) => {
41+ const reject = ( ) => {
42+ res . setHeader ( 'www-authenticate' , 'Basic' )
43+ res . sendStatus ( 401 )
44+ }
45+ if ( ! checkAuth ( req . headers . authorization , password ) ) {
46+ return reject ( ) ;
47+ }
48+ res . end ( '{ "port": ' + port + ', "password": "' + password + '", "nofusers": ' + nofusers + ' }' ) ;
49+ } ) ;
4050 server . listen ( port || 3000 , '0.0.0.0' , ( ) => {
4151 consolelog ( "Starting server on port " + ( port || 3000 ) + " with password " + password ) ;
4252 if ( appserver ) {
Original file line number Diff line number Diff line change 108108 < div id ="content " class ="content ">
109109 < h1 > EmulatorJS Netplay Server</ h1 >
110110 < img src ="img/logo-light.png " alt ="Logo " class ="logo ">
111- < h3 > Server Info:</ h3 >
112- < p > Runing on port: < b > 3000</ b > </ p >
113- < p > Password is: < b > admin123</ b > </ p >
111+ < p id ="info "> Server info</ p >
114112 < h3 > Server Options:</ h3 >
115113 < button onclick ="startbutton() " id ="server " class ="button "> Start Server</ button >
116- < button onclick ="changeport() " id ="port " class ="button "> Change Port</ button >
117114 < p id ="status "> </ p >
118115 < p id ="nuser "> </ p >
119116 < br >
@@ -137,6 +134,26 @@ <h3>Server Options:</h3>
137134 } , 2000 ) ;
138135 } ) ;
139136
137+ ( function ( ) {
138+ status ( ) . then ( info => {
139+ document . getElementById ( 'info' ) . innerHTML = "Running server on port " + ( info . port || 3000 ) + " with password " + info . password ;
140+ } ) ;
141+ document . getElementById ( 'urls' ) . innerHTML = '<li><a href="' + window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/" target="_blank" onclick="window.api.openExternal(this.href);event.preventDefault()">' + window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/</a></li>' ;
142+ } ) ( ) ;
143+
144+ function status ( ) {
145+ return fetch ( '/status' , {
146+ method : 'POST' ,
147+ headers : {
148+ 'Content-Type' : 'application/json'
149+ }
150+ } )
151+ . then ( response => response . json ( ) )
152+ . then ( data => {
153+ return data ;
154+ } ) ;
155+ }
156+
140157 var startstop = document . getElementById ( 'startStop' ) ;
141158 function startbutton ( ) {
142159 if ( startstop . textContent === 'Start' ) {
@@ -176,10 +193,6 @@ <h3>Server Options:</h3>
176193 update ( ) ;
177194 } ) ;
178195 }
179- ( function ( ) {
180- check ( ) ;
181- document . getElementById ( 'urls' ) . innerHTML = '<li><a href="' + window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/" target="_blank" onclick="window.api.openExternal(this.href);event.preventDefault()">' + window . location . protocol + "//" + window . location . hostname + ':' + window . location . port + '/</a></li>' ;
182- } ) ( ) ;
183196 function startstopserver ( option ) {
184197 fetch ( '/startstop' , {
185198 method : 'POST' ,
You can’t perform that action at this time.
0 commit comments