socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

IOS 15.5 Cannot Connect (Client & Server 4.5.1)

Open AlvinStefanus opened this issue 4 years ago • 1 comments

Describe the bug Cannot connect with IOS 15.5 Devices

To Reproduce

Socket.IO server version: 4.5.1

Server

export const initSocketIO = (server: any) => {
  const io = require("socket.io")(server);

  io.on("connection", async (socket: Socket) => {
    logger.info(`user is connecting...`);

    let token = socket.handshake.query.token;
    let applicationId = socket.handshake.query.applicationId;

    .....

Socket.IO client version: 4.5.1

Client

  useEffect(() => {

    if (socket) {
      socket.removeAllListeners();

      if (socket.listeners("connect").length === 0) {
        socket.on('connect', () => {
          console.log('connected')
          dispatch(setSupportStatus(true));
        })
      }

      if (socket.listeners("message").length === 0) {
        socket.on('message', (data: any) => {
          console.log(data);
          if (data.chatRoomId == support.selectedChatRoom?.id) {
            dispatch(addActiveChat(data));
          } else {
            //create notification badge
            dispatch(setNewMessage({ id: data.chatRoomId, value: true }));
          }
        })
      }

      if (socket.listeners("close-chat-room").length === 0) {
        socket.on('close-chat-room', (id: string) => {
          dispatch(closeChatRoom(id));
        })
      }

      if (socket.listeners("disconnect").length === 0) {
        socket.on('disconnect', (data: any) => {
          console.log('disconnected');
          dispatch(setSupportStatus(false));
        })
      }
    }

    if (socket && !support.connected) {
      socket.connect();
      getActiveSupportTickets();
    }
  }, [dispatch, support.connected, support.selectedChatRoom?.id, getActiveSupportTickets, socketReady]);

  useEffect(() => {
    if (support.userId && support.token && support.applicationId) {
      setSocket(io(socketIoServer,
        {
          transports: ['websocket'],
          query: {
            token: support.token,
            applicationId: support.applicationId
          }
        }));
      setSocketReady(true);
    }
  }, [support.applicationId, support.token, support.userId]);

The code does not even get into io.on("connection",..., it stopped by the error even before getting into the connection event.

Expected behavior A clear and concise description of what you expected to happen.

I expect IOS devices to be able to connect with my server.

Platform:

  • Device: All IOS Devices 15.5
  • OS: IOS 15.5

Additional context Add any other context about the problem here.

The Error

The error from client:

[Error] WebSocket connection to 'wss://support.xxxxxx.com/socket.io/?token=xxxxx&applicationId=xxxxxx&EIO=4&transport=websocket' failed: There was a bad response from the server.

The error from the server:

2022-06-19T04:10:44.809Z engine handshaking client "KddXP_t6guQ2dxHwAABK" 
2022-06-19T04:10:44.809Z socket.io:server incoming connection with id KddXP_t6guQ2dxHwAABK Node.js

2022-06-19T04:10:46.125Z socket.io:client no namespace joined yet, close the client 
2022-06-19T04:10:46.125Z socket.io:client forcing transport close 
2022-06-19T04:10:46.125Z socket.io:client client close with reason forced close 
2022-06-19T04:10:46.125Z socket.io:client client close with reason forced server close Node.js

2022-06-19T04:10:50.706Z engine handshaking client "Y_yOM8oTDtT8sgntAABL" 
2022-06-19T04:10:50.706Z socket.io:server incoming connection with id Y_yOM8oTDtT8sgntAABL Node.js

2022-06-19T04:10:52.615Z socket.io:client no namespace joined yet, close the client 
2022-06-19T04:10:52.615Z socket.io:client forcing transport close 
2022-06-19T04:10:52.615Z socket.io:client client close with reason forced close 
2022-06-19T04:10:52.615Z socket.io:client client close with reason forced server close

The error repeated as the client keeps trying to re-connect.

Is is fine on Android Devices


Github Repo To Test

I have setup the github repo for testing the socket.io-client using dummy user (https://github.com/AlvinStefanus/socket).


Polling Connection Works

The polling connection works fine on iOS devices, but not websocket connection.

AlvinStefanus avatar Jun 19 '22 08:06 AlvinStefanus

@AlvinStefanus Stumbled across this when I was facing a similar issue. The fix mentioned in the below github issue fixed it for me.

https://github.com/facebook/react-native/issues/30727

varanasisrikar avatar Dec 12 '25 06:12 varanasisrikar