Search code examples
socket.ioconnectionnativescript

nativescript-socketio connect() issue after upgrading


i recently upgraded one of my projects to NS8 and thus nativescript-socketio to @triniwiz/nativescript-socketio.

Everything seems to work, but connect() does nothing, at all. No exception, no error. Juste nothing. I tried a blank project with just this in app.js :

import { SocketIO } from '@triniwiz/nativescript-socketio';
const socketIO = new SocketIO("http://1**.**.***.***:3001");

// connect
socketIO.connect();

And nothing happens, the server doesn't react. The server works perfectly, i can reach it with other socket.io clients and a curl request without any problem.

curl "http://1**.**.***.***:3001/socket.io/?EIO=4&transport=polling"

95:0{"sid":"wsR7LhpisXyHhQpxAAAB","upgrades":["websocket"],"pingInterval":2000,"pingTimeout":2000}2:40

Is there anything new i need to do in NS8 for nativescript-socketio to work properly ?

Thank you :)


Solution

  • Ok, i finally solved the problem, it was just because i fall back from https to http, and then having a cors policy issue.

    Adding

    android:usesCleartextTraffic="true"
    

    To AndroidManifest.xml did the trick.

    From

    <application
            android:name="com.tns.NativeScriptApplication"
            android:allowBackup="true"
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
    

    To

    <application
            android:name="com.tns.NativeScriptApplication"
            android:allowBackup="true"
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme"
            android:usesCleartextTraffic="true">