Gathering detailed insights and metrics for vue-3-ts-socket.io
Gathering detailed insights and metrics for vue-3-ts-socket.io
Gathering detailed insights and metrics for vue-3-ts-socket.io
Gathering detailed insights and metrics for vue-3-ts-socket.io
npm install vue-3-ts-socket.io
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
127 Commits
1 Branches
1 Contributors
Updated on Oct 21, 2021
Latest Version
1.0.3
Package Id
vue-3-ts-socket.io@1.0.3
Unpacked Size
113.05 kB
Size
60.93 kB
File Count
8
NPM Version
6.14.15
Node Version
14.17.6
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Vue-3-ts-Socket.io is a Vue 3 Typescript compatibility version of this repo
All thanks to its author
are you looking for old documentation? it's here
1npm install vue-3-ts-socket.io --save
1import Vue from 'vue' 2import store from './store' 3import App from './App.vue' 4import VueSocketIO from 'vue-3-socket.io' 5 6Vue.use(new VueSocketIO({ 7 debug: true, 8 connection: 'http://metinseylan.com:1992', 9 vuex: { 10 store, 11 actionPrefix: 'SOCKET_', 12 mutationPrefix: 'SOCKET_' 13 }, 14 options: { path: "/my-app/" } //Optional options 15})) 16 17new Vue({ 18 router, 19 store, 20 render: h => h(App) 21}).$mount('#app')
1import Vue from 'vue' 2import store from './store' 3import App from './App.vue' 4import VueSocketIO from 'vue-3-socket.io' 5import SocketIO from 'socket.io-client' 6 7const options = { path: '/my-app/' }; //Options object to pass into SocketIO 8 9Vue.use(new VueSocketIO({ 10 debug: true, 11 connection: SocketIO('http://metinseylan.com:1992', options), //options object is Optional 12 vuex: { 13 store, 14 actionPrefix: "SOCKET_", 15 mutationPrefix: "SOCKET_" 16 } 17 }) 18); 19 20new Vue({ 21 router, 22 store, 23 render: h => h(App) 24}).$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 |
If you want to listen socket events from component side, you need to add `sockets` object in Vue component, and every function will start to listen events, depends on object key
1new Vue({ 2 sockets: { 3 connect: function () { 4 console.log('socket connected') 5 }, 6 customEmit: function (data) { 7 console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)') 8 } 9 }, 10 methods: { 11 clickButton: function (data) { 12 // $socket is socket.io-client instance 13 this.$socket.emit('emit_method', data) 14 } 15 } 16})
If you need consuming events dynamically in runtime, you can use `subscribe` and `unsubscribe` methods in Vue component
1this.sockets.subscribe('EVENT_NAME', (data) => { 2 this.msg = data.message; 3}); 4 5this.sockets.unsubscribe('EVENT_NAME');
If you want to handle 'kebab-case', or "event with space inside it" events, then you have to define it via the following way
1export default { 2 name: 'Test', 3 sockets: { 4 connect: function () { 5 console.log('socket to notification channel connected') 6 }, 7 }, 8 9 data () { 10 return { 11 something: [ 12 // ... something here for the data if you need. 13 ] 14 } 15 }, 16 17 mounted () { 18 this.$socket.subscribe("kebab-case", function(data) { 19 console.log("This event was fired by eg. sio.emit('kebab-case')", data) 20 }) 21 } 22}
When you set store parameter in installation, `Vue-Socket.io` will start sending events to Vuex store. If you set both prefix for vuex, you can use `actions` and `mutations` at the same time. But, best way to use is just `actions`
1import Vue from 'vue' 2import Vuex from 'vuex' 3 4Vue.use(Vuex) 5 6export default new Vuex.Store({ 7 state: {}, 8 mutations: { 9 "<MUTATION_PREFIX><EVENT_NAME>"() { 10 // do something 11 } 12 }, 13 actions: { 14 "<ACTION_PREFIX><EVENT_NAME>"() { 15 // do something 16 } 17 } 18})
No vulnerabilities found.
No security vulnerabilities found.