socketio / socket.io-client-swift

Other
5.21k stars 841 forks source link

Behaviour change: connect on manager #1423

Open yosiat opened 2 years ago

yosiat commented 2 years ago

Hi!

We tried upgrading to socket.io-client-swift to v16 from v15 and it tooks us sometime to understand that, but there was a change in behaviour that wasn't documented here - https://nuclearace.github.io/Socket.IO-Client-Swift/15to16.html

Based on this code - https://github.com/socketio/socket.io-swift-fiddle I tested it with both v15 and v16, by changing this line - https://github.com/socketio/socket.io-swift-fiddle/blob/main/Sources/Fiddle/main.swift#L16 to manager.connect()

On v15, I managed to get connected event -

2022-08-14 20:14:20.249 Fiddle[78784:132082799] LOG SocketIOClient{/}: Adding handler for event: connect
2022-08-14 20:14:20.249 Fiddle[78784:132082799] LOG SocketIOClient{/}: Adding handler for event: disconnect
2022-08-14 20:14:20.249 Fiddle[78784:132082799] LOG SocketManager: Adding engine
2022-08-14 20:14:20.250 Fiddle[78784:132082867] LOG SocketEngine: Starting engine. Server: https://socket-host.com
2022-08-14 20:14:20.250 Fiddle[78784:132082867] LOG SocketEngine: Handshaking
2022-08-14 20:14:22.832 Fiddle[78784:132082877] LOG SocketIOClient{/}: Handling event: websocketUpgrade with data: [["server": "openresty", "strict-transport-security": "max-age=2419200; includeSubDomains", "date": "Sun, 14 Aug 2022 17", "sec-websocket-accept": "Rx6Nt5dDZLUC1/cg3JlbQkycZ+E=", "sec-websocket-extensions": "permessage-deflate; server_max_window_bits=15", "connection": "upgrade", "upgrade": "websocket"]]
2022-08-14 20:14:22.832 Fiddle[78784:132082877] LOG SocketEngine: Got message: 0{"sid":"9WcIc48LfEyiEk-bDze-","upgrades":[],"pingInterval":25000,"pingTimeout":20000,"maxPayload":1000000}
2022-08-14 20:14:22.832 Fiddle[78784:132082877] LOG SocketEngine: Got message: 40
2022-08-14 20:14:22.832 Fiddle[78784:132082867] LOG SocketIOClient{/}: Handling event: ping with data: []
2022-08-14 20:14:22.832 Fiddle[78784:132082877] LOG SocketEngine: Writing ws:  has data: false
2022-08-14 20:14:22.832 Fiddle[78784:132082877] LOG SocketEngineWebSocket: Sending ws:  as type: 2
2022-08-14 20:14:22.832 Fiddle[78784:132082867] LOG SocketManager: Engine opened Connect
2022-08-14 20:14:22.832 Fiddle[78784:132082867] LOG SocketIOClient{/}: Socket connected
2022-08-14 20:14:22.832 Fiddle[78784:132082867] LOG SocketIOClient{/}: Handling event: statusChange with data: [connected, 3]
2022-08-14 20:14:22.833 Fiddle[78784:132082867] LOG SocketIOClient{/}: Handling event: connect with data: ["/"]
SOCKET CONNECTED
2022-08-14 20:14:22.833 Fiddle[78784:132082867] LOG SocketParser: Parsing 0
2022-08-14 20:14:22.833 Fiddle[78784:132082867] LOG SocketParser: Decoded packet as: SocketPacket {type: 0; data: []; id: -1; placeholders: 0; nsp: /}
2022-08-14 20:14:23.100 Fiddle[78784:132082877] LOG SocketEngine: Got message: 3
2022-08-14 20:14:23.100 Fiddle[78784:132082877] LOG SocketIOClient{/}: Handling event: pong with data: []

On v16, The socket is not being connected -

2022-08-14 20:15:06.145 Fiddle[82035:132094709] LOG SocketIOClient{/}: Adding handler for event: connect
2022-08-14 20:15:06.145 Fiddle[82035:132094709] LOG SocketIOClient{/}: Adding handler for event: disconnect
2022-08-14 20:15:06.145 Fiddle[82035:132094709] LOG SocketManager: Adding engine
2022-08-14 20:15:06.146 Fiddle[82035:132094760] LOG SocketEngine: Starting engine. Server: https://socket-host.com
2022-08-14 20:15:06.146 Fiddle[82035:132094760] LOG SocketEngine: Handshaking
2022-08-14 20:15:07.289 Fiddle[82035:132094765] LOG SocketEngine: Got message: 0{"sid":"0FcahdfumGM4aVYADzgS","upgrades":[],"pingInterval":25000,"pingTimeout":20000,"maxPayload":1000000}
2022-08-14 20:15:07.289 Fiddle[82035:132094768] LOG SocketIOClient{/}: Handling event: websocketUpgrade with data: [["Connection": "upgrade", "Server": "openresty", "Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Upgrade": "websocket", "Date": "Sun, 14 Aug 2022 17:15:07 GMT", "Strict-Transport-Security": "max-age=2419200; includeSubDomains", "Sec-WebSocket-Accept": "nuoxPhIHFfXznlIUX8CSiTlF4/U="]]
2022-08-14 20:15:07.289 Fiddle[82035:132094765] LOG SocketManager: Engine opened Connect

I am not sure if this an intentional change, if not I think the migration guide should be updated.

My opinion: I am not a Swift/Objective-C developer, coming from NodeJS background.. It makes sense to me that you should do connect on the socket, and I don't understand what's the meaning of doing connect on the manager it self.