socket.io specific iOS device not receiving "group" emit

Viewed 23

I've built a small game in iOS using Socket IO (Flask GCP Back end in Python) and when two people are playing each other, I send updates like this

emit("update", {"state": OutgoingMatchState.player_moved.value,
                "move": move,
                "match_id": match.id,
                "id": player_id}, to=[home_player.sid, away_player.sid])

This has been working fine until recently I've been testing on my iPad... and this device specifically doesn't receive this type of emit

All other devices and simulators I've tested with work 100% of the time. Even when this device doesn't receive the update, the other device in the match does.

I'm also 100% sure the sids exist and are accurate... if I emit the same update without the to=[] part, it works for the iPad in question...

i.e. this works fine if the iPad makes the original socket post.

emit("update", {"state": OutgoingMatchState.player_moved.value,
                "move": move,
                "match_id": match.id,
                "id": player_id})

I need to send updates to both players in the game, I understand I could refactor to make a room for each match, but I'm wondering why this specific device isn't working.. Making a room based on match.id is a little messy considering I'd have to tidy them away after.

I've tried deleting the app on device and creating a new account, its also broken... it is the device specifically that doesn't like the to=[] updates.

To make sure I've tried namespace="\" and include_self=True but these also do not resolve the issue.

My manager looks like this... but like I said its working for all other devices

    private lazy var socketManager: SocketManager = {
        let config: SocketIOClientConfiguration = [.log(false), .compress]
        let manager = SocketManager(socketURL: URL(string: domain)!, config: config)
        manager.forceNew = true
        manager.reconnectWait = 3
        return manager
    }()

Turning on .log(true) nothing is received at this level either..

OK here is what is happening on the server side...

2022-09-20 16:25:33.000 ICT
e9Hz8a1GQ-lxB3gvAAAO: Received packet MESSAGE data 1/,
2022-09-20 16:25:33.000 ICT
e9Hz8a1GQ-lxB3gvAAAO: Received packet MESSAGE data 0/,
2022-09-20 16:25:33.000 ICT
******* connection established *******
2022-09-20 16:25:33.000 ICT
e9Hz8a1GQ-lxB3gvAAAO: Sending packet MESSAGE data 0{"sid":"JjExeVH003_sW2MqAAAQ"}
2022-09-20 16:25:33.000 ICT
e9Hz8a1GQ-lxB3gvAAAO: Received packet MESSAGE data 1/,
2022-09-20 16:25:33.000 ICT
e9Hz8a1GQ-lxB3gvAAAO: Received packet MESSAGE data 0/,
2022-09-20 16:25:33.000 ICT
******* connection established *******
2022-09-20 16:25:33.000 ICT
e9Hz8a1GQ-lxB3gvAAAO: Sending packet MESSAGE data 0{"sid":"KlAr45jZhO1Nb9ApAAAR"}

In the server side code

@socketio.event()
def connect():
    print("******* connection established *******")

The connection is being established twice for this particular device, but the device is not hearing back about the second one....

Client side code:

        socket.on(clientEvent: .connect) { [weak self] data, ack in
            print("*** Connected ***")
            guard let `self` = self else { return }
            guard let d = data[safe: 1] as? [String: Any],
                    let sid = d["sid"] as? String else {
                print("Malformed connection data:", data)
                return
            }
            print(sid)
            print("*** SID ***")
            self.socketId = sid
            self.socketConnectionStatus.value = true
            self.matchDelegate?.connectionMade()
        }

        socket.on(clientEvent: .reconnect) { [weak self] data, ack in
            guard let `self` = self else { return }
  
            print("**** Websocket reconnected ****")
            
            guard let d = data[safe: 1] as? [String: Any],
                  let sid = d["sid"] as? String else {
                print("Malformed connection data:", data)
                return
            }
            print(sid)
            print("*** SID ***")
            self.socketId = sid
            self.matchDelegate?.connectionMade()
            self.socketConnectionStatus.value = true
        }

The client only heard about JjExeVH003_sW2MqAAAQ and keeps that as its sid however some double connection is being made but its not reported on the client side.

printed:

*** Connected ***
JjExeVH003_sW2MqAAAQ
*** SID ***
1 Answers

TLDR in the comments... I was being too tough with the disconnect / reconnect apis when trying to re-establish connection... being gentler with it worked. However, the second sid doesn't come through which is a concern.

Related