lkollar / aircast

AirCast - Stream AirPlay audio to Chromecast devices
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

BufferedStream not closed when a client disconnects #3

Open lkollar opened 8 years ago

lkollar commented 8 years ago

This causes a crash when the next clients start playback:

/home/lkollar/aircast/node_modules/bufferedstream/index.js:27
      throw new Error('BufferedStream is already piped');
      ^

Error: BufferedStream is already piped
    at BufferedStream.<anonymous> (/home/lkollar/aircast/node_modules/bufferedstream/index.js:27:13)
    at emitOne (events.js:77:13)
    at BufferedStream.emit (events.js:169:7)
    at OutputStream.Readable.pipe (/home/lkollar/aircast/node_modules/readable-stream/lib/_stream_readable.js:635:8)
    at null.<anonymous> (/home/lkollar/aircast/index.js:159:16)
    at emitOne (events.js:77:13)
    at NodeTunes.emit (events.js:169:7)
    at announceParse (/home/lkollar/aircast/node_modules/nodetunes/lib/rtspmethods.js:141:25)
    at announce (/home/lkollar/aircast/node_modules/nodetunes/lib/rtspmethods.js:81:7)
    at RtspServer.<anonymous> (/home/lkollar/aircast/node_modules/nodetunes/lib/rtsp.js:60:7)
    at emitTwo (events.js:87:13)
    at ServerParser.emit (events.js:172:7)
    at ServerParser._emitMessage (/home/lkollar/aircast/node_modules/httplike/lib/server-parser.js:28:8)
    at ServerParser.Parser._write (/home/lkollar/aircast/node_modules/httplike/lib/parser.js:103:12)
    at doWrite (_stream_writable.js:292:12)
lkollar commented 8 years ago

I haven't looked into this in detail but I think what's happening is that when a new client connects (or the same client reconnects) the buffer cannot be reused. One simple solution is to create the buffer on a new connection only and close it on disconnect. I'm not sure we can get a disconnect event from airtunes, have to look into that.