2021年5月3日星期一

undefined var , reading top to bottom?

I have the following code;

io.on('connection', function(socket){            socket.emit('message','Hello from FlamingoX server!');      socket.emit('message','Please set the StreamKey before start streaming.');      socket.emit('message','Checking if your Stream Directory Exists; please wait...');          socket.on('config_streamKey',function(e){ if(typeof e != 'string'){ socket.emit('fatal','streamKey ivalid'); return; }                socket._streamKey=e;      socket.emit('message','streamKey destination set to: '+e);      });             socket.on('config_timestamp',function(t){ if(typeof t != 'string'){ socket.emit('fatal','timestamp ivalid'); return; }                          socket._timestamp=t;      socket.emit('message','stream timestamp set: '+t);      });            socket.on('config_date',function(d){ if(typeof d != 'string'){  socket.emit('fatal','timestamp ivalid'); return; }                          socket._date=d;      socket.emit('message','stream date set: '+d);                 });             var filePath = "/var/www/html/replaceDate/replaceKey/";      filePath = filePath.replace("replaceDate", socket._date);      filePath = filePath.replace("replaceKey", socket._streamKey);            socket.emit('message',' '+filePath);    ...  

The output I am getting is as followed;

SERVER:Hello from FlamingoX server!  SERVER:Please set the StreamKey before start streaming.  SERVER:Checking if your Stream Directory Exists; please wait...  SERVER: /var/www/html/undefined/undefined/  SERVER:streamKey destination set to: 1618380585-6666-863686008-4444-21  SERVER:stream timestamp set: 1620100750  SERVER:stream date set: 04-05-2021  

the problem is here SERVER: /var/www/html/undefined/undefined/ ; I would expect if its reading from top to bottom that it should process these socket.on lines before it emits the file path; however its emitting the filepath before doing the if statements and before it has defined the date and streamkey. Please could someone tell me whats going on here, I really appreciate it.

The desired outcome is as followed;

SERVER:Hello from FlamingoX server!  SERVER:Please set the StreamKey before start streaming.  SERVER:Checking if your Stream Directory Exists; please wait...  SERVER:streamKey destination set to: 1618380585-6666-863686008-4444-21  SERVER:stream timestamp set: 1620100750  SERVER:stream date set: 04-05-2021  SERVER: /var/www/html/04-05-2021/1618380585-6666-863686008-4444-21/  

Thanks for any help.

https://stackoverflow.com/questions/67378664/undefined-var-reading-top-to-bottom May 04, 2021 at 12:06PM

没有评论:

发表评论