because shithub doesnt have ipv6 support
Find a file
2018-11-18 17:15:14 +03:00
dist small changes and logo 2018-11-18 13:44:07 +03:00
docs small changes and logo 2018-11-18 13:44:07 +03:00
src added vuex support 2018-10-28 18:56:16 +03:00
.gitignore added vuex support 2018-10-28 18:56:16 +03:00
.npmignore added vuex support 2018-10-28 18:56:16 +03:00
LICENSE small changes and logo 2018-11-18 13:44:07 +03:00
package.json small changes and logo 2018-11-18 13:44:07 +03:00
README.md added dynamic listenler docs 2018-11-18 17:15:14 +03:00
webpack.config.js small changes and logo 2018-11-18 13:44:07 +03:00

Vue-Socket.io is a socket.io integration for Vuejs, easy to use, supporting Vuex and component level socket consumer managements

Demo

🚀 Installation

npm install vue-socket.io --save
import Vue from 'vue'
import store from './store'
import App from './App.vue'
import VueSocketIO from 'vue-socket.io'

Vue.use(new VueSocketIO({
    debug: true,
    connection: 'http://metinseylan.com:1992',
    vuex: {
        store,
        actionPrefix: 'SOCKET_',
        mutationPrefix: 'SOCKET_'
    }
}))

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
Parameters Type's Default Required Description
debug Boolean false Optional Enable logging for debug
connection String/Socket.io-client null Required Websocket server url or socket.io-client instance
vuex.store Vuex null Optional Vuex store instance
vuex.actionPrefix String null Optional Prefix for emitting server side vuex actions
vuex.mutationPrefix String null Optional Prefix for emitting server side vuex mutations

🌈 Component Level Usage

if you want listen socket events from component side, you have to add `sockets` object in Vue component, and every function will start listen events, depends on object key

new Vue({
    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)')
        }
    },
    methods: {
        clickButton: function (data) {
            // $socket is socket.io-client instance
            this.$socket.emit('emit_method', data)
        }
    }
})
Dynamic Listenlers

if you need consuming events dynamically in runtime, you can use `subscribe` and `unsubscribe` methods in Vue component

this.sockets.subscribe('EVENT_NAME', (data) => {
    this.msg = data.message;
});

this.sockets.unsubscribe('EVENT_NAME');