MetinSeylan / Vue-Socket.io

😻 Socket.io implementation for Vuejs and Vuex
https://metin.sh
MIT License
3.95k stars 499 forks source link

I do not get any data to console.log() #290

Open msadeghyan1996 opened 4 years ago

msadeghyan1996 commented 4 years ago

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

eddOrnelas commented 3 years ago

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.

snow-sprite commented 2 years ago

I faced, too. Did you find a workaround?