openstf / ios-minicap

iOS Minicap provides a socket interface for streaming realtime screen capture data out of iOS devices.
Other
434 stars 130 forks source link

Example-Server crashes when client leaves page #28

Open software2000 opened 7 years ago

software2000 commented 7 years ago

Hey everyone,

everytime a client leaves the example webpage, app.js crashes.

console output:

` Listening on port 9002 Got a client Lost a client /Users/user/Desktop/ios-minicap-master/example/node_modules/ws/lib/WebSocket.js:219 else throw new Error('not opened'); ^

Error: not opened at WebSocket.send (/Users/user/Desktop/ios-minicap-master/example/node_modules/ws/lib/WebSocket.js:219:16) at Parser.onFrameAvailable (/Users/user/Desktop/ios-minicap-master/example/app.js:43:8) at Parser.parse (/Users/user/Desktop/ios-minicap-master/example/nodemodules/minicap/lib/parser.js:33:34) at Socket.tryParse (/Users/user/Desktop/ios-minicap-master/example/app.js:56:14) at emitNone (events.js:86:13) at Socket.emit (events.js:185:7) at emitReadable (_stream_readable.js:432:10) at emitReadable (_stream_readable.js:426:7) at readableAddChunk (_stream_readable.js:187:13) at Socket.Readable.push (_stream_readable.js:134:10)`

sorccu commented 7 years ago

Haven't seen that before, but really, it's just a minimal example. You're supposed to make your own.

sorccu commented 7 years ago

You should check ws.readyState (or use some other flag variable, or tear down instantly) in the onFrameAvailable callback.

vbanthia-zz commented 7 years ago

It does crashes. Quick workaorund will be to use android-minicap example with some changes such as port number etc, https://github.com/openstf/minicap/tree/master/example

software2000 commented 7 years ago

Solution: Just add stream.destroy() to ws.on('close').

ws.on('close', () => { console.info('Lost a client') stream.end() stream.destroy(); })

software2000 commented 7 years ago

29