Answer the question
In order to leave comments, you need to log in
How to change the token in vue-socket.io-extended on an established connection?
I use Nuxt.js, I connect the following code through the plugin:
import Vue from 'vue'
import VueSocketio from 'vue-socket.io-extended'
import socketio from 'socket.io-client'
export default ({app, store, nuxtState, req, route}) => {
let socket = socketio('http://localhost:5003', {
autoConnect: false,
transports:['websocket'],
query: {
token: store.getters['auth/userHash']
},
});
Vue.use(VueSocketio, socket);
socket.open();
socket.on('connect', () => {
store.dispatch('rooms/socketConnectUpdate', true);
});
socket.on('disconnect', () => {
store.dispatch('rooms/socketConnectUpdate', false);
});
}
this.$socket.io.disconnect();
this.$socket.query = `token=${newVal}`;
this.$socket.io.connect();
Answer the question
In order to leave comments, you need to log in
this.$socket.disconnect();
this.$socket.query = `token=${newVal}`;
this.$socket.io.opts.query = `token=${newVal}`;
this.$socket.open();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question