openstf / ios-minicap

iOS Minicap provides a socket interface for streaming realtime screen capture data out of iOS devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example-Server crashes when client leaves page

software2000 opened this issue · comments

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/node_modules/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)`

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

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

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

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

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