-
Notifications
You must be signed in to change notification settings - Fork 495
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
Installing the plugin asynchronously results in socket listeners not working #109
Comments
got a similar problem where the vuex mutations do not work after waiting for user authentication. Not sure why and it seems hard to debug. |
I'm working similar to you, creating a connection to the socket after a login with Vuex and not a problem, but I made a connection differently. main.jsimport socketIo from 'socket.io-client';
import VueSocketIo from 'vue-socket.io';
import store from './store';
Vue.use(VueSocketIo, socketIo('http://localhost:5000', { autoConnect: false }, store));
new Vue({
el: '#app',
router,
store,
render: h => h(App),
}); store.jsimport Vue from 'vue';
import Vuex from 'vuex';
import chat from './modules/chat';
Vue.use(Vuex);
export default new Vuex.Store({
actions: {
socket_connect = ({ commit }) =>
commit('SOCKET_CONNECT');
socket_atualizar = ({ commit }, message) =>
commit('SOCKET_MESSAGE', message);
},
modules: {
chat,
},
strict: true,
}); chat.jsconst mutations = {
SOCKET_CONNECT(state) {
state.connect = true;
},
SOCKET_MESSAGE(state, message) {
state.messages.push(message);
},
};
const state = {
connect: false,
messages: [],
};
export default {
state,
mutations,
}; component.vue<script>
export default {
methods: {
click() {
// in my case I change the header
this.$socket.io.opts.transportOptions.polling.extraHeaders.Authorization = 'token';
this.$socket.open()
}
}
}
</script> |
@chambber The original only need to set {autoConnect: false} |
This is necessary for me because I authenticate via token on the server. |
Another option, works to me: socket-client-instance.jsimport SocketIO from 'socket.io-client';
const socketServer = `http://${process.env.VUE_APP_WEBSOCKET_HOST}:${process.env.VUE_APP_WEBSOCKET_PORT}`;
const token = localStorage.getItem('token');
const clientSocketOptions = {
autoConnect: false,
query: { token },
};
export default SocketIO(socketServer, clientSocketOptions); Vue Componentthis.$socket.io.opts.query.token = token; |
Hello,
I was trying use the plugin in this scenario:
User authenticates on a server, and after the authentication response is positive, the user connects via socketio. So i do something like this:
After this i can emit events to the server, but the socket event listeners inside the socket block in components do not work. They do work as expected when i connect to the server in the main.js file, but doing it asynchronously seems to break some things down.
Is this a bug or am i doing something wrong?
The text was updated successfully, but these errors were encountered: