Gathering detailed insights and metrics for vue-socket.io-extended
Gathering detailed insights and metrics for vue-socket.io-extended
Gathering detailed insights and metrics for vue-socket.io-extended
Gathering detailed insights and metrics for vue-socket.io-extended
@awamwang/vue-socket.io-extended
Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
@amiceli/vue-socket.io-extended
Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
cloudenlynotifications
##### Project setup ``` npm install ``` in "main.js" file of the project copy and paste the code below ``` Vue.use(cloudenlynotifications) import VueSocketIOExt from 'vue-socket.io-extended'; import io from 'socket.io-client'; const socket = io('CLOUDENLY
✌⚡ Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
npm install vue-socket.io-extended
Typescript
Module System
Node Version
NPM Version
JavaScript (98.24%)
Shell (1.76%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
625 Stars
1,643 Commits
35 Forks
12 Watchers
14 Branches
11 Contributors
Updated on Jun 18, 2025
Latest Version
4.2.0
Package Id
vue-socket.io-extended@4.2.0
Size
10.98 kB
NPM Version
6.14.12
Node Version
14.16.1
Published on
Apr 25, 2021
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
1
24
Socket.io bindings for Vue.js 2 and Vuex (inspired by Vue-Socket.io)
:warning: The alpha version of v5 (with Vue 3 support) has been released. Your feedback would be appreciated here
$socket.connected
and $socket.disconnected
socket.io
events inside componentssocket.io
eventssocket.io-client
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|---|
38+ :heavy_check_mark: | 13+ :heavy_check_mark: | 8+ :heavy_check_mark: | 25+ :heavy_check_mark: | 12+ :heavy_check_mark: | 11+ :heavy_check_mark: |
We support only browsers with global usage statistics greater then 1% and last 2 version of each browser (but not dead browsers). Library may work in older browser as well but we don't not guarantee that. You may need addition polyfills to make it work.
I was using Vue-Socket.io
for few months. I've liked the idea, but the more I used it the more I faced with bugs, outdated documentation, lack of support, absence of tests and a huge amount of issues :disappointed:. That slowed down development of the product I was working on. So I ended up with a decision to create my own fork with all the desirable stuff (features/fixes/tests/support/CI checks etc). That's how vue-socket.io-extended
was born.
If you'd like to help - create an issue or PR. I will be glad to see any contribution. Let's make the world a better place :heart:
You must have a running Socket.IO server before starting any Vue/Socket.IO project! Instructions on how to build a Node/Socket.IO server are found here.
>=2.X
>=2.X
>=2.X
(optional)1npm install vue-socket.io-extended socket.io-client
1import VueSocketIOExt from 'vue-socket.io-extended'; 2import { io } from 'socket.io-client'; 3 4const socket = io('http://socketserver.com:1923'); 5 6Vue.use(VueSocketIOExt, socket);
Note: you have to pass instance of socket.io-client
as second argument to prevent library duplication. Read more here.
1<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script> 2<script src="https://cdn.jsdelivr.net/npm/socket.io-client/dist/socket.io.slim.js"></script> 3<script src="https://cdn.jsdelivr.net/npm/vue-socket.io-extended"></script> 4<script> 5 var socket = io('http://socketserver.com:1923'); 6 Vue.use(VueSocketIOExt, socket); 7</script>
Define your listeners under sockets
section and they will listen corresponding socket.io
events automatically.
1new Vue({ 2 sockets: { 3 connect() { 4 console.log('socket connected') 5 }, 6 customEmit(val) { 7 console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)') 8 } 9 }, 10 methods: { 11 clickButton(val) { 12 // this.$socket.client is `socket.io-client` instance 13 this.$socket.client.emit('emit_method', val); 14 } 15 } 16})
Note: Don't use arrow functions for methods or listeners if you are going to emit socket.io
events inside. You will end up with using incorrect this
. More info about this here
Create a new listener
1this.$socket.$subscribe('event_name', payload => {
2 console.log(payload)
3});
Remove existing listener
1this.$socket.$unsubscribe('event_name');
$socket.connected
and $socket.diconnected
are reactive. That means you can use them in expressions
1<template> 2 <div> 3 <span>{{ $socket.connected ? 'Connected' : 'Disconnected' }}</span> 4 </div> 5</template>
Or conditions
1<template> 2 <span 3 class="notification" 4 v-if="$socket.disconnected" 5 > 6 You are disconnected 7 </span> 8</template>
Or computed properties, methods and hooks. Treat them as computed properties that are available in all components
To set up Vuex integration just pass the store as the third argument. In a Vue CLI project, you might do this in the src/main.js
file. Example:
1import VueSocketIOExt from 'vue-socket.io-extended'; 2import { io } from 'socket.io-client'; 3import store from './store' 4 5const socket = io('http://socketserver.com:1923'); 6 7Vue.use(VueSocketIOExt, socket, { store });
Mutations and actions will be dispatched or committed automatically in the Vuex store when a socket event arrives. A mutation or action must follow the naming convention below to recognize and handle a socket event.
SOCKET_
prefix and continue with an uppercase version of the eventsocket_
prefix and continue with camelcase version of the eventServer Event | Mutation | Action |
---|---|---|
chat message | SOCKET_CHAT MESSAGE | socket_chatMessage |
chat_message | SOCKET_CHAT_MESSAGE | socket_chatMessage |
chatMessage | SOCKET_CHATMESSAGE | socket_chatMessage |
CHAT_MESSAGE | SOCKET_CHAT_MESSAGE | socket_chatMessage |
Check the Configuration section if you'd like to use a custom transformation.
Check the Migration from VueSocketIO section if you want to keep actions names in UPPER_CASE.
1// In this example we have a socket.io server that sends message ID when it arrives
2// so to get entire body of the message we need to make AJAX call the server
3import Vue from 'vue'
4import Vuex from 'vuex'
5
6// `MessagesAPI.downloadMessageById` is an async function (goes to backend through REST Api and fetches all message data)
7import MessagesAPI from './api/message'
8
9Vue.use(Vuex);
10
11export default new Vuex.Store({
12 state: {
13 // we store messages as a dictionary for easier access and interaction
14 // @see https://hackernoon.com/shape-your-redux-store-like-your-database-98faa4754fd5
15 messages: {},
16 messagesOrder: []
17 },
18 mutations: {
19 NEW_MESSAGE(state, message) {
20 state.messages[message.id] = message;
21 state.messagesOrder.push(message.id);
22 }
23 },
24 actions: {
25 socket_userMessage ({ dispatch, commit }, messageId) { // <-- this action is triggered when `user_message` is emmited on the server
26 return MessagesAPI.downloadMessageById(messageId).then((message) => {
27 commit('NEW_MESSAGE', message);
28 })
29 }
30 }
31})
Events can be sent to the Socket.IO server by calling this._vm.$socket.client.emit
from a Vuex mutation or action. Mutation or action names are not subject to the same naming requirements as above. More then one argument can be included. All serializable data structures are supported, including Buffer.
1 actions: { 2 emitSocketEvent(data) { 3 this._vm.$socket.client.emit('eventName', data); 4 this._vm.$socket.client.emit('with-binary', 1, '2', { 3: '4', 5: new Buffer(6) }); 5 } 6 }
Namespaced modules are supported out-of-the-box. Any appropriately-named mutation or action should work regardless of whether it's in a module or in the main Vuex store.
1import Vue from 'vue' 2import Vuex from 'vuex' 3 4Vue.use(Vuex); 5 6const messages = { 7 state: { 8 messages: [] 9 }, 10 mutations: { 11 SOCKET_CHAT_MESSAGE(state, message) { 12 state.messages.push(message); 13 } 14 }, 15 actions: { 16 socket_chatMessage() { 17 console.log('this action will be called'); 18 } 19 }, 20}; 21 22const notifications = { 23 state: { 24 notifications: [] 25 }, 26 mutations: { 27 SOCKET_CHAT_MESSAGE(state, message) { 28 state.notifications.push({ type: 'message', payload: message }); 29 } 30 }, 31}; 32 33export default new Vuex.Store({ 34 modules: { 35 messages, 36 notifications, 37 } 38})
The above code will:
SOCKET_CHAT_MESSAGE
mutation in the messages
moduleSOCKET_CHAT_MESSAGE
mutation in the notification
modulesocket_chatMessage
action in the messages
moduleRequired: ECMAScript stage 1 decorators.
If you use Babel, babel-plugin-transform-decorators-legacy is needed.
If you use TypeScript, enable --experimentalDecorators
flag.
It does not support the stage 2 decorators yet since mainstream transpilers still transpile to the old decorators.
We provide @Socket()
decorator for users of class-style Vue components. By default, @Socket()
decorator listens the same event as decorated method name but you can use custom name by passing a string inside decorator e.g. @Socket('custom_event')
.
Check the example below:
1<!-- App.vue --> 2<script> 3import Vue from 'vue' 4import Component from 'vue-class-component' 5import { Socket } from 'vue-socket.io-extended' 6 7@Component({}) 8export default class App extends Vue { 9 @Socket() // --> listens to the event by method name, e.g. `connect` 10 connect () { 11 console.log('connection established'); 12 } 13 14 @Socket('tweet') // --> listens to the event with given name, e.g. `tweet` 15 onTweet (tweetInfo) { 16 // do something with `tweetInfo` 17 } 18} 19</script>
The key point here is to disable SSR for the plugin as it will crash otherwise. It's a well-know issue and we are going to fix it. Thanks @ll931217 for investigation.
1. Create plugin:
1// ~/plugins/socket.io.js 2import Vue from 'vue'; 3import { io } from 'socket.io-client'; 4import VueSocketIOExt from 'vue-socket.io-extended'; 5 6const socket = io('http://localhost:3000'); 7 8export default ({ store }) => { 9 Vue.use(VueSocketIOExt, socket, { store }); 10}
2. Then register it:
1// nuxt.config.js 2module.exports = { 3 //..., 4 plugins: [ 5 //..., 6 { 7 src: '~/plugins/socket.io.js', 8 ssr: false, // <-- this line is required 9 }, 10 ] 11}
Register vue-socket.io-extended with a boot file and disable server side rendering
1. Create bootfile:
1// ~/boot/socket.io.js 2import { io } from 'socket.io-client'; 3import VueSocketIOExt from 'vue-socket.io-extended'; 4 5const socket = io('http://localhost:3000'); 6 7export default async ({ store, Vue }) => { 8 Vue.use(VueSocketIOExt, socket, { store }) 9}
2. Then register it:
1// quasar.conf.js 2module.exports = function (ctx) { 3 return { 4 //..., 5 boot: [ 6 //..., 7 { 8 path: 'socket.io', 9 server: false, 10 }, 11 ] 12}
In addition to store instance, vue-socket.io-extended
accepts other options.
Here they are:
Option | Type | Default | Description |
---|---|---|---|
store | Object | undefined | Vuex store instance, enables vuex integration |
actionPrefix | String | 'socket_' | Prepend to event name while converting event to action. Empty string disables prefixing |
mutationPrefix | String | 'SOCKET_' | Prepend to event name while converting event to mutation. Empty string disables prefixing |
eventToMutationTransformer | Function string => string | uppercase function | Determines how event name converted to mutation |
eventToActionTransformer | Function string => string | camelcase function | Determines how event name converted to action |
eventMapping | Function socket => string | Map your event from socket event data |
FYI: You can always access default plugin options if you need it (e.g. re-use default eventToActionTransformer
function):
1import VueSocketIOExt from 'vue-socket.io-extended'; 2VueSocketIOExt.defaults // -> { actionPrefix: '...', mutationPrefix: '...', ... }
For everyone who has migrated from old package VueSocketIO to this new one on existing project. You need to redefine 2 parameters so you will be able to use old store actions names like "SOCKET_EVENT_NAME".
1import VueSocketIO from 'vue-socket.io-extended'; 2import { io } from 'socket.io-client'; 3 4 5const ioInstance = io('https://hostname/path', { 6 reconnection: true, 7 reconnectionDelay: 500, 8 maxReconnectionAttempts: Infinity 9}); 10Vue.use(VueSocketIO, ioInstance, { 11 store, // vuex store instance 12 actionPrefix: 'SOCKET_', // keep prefix in uppercase 13 eventToActionTransformer: (actionName) => actionName // cancel camel case 14 } 15});
This plugin follows semantic versioning.
We're using GitHub Releases.
We're more than happy to see potential contributions, so don't hesitate. If you have any suggestions, ideas or problems feel free to add new issue, but first please make sure your question does not repeat previous ones.
See the LICENSE file for license rights and limitations (MIT).
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
project is archived
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
90 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More