D
D
Dmitry Volkhontsev2017-09-21 15:10:19
JavaScript
Dmitry Volkhontsev, 2017-09-21 15:10:19

How to reconnect to server using vue-socket.io?

Good day.
Trying to build a web app with vue.js? in which on the same page, depending on the value of the variable, either the application interface or the login window will be displayed. The application uses socket.io on the server side and vue-socket.io on the client side.
The problem is this - when the page is initially loaded, vue-socket.io tries to connect to the server, which in turn checks for the existence of a session and if it does not exist, it refuses to connect. After entering the username and password, a session is created, but it is not possible to start a second attempt to connect to the server.
Tried various vue-socket.io commands like - this.$socket.connect(), this.$socket.emit('message'), this.$socket.open(). But nothing happens. At the same time, if you refresh the page, then, accordingly, vue-socket.io makes a new request to the server, which ends in success and the application interface opens.
The initial connection is made in the following way:

import VueSocketio from 'vue-socket.io';
Vue.use(VueSocketio, '/', store);

The question actually is how to force vue-socket.io to perform a second one. trying to connect to the server after entering the username and password?
PS Taking this moment, I would like to know if it is possible to make socket.emit requests from vuex? Since at the moment, in order to find out that the connection has already been established in the application itself, I execute this.$store.subscribe() with a check of which mutation has been performed. Or is using this.$store.subscribe() still the right approach?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question