1

I'm using simple Websocket connection on react native framework, with ios it works great, but on Android I'm in 70% getting message: WebSocketEvent {type: "error", message: null} and this error is closing socket connection. I don't know why does it happenning?

My code is:

self._ws = new WebSocket("wss://fe01-ws.wearetv.com/platform/simchacr/some_code");

    var initPing = function (){
        pingInterval = setInterval(function(){
            ping.timestamp = new Date().getTime();
            ping.sequenceNumber++;
            ping.params.timestamp = ping.timestamp;
            ping.params.sent_ts = ping.timestamp;
            ping.params.seq = ping.sequenceNumber.toString();
            self._ws.send(JSON.stringify(ping.params));
            console.log("Ping is sent");
            isPinged = false;
            pongTimeout = setTimeout(function(){
                if (isPinged === false) {
                    self._ws.close();
                }
            }, PONG_DELAY);
        }, PING_INTERVAL);
    };


    var initConnection = (function me() {
        isPinged = false;

        self._ws.onopen = function () {
            console.log("Connection opened");
            initPing();
        };
        self._ws.onerror = function(error) {
            console.error(error);
            self._ws.close();
        };
        self._ws.onclose = function() {
            console.log("Connection closed");
            clearInterval(pingInterval);
            clearTimeout(pongTimeout);
            clearTimeout(reconnectTimeout);
            reconnectTimeout = setTimeout(function(){
                console.log("Ping reconnection");
                initConnection();
                initPing();
            }, PING_RECONNECT_TIME);
            isPinged = false;
        };
        self._ws.onmessage = function (message) {
            //var data = JSON.parse(message.data);
            //console.log(data);
            //if (data[REQUEST_PROPERTY_MAIN] === "ACK") {
            //    clearTimeout(pongTimeout);
            //    clearTimeout(reconnectTimeout);
            //    isPinged = true;
            //}
            //self._getMessage(data);
        };
        return me;
    })();
1
  • Did you end up finding a solution to this? Commented Nov 17, 2015 at 21:04

1 Answer 1

2

Have you configured Gradle to compile the same react-native version as the one you installed from the npm?

For example: compile project(':ReactAndroid')

as opposed to com.facebook.react:react-native:0.12.+

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.