{"action":"created","issue":{"url":"https://api.github.com/repos/faye/faye-websocket-node/issues/35","labels_url":"https://api.github.com/repos/faye/faye-websocket-node/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/faye/faye-websocket-node/issues/35/comments","events_url":"https://api.github.com/repos/faye/faye-websocket-node/issues/35/events","html_url":"https://github.com/faye/faye-websocket-node/issues/35","id":50715687,"number":35,"title":"Allow users of the client code to be notified when low-level data is read","user":{"login":"glasser","id":16724,"avatar_url":"https://avatars.githubusercontent.com/u/16724?v=3","gravatar_id":"","url":"https://api.github.com/users/glasser","html_url":"https://github.com/glasser","followers_url":"https://api.github.com/users/glasser/followers","following_url":"https://api.github.com/users/glasser/following{/other_user}","gists_url":"https://api.github.com/users/glasser/gists{/gist_id}","starred_url":"https://api.github.com/users/glasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glasser/subscriptions","organizations_url":"https://api.github.com/users/glasser/orgs","repos_url":"https://api.github.com/users/glasser/repos","events_url":"https://api.github.com/users/glasser/events{/privacy}","received_events_url":"https://api.github.com/users/glasser/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-12-02T20:36:32Z","updated_at":"2015-11-17T21:54:43Z","closed_at":"2015-11-17T21:54:43Z","body":"In our application, we have some heartbeat-style timeouts that let us detect the case where we haven't heard anything from the server in a long time.  (We implement this using application-level heartbeats in normal data frames, though the same issue would apply if we used WebSocket ping/pongs.)\r\n\r\nUsers behind very slow connections end up unnecessarily triggering these timeouts if the \"pong\" response is stuck behind a bunch of other messages or a single long message, though.\r\n\r\nIn the \"large number of small messages\" case, we can solve this by just considering any received message to effectively be a \"pong\".  But this doesn't work for the \"single large message\" case, because the Websocket API doesn't give us any way of knowing that we've received some data over the network until a full message arrives.\r\n\r\nSome non-ideal solutions:\r\n- Manually split up our large messages into small messages at the app level. This reduces to another guessing game about how big is \"too big\" and is a burden on app code authors.\r\n- Implement message fragmenting for Faye on our server, and add some sort of \"message fragment received\" event to Faye client. This is arguably more work than the solution I'm going to propose and still requires guessing game about good sizes.  Note that the fact that you can intersperse PONG frames between fragments is a red herring here, since the server will presumably still put all of the fragments onto the wire at once.\r\n- Switch from faye-websocket to websocket-driver and reimplement all of faye-websocket's features in order to add one tiny feature.  I did this before for proxy support and it was pretty unpleasant to try to get all the error handling right... turns out that faye-websocket is in fact some pretty good and useful code!\r\n- Reach inside the websocket object to get at `_stream` and place an event handler (for 'readable' or 'data') there (or stream it somewhere).  Obviously icky due to looking at internal fields.\r\n\r\nI think what I'm looking for is the ability to just add a \"dataReceived\" or something handler on the websocket object directly, and get it invoked (not necessarily with any data) whenever `_stream` receives any bytes.  I'm happy to implement this myself if you let me know what you think would make a good API.\r\n\r\n(There's some trickiness around the special handling of \"on 'data'\" in Node where just adding that listener has side effects... and \"on 'readable'\" doesn't support 0.8.)"},"comment":{"url":"https://api.github.com/repos/faye/faye-websocket-node/issues/comments/157521296","html_url":"https://github.com/faye/faye-websocket-node/issues/35#issuecomment-157521296","issue_url":"https://api.github.com/repos/faye/faye-websocket-node/issues/35","id":157521296,"user":{"login":"jcoglan","id":9265,"avatar_url":"https://avatars.githubusercontent.com/u/9265?v=3","gravatar_id":"","url":"https://api.github.com/users/jcoglan","html_url":"https://github.com/jcoglan","followers_url":"https://api.github.com/users/jcoglan/followers","following_url":"https://api.github.com/users/jcoglan/following{/other_user}","gists_url":"https://api.github.com/users/jcoglan/gists{/gist_id}","starred_url":"https://api.github.com/users/jcoglan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcoglan/subscriptions","organizations_url":"https://api.github.com/users/jcoglan/orgs","repos_url":"https://api.github.com/users/jcoglan/repos","events_url":"https://api.github.com/users/jcoglan/events{/privacy}","received_events_url":"https://api.github.com/users/jcoglan/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T21:54:43Z","updated_at":"2015-11-17T21:54:43Z","body":"I'm going to close this; I still feel like I agree with the last comment I posted."}}