Closed Daltron closed 7 years ago
@sjrmanning, if you could chime in on this, that would be greatly appreciated! 😃
I've had a look at this and I think the best solution is to catch this in Socket
, checking if we're connected before we process the Push
.
When I get some time I'd like to refactor a lot of this stuff so the errors are more formal — at least a way to distinguish Birdsong client errors from errors that might come back from the server with the same status key (currently "error"
).
For now I've fixed this and return a simple ["reason": "Not connected to socket."]
payload when send
is called when disconnected. Let me know if this is suitable for you or if you have any thoughts :)
Note: tested this with a disconnected socket with the example below.
self.channel = self.socket.channel("test")
self.channel?.send("new:msg", payload: ["body": "test"])?.receive("error", callback: { payload in
debugPrint("Received error reason: ", payload)
})
@sjrmanning This is actually exactly what I am doing right now so I think this is a great to handle it. Thanks! 👍
You're welcome! I haven't had time lately to continue my side-project that I use Birdsong for so I really appreciate the reports & PRs in the mean-time :)
While the server is turned off intentionally (thus my socket being disconnected), I am running the following block of code:
I was expecting the error callback to be executed if trying to send a message while the socket was disconnected. I don't know wether this is the way the library is designed or if it is a bug. Should I be checking before I send messages to the channel wether or not the socket is connected?