{"action":"created","issue":{"url":"https://api.github.com/repos/faye/faye/issues/447","repository_url":"https://api.github.com/repos/faye/faye","labels_url":"https://api.github.com/repos/faye/faye/issues/447/labels{/name}","comments_url":"https://api.github.com/repos/faye/faye/issues/447/comments","events_url":"https://api.github.com/repos/faye/faye/issues/447/events","html_url":"https://github.com/faye/faye/issues/447","id":168375041,"number":447,"title":"Updating to 1.2.2 with Chrome time throttling","user":{"login":"justindujardin","id":101493,"avatar_url":"https://avatars.githubusercontent.com/u/101493?v=3","gravatar_id":"","url":"https://api.github.com/users/justindujardin","html_url":"https://github.com/justindujardin","followers_url":"https://api.github.com/users/justindujardin/followers","following_url":"https://api.github.com/users/justindujardin/following{/other_user}","gists_url":"https://api.github.com/users/justindujardin/gists{/gist_id}","starred_url":"https://api.github.com/users/justindujardin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justindujardin/subscriptions","organizations_url":"https://api.github.com/users/justindujardin/orgs","repos_url":"https://api.github.com/users/justindujardin/repos","events_url":"https://api.github.com/users/justindujardin/events{/privacy}","received_events_url":"https://api.github.com/users/justindujardin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-29T17:33:26Z","updated_at":"2016-07-31T15:47:49Z","closed_at":null,"body":"### Problem\r\nRecent versions of Chrome browser throttle time callbacks to pages when in the background or when the tab is not active. This resulted in frequent websocket disconnects on `1.1.2`, so we monkey patched the `Faye.Transport.WebSocket.prototype._ping` method to receive time updates from a WebWorker (which is not subject to time throttling.) \r\n\r\nWhile updating to `1.2.2` to get the fix from #394, it became apparent that our patch of WebSocket ping will no longer work because `Faye.Transport.WebSocket.prototype` is no longer exposed.\r\n\r\n### Question\r\nCan you recommend a method for providing reliable time updates to the WebSocket._ping method without the monkey patch that was used in `1.1.2`?\r\n\r\nBecause Faye now [checks the readyState](https://github.com/faye/faye/blob/1.2.1/src/transport/web_socket.js#L128) of the socket while pinging, I think the only thing I really _need_ is the custom timeout function bit.\r\n\r\n### Existing 1.1.2 Patch\r\n```typescript\r\n// Based on official method: https://github.com/faye/faye/blob/1.1.2/javascript/transport/web_socket.js#L113-L117\r\nFaye.Transport.WebSocket.prototype._ping = function () {\r\n  let self: any = this;\r\n  if (self._socket) {\r\n    let socket = self._socket;\r\n    let state = socket.readyState;\r\n    if (state === socket.CLOSED || state === socket.CLOSING) {\r\n      return;\r\n    }\r\n    else {\r\n      self._socket.send('[]');\r\n    }\r\n    time.wait(pingDelay, () => self._ping()); // schedule the next\r\n  }\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/faye/faye/issues/comments/236437264","html_url":"https://github.com/faye/faye/issues/447#issuecomment-236437264","issue_url":"https://api.github.com/repos/faye/faye/issues/447","id":236437264,"user":{"login":"justindujardin","id":101493,"avatar_url":"https://avatars.githubusercontent.com/u/101493?v=3","gravatar_id":"","url":"https://api.github.com/users/justindujardin","html_url":"https://github.com/justindujardin","followers_url":"https://api.github.com/users/justindujardin/followers","following_url":"https://api.github.com/users/justindujardin/following{/other_user}","gists_url":"https://api.github.com/users/justindujardin/gists{/gist_id}","starred_url":"https://api.github.com/users/justindujardin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justindujardin/subscriptions","organizations_url":"https://api.github.com/users/justindujardin/orgs","repos_url":"https://api.github.com/users/justindujardin/repos","events_url":"https://api.github.com/users/justindujardin/events{/privacy}","received_events_url":"https://api.github.com/users/justindujardin/received_events","type":"User","site_admin":false},"created_at":"2016-07-31T15:47:49Z","updated_at":"2016-07-31T15:47:49Z","body":"`global.setTimeout` is used internally in Faye.  When running in Chrome, and not the active tab, the callback functions for `setTimeout` and `setInterval` are not invoked on time. A setTimeout call with a 500ms delay may have its callback invoked 5 seconds later. This presents a problem for Faye because over time the ping messages become further and further behind and eventually the client connection is terminated.\r\n\r\nThe patch I applied delegates the `setTimeout` calls to a custom class that posts a message to a webworker. The worker sets the timeout and then posts back to the main thread when it is complete.  WebWorkers are not subject to the throttling of \"time\" callbacks (i.e. setTimeout, setInterval.) This allows the client to deliver timely pings to the server, making the websocket connection much more reliable."}}
{"actor":{"display_login":"justindujardin"}}