JoJoBond / 3LAS

Low Latency Live Audio Streaming
GNU General Public License v2.0
90 stars 23 forks source link

Failing when page is refreshed after initially playing #16

Closed StillTravelling closed 3 years ago

StillTravelling commented 3 years ago

Steps:

Run the server Start Playing, Refresh the page

The server then prints an error message to the console:

events.js
throw er; Unhandled 'error' event

Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:200:27)....

Essentially it is failing when the websocket disconnects after it is played. So I need to rerun the server after it disconnects. Ideally it would keep running. I would try and fix it myself but unsure how.

From what I've seen from other websocket uses in nodeJS...

const Websocket = require('ws');
const wss = new WebSocket.Server({ port: 9999});

wss.on('connection, function(ws){ 
ws.on('close', console.log('disconnected');) 
});

whereas in 3las.stdinstreamer.js:

this.Server.on('connection', this.OnServerConnection.bind(this));

I think something like this might handle the error when dealing with a specific client? Currently there is no code to deal with any disconnections. I don't know how the "this" would carry into the function.

Sorry if this doesn't make any sense!!

JoJoBond commented 3 years ago

Does the server stop/crash or does it continue?

StillTravelling commented 3 years ago

The server crashes and I have to rerun the batch file.

JoJoBond commented 3 years ago

I suspect it is due to a newer version of the 'ws' library. I will investigate.

StillTravelling commented 3 years ago

Thank you, just for clarity, here is the command..

ffmpeg -re -rtbufsize 256k -f dshow -i audio="Hi-Fi Cable Output (VB-Audio Hi-Fi Cable)" -acodec libmp3lame -b:a 320k -ac 2 -reservoir 0 -f mp3 -write_xing 0 -id3v2_version 0 -fflags +nobuffer -flush_packets 1 - | node 3las.stdinstreamer.js -port 9601 -type mpeg

and the output once the page has refreshed after it has been initially played:

Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, dshow, from 'audio=Hi-Fi Cable Output (VB-Audio Hi-Fi Cable)':
  Duration: N/A, start: 442087.740000, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'pipe:':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p, 320 kb/s
    Metadata:
      encoder         : Lavc58.91.100 libmp3lame
events.js:200kB time=00:00:28.93 bitrate= 320.3kbits/s speed=   1x
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:200:27)
Emitted 'error' event on WebSocket instance at:
    at WebSocket.finalize (C:\Users\stuar\AppData\Roaming\npm\node_modules\ws\lib\WebSocket.js:182:41)
    at Socket.emit (events.js:223:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:21) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}
av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument
size=    1132kB time=00:00:28.96 bitrate= 320.0kbits/s speed=0.998x
video:0kB audio:1133kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!
Press any key to continue . . .
JoJoBond commented 3 years ago

Can you tell what browser you are using and what version of node.js as well as the 'ws' library?

JoJoBond commented 3 years ago

Never mind the issues seems similar to this: https://github.com/websockets/ws/issues/1256 . Please see if commit a89ec46a74aef1628ff1a069748459ea73919fc0 fixes the issue.

StillTravelling commented 3 years ago

That is epic, thank you so much! I can confirm the commit has fixed the issue.