Vue-Socket.io
Vue-Socket.io copied to clipboard
I do not get any data to console.log()
Hello. my project for asterisk ami and i want give all call events. my nodejs server is worked fine and in putty give all events but in vuejs i can't give any event.
newCallPopup.vue
export default {
sockets: {
connect: function () {
console.log('socket connected')
},
customEmit: function (data) {
console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)')
}
},
mounted(){
this.sockets.subscribe('news', (data) => {
this.msg = data.message;
});
},
}
app.js
import VueSocketIO from 'vue-socket.io'
import SocketIO from 'socket.io-client'
const options = {
"transports" : ["websocket"]
};
Vue.use(new VueSocketIO({
debug: true,
connection: SocketIO('http://192.168.12.4:3000', options),
})
);
when i test it with js code it's work and return all event's in console.log() :
var connectionOptions = {
"force new connection" : true,
"reconnectionAttempts": "Infinity",
"timeout" : 10000,
"transports" : ["websocket"]
};
var socket = io.connect('http://192.168.12.4:3000', connectionOptions);
socket.on('news', function (data) {
console.log(data);
}
pls help me
I got nearly the same problem, i was using vue-socket.io directly without socket.io-client, following your example i got connection when i included the socket.io-client part like
connection: SocketIO('ws://localhost:3000', connectionOptions)
maybe you should download/install socket.io-client from npm and see what happens
post here what the developers tools / network log tells you
Regards.
I faced, too. Did you find a workaround?