S
S
squadbrodyaga2020-10-29 21:38:51
Node.js
squadbrodyaga, 2020-10-29 21:38:51

Is it possible to use response and request in socket.io?

In general, I am learning to use Socket.io.

I'm making a chat, but so far I can't see who sent the message. I want to pull the user login from the session,
but I don't know how to use request in socket.io to do something like this:
const login = req.session.user.login

If the login from the session can be obtained somehow differently, then please tell me how.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VegasChickiChicki, 2020-10-29
@VegasChickiChicki

front

this.socket.emit('new-message', {
            chat: {
              name: this.$route.params.id
            },
            user: {
              name: this.UserInfo.login
            },
            message: this.NewMessage,
          });

back
socket.on('new-message', data => {
      io.emit('update-chat', {
        user: data.user.name,
        message: data.message,
        date: date,
      });
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question