Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.on() method is not triggered on updating data in react native chat #1252

Closed
vishaldhanotiya opened this issue Dec 6, 2018 · 6 comments

Comments

@vishaldhanotiya
Copy link

I have implement one to one chat using socket.io-client in react native..
I have 2 user they have messaging each other using socket.emit event. One user send message to other user but other user not get message because socket.on method is not triggering.

Socket is connected properly but i am receiving data which is send by other user??

@vishaldhanotiya vishaldhanotiya changed the title Socket.on() method is not triggered on new data in react native chat Socket.on() method is not triggered on updating data in react native chat Dec 6, 2018
@0xK3K
Copy link

0xK3K commented Dec 10, 2018

Had the same issue with my App. I receive the very first event, then nothing else works. My temp fix for now is to stay with 2.1.1 and not update. At least it works.

@aleftenorio
Copy link

My problem is with the on method;

It is not receiving user messages by the same user, because it works when it is called screen and I go back, it is a loading problem.

constructor(props) {
super(props);

    (async () => {
        try {
            //Criando conexão de Socket IO com o servidor backend
            let tokenuser = await devStorage.getToken();

            //console.log(tokenuser);

            this.socket = await SocketIOClient('http://192.168.0.17:3000', {
                query: { token: tokenuser.access_token }
            });

            //Escrevendo os dois usuários em uma sala privada do socketio
            let nameroom = `${this.props.navigation.state.params.iduserfrom}${this.props.navigation.state.params.iduserto}`//Nome da sala, vai ser a concatenação do ID (Banco) dos dois usuários
            await this.socket.emit('subscribe', nameroom);

            //--------------------------------------------------------

            await this.socket.on(nameroom, (msg) => alert("Nova Mensagem"));

            console.log(this.socket)

            return;
            //Criando conexão de Socket IO com o servidor backend
        } catch (e) {
            console.log(`Erro ao iniciar socketio no constructor ${e}`);
        }
    })();
}


onSend(messages = []) {

    let nameroom2 = `${this.props.navigation.state.params.iduserfrom}${this.props.navigation.state.params.iduserto}`//Nome da sala, vai ser a concatenação do ID (Banco) dos dois usuários

    //console.log(nameroom)
    this.socket.emit('sendMessage', {
        room: nameroom2,
        message: messages[0].text
    });
}

When I send a message by the onSend method, calling the emit of the socket. The message arrives on the server. Plus the "On" can not hear the message.

If I leave the screen and come back, it works.

What can it be??

@lkonzen-garupa
Copy link

Anyone can solve this? I'm having the same error. Only the initial messages trigger the .on() method.

@nagmasalaria
Copy link

nagmasalaria commented Aug 12, 2021

When I send a message by the onSend method, calling the emit of the socket. The message arrives on the server. but
socket.on('add-message-response', (msg) => {
console.log(msg)
});
cannot hear the message this is not working and not recieve any message . please help me how to solve this

@raulangelj
Copy link

I am having the same issue, I see the some PR have been raise, does anyone knows if there is a version with this fix? 😬

@darrachequesne
Copy link
Member

@raulangelj could you please open a new issue with all necessary details to reproduce the behavior you are seeing? The PR are unrelated. Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants