{"action":"created","issue":{"url":"https://api.github.com/repos/pladaria/reconnecting-websocket/issues/60","repository_url":"https://api.github.com/repos/pladaria/reconnecting-websocket","labels_url":"https://api.github.com/repos/pladaria/reconnecting-websocket/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/pladaria/reconnecting-websocket/issues/60/comments","events_url":"https://api.github.com/repos/pladaria/reconnecting-websocket/issues/60/events","html_url":"https://github.com/pladaria/reconnecting-websocket/issues/60","id":323247613,"node_id":"MDU6SXNzdWUzMjMyNDc2MTM=","number":60,"title":"onclose behaviour has changed -- was it intentional?","user":{"login":"naggie","id":208440,"node_id":"MDQ6VXNlcjIwODQ0MA==","avatar_url":"https://avatars2.githubusercontent.com/u/208440?v=4","gravatar_id":"","url":"https://api.github.com/users/naggie","html_url":"https://github.com/naggie","followers_url":"https://api.github.com/users/naggie/followers","following_url":"https://api.github.com/users/naggie/following{/other_user}","gists_url":"https://api.github.com/users/naggie/gists{/gist_id}","starred_url":"https://api.github.com/users/naggie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/naggie/subscriptions","organizations_url":"https://api.github.com/users/naggie/orgs","repos_url":"https://api.github.com/users/naggie/repos","events_url":"https://api.github.com/users/naggie/events{/privacy}","received_events_url":"https://api.github.com/users/naggie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2018-05-15T14:38:21Z","updated_at":"2018-07-21T16:29:51Z","closed_at":null,"author_association":"NONE","body":"I noticed my application was failing to reconnect after the reconnecting-websocket rewrite. Upon investigation, I realised this seems to be because this library no longer reconnects when a websocket is intentionally closed by the server --  a `close` event is triggered but nothing else happens.\r\n\r\nPreviously, a graceful server-side close event would trigger a reconnect:\r\nhttps://github.com/pladaria/reconnecting-websocket/blob/e79fba552f236463adac04e1872f5e20e37d66a1/index.ts#L141\r\n\r\n...but now the reconnect is not triggered: https://github.com/pladaria/reconnecting-websocket/blob/2e5d6f0406784da357e3213506c9b508c2b32991/reconnecting-websocket.ts#L392\r\n\r\n\r\nThe reconnect mechanism is triggered on `error` so I suspect this is an intentional change.\r\n\r\nWhat do you think about adding a `reconnectOnClose` option, on by default? \r\n\r\nAlternatively the docs could be updated to clarify this behaviour, and perhaps suggest manually binding a reconnect such as:\r\n\r\n```\r\nrws.addEventListener('close', () => rws.reconnect());\r\n\r\n```\r\n\r\nAlthough that seems to cause thrashing if the connection cannot be established, as reconnect calls `_disconnect` which calls the handlers again.\r\n\r\n\r\nThanks for the well written library."},"comment":{"url":"https://api.github.com/repos/pladaria/reconnecting-websocket/issues/comments/406808027","html_url":"https://github.com/pladaria/reconnecting-websocket/issues/60#issuecomment-406808027","issue_url":"https://api.github.com/repos/pladaria/reconnecting-websocket/issues/60","id":406808027,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjgwODAyNw==","user":{"login":"borrascador","id":16508085,"node_id":"MDQ6VXNlcjE2NTA4MDg1","avatar_url":"https://avatars0.githubusercontent.com/u/16508085?v=4","gravatar_id":"","url":"https://api.github.com/users/borrascador","html_url":"https://github.com/borrascador","followers_url":"https://api.github.com/users/borrascador/followers","following_url":"https://api.github.com/users/borrascador/following{/other_user}","gists_url":"https://api.github.com/users/borrascador/gists{/gist_id}","starred_url":"https://api.github.com/users/borrascador/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borrascador/subscriptions","organizations_url":"https://api.github.com/users/borrascador/orgs","repos_url":"https://api.github.com/users/borrascador/repos","events_url":"https://api.github.com/users/borrascador/events{/privacy}","received_events_url":"https://api.github.com/users/borrascador/received_events","type":"User","site_admin":false},"created_at":"2018-07-21T16:29:51Z","updated_at":"2018-07-21T16:29:51Z","author_association":"NONE","body":"Reporting my own experiences here. I am using version 4.0.0-rc5 and was able to resolve the problem following naggie and adding the following code to my ReconnectingWebSocket instance. @jobelenus I am pretty sure naggie's answer needs 4.0.0 to work, not 3.2.2\r\n\r\n`rws.addEventListener('close', () => rws._shouldReconnect && rws._connect());`\r\n\r\nAnd also confirming that the following solution suggested by @pladaria causes an infinite loop and crashes my site on testing.\r\n\r\n`rws.addEventListener('close', () => rws.reconnect());`\r\n\r\nI'm seconding a lot of people in hoping that naggie's code becomes the default behavior. Otherwise, making this a default option makes sense to me as well."}}
{"actor":{"display_login":"borrascador"}}