I have a Swift app that uses Socket.IO, and sometimes, the socket just refuses to get events triggered from the Server for some unknown reason (there is no disconnection and there is no error log that I can find). The events that the app can get is only events that are first emitted by the app, and then the server acknowledges it, and sends an event back as a respond to the app's emit.
Below is how I initiated the socket:
guard let url = URL(string: BASE_URL_SOCKET) else {return} // NEW
socketManager = SocketManager(socketURL: url, config: [.log(true), press, .connectParams(params), .path("..."), .reconnects(true), .forceNew(true), .reconnectAttempts(-1), .reconnectWait(5)])
socket = socketManager?.defaultSocket
self.socket?.connect()
This is what the I have been doing: Below is the example of my socket listener events and my socket emitting events:
- success flow : I emit get-room, and server gives me "room-listener"
- error flow: I setup the handler, and just wait for the server to give me the room-listener event
func emitFunction() {
let params: [String: Any] = [
"param1": "value1"
]
self.socket?.emit("get-room", params)
}
func setupHandler() {
self.socket?.on("room-listener", callback: { data, ack in
....
})
}
I am using version 16.1.1 of Socket IO (Swift Package Manager). Any insight is appreciated, as I have not found any leads on this. (for reference, the same works for Android, regardless of flow, so i'm stumped)
Will try to provide the server codes if need be from my Back End team. Thank you!