All Projects → joe-re → Vuex Socketio Plugin

joe-re / Vuex Socketio Plugin

Licence: mit
Vuex plugin to integrate socket.io client

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Vuex Socketio Plugin

Vue Chat
📲 A web chat application. Vue + node(koa2) + Mysql + socket.io
Stars: ✭ 617 (+1714.71%)
Mutual labels:  websocket, vuex, socket-io
Vue Socket.io
😻 Socket.io implementation for Vuejs and Vuex
Stars: ✭ 3,746 (+10917.65%)
Mutual labels:  websocket, vuex, socket-io
Dokit
基于 Spring Boot2、 Jpa、 Spring Security、JWT、redis、Vue的前后端分离的后台管理系统开发平台, 用户管理、菜单管理、角色管理、字典管理、权限控制的方式为RBAC,操作日志、异常日志、接口限流、项目支持数据权限管理,支持一键生成前后端代码(支持在线预览及打包下载),支持前端菜单动态路由 可一键部署服务器应用,数据库。系统中活跃用户状态监控,监视当前系统CPU、内存、磁盘、堆栈等相关信息,基于Element UI在线表单设计及生成Vue代码。
Stars: ✭ 348 (+923.53%)
Mutual labels:  websocket, vuex
Laravel Swoole
High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
Stars: ✭ 3,726 (+10858.82%)
Mutual labels:  websocket, socket-io
Socket.io Unity
socket.io client for Unity, power game client with node.js back-end
Stars: ✭ 396 (+1064.71%)
Mutual labels:  websocket, socket-io
Vue Project
基于vue-cli构建的财务后台管理系统(vue2+vuex+axios+vue-router+element-ui+echarts+websocket+vue-i18n)
Stars: ✭ 301 (+785.29%)
Mutual labels:  websocket, vuex
Socket.io Client Dart
socket.io-client-dart: Dartlang port of socket.io-client https://github.com/socketio/socket.io-client
Stars: ✭ 333 (+879.41%)
Mutual labels:  websocket, socket-io
Vue Chatroom
Vue全家桶 + socket.io + express 搭建的聊天室+ 智能问答助手
Stars: ✭ 27 (-20.59%)
Mutual labels:  vuex, socket-io
Cuckoo
🎥 Cuckoo - A free anonymous video-calling web application built with WebRTC and React that provides peer-to-peer video and audio communication in a web browser with no plugins or extensions required.
Stars: ✭ 195 (+473.53%)
Mutual labels:  websocket, socket-io
Vue Socket.io Extended
✌️⚡️ Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
Stars: ✭ 506 (+1388.24%)
Mutual labels:  vuex, socket-io
Netty Socketio
Socket.IO server implemented on Java. Realtime java framework
Stars: ✭ 5,565 (+16267.65%)
Mutual labels:  websocket, socket-io
Socket.io
NodeJS《你画我猜》游戏
Stars: ✭ 255 (+650%)
Mutual labels:  websocket, socket-io
Egg Socket.io
socket.io plugin for eggjs.
Stars: ✭ 209 (+514.71%)
Mutual labels:  websocket, socket-io
Vue Qq
🎨 Vue family bucket with socket.io and express/koa2 , create a web version of mobile QQ, supporting real-time group chat, real-time private chat, special care, shielding chat, smart IP geographic location, real-time display temperature and other QQ core functions
Stars: ✭ 861 (+2432.35%)
Mutual labels:  vuex, socket-io
Python Socketio
Python Socket.IO server and client
Stars: ✭ 2,655 (+7708.82%)
Mutual labels:  websocket, socket-io
Wssip
Application for capturing, modifying and sending custom WebSocket data from client to server and vice versa.
Stars: ✭ 373 (+997.06%)
Mutual labels:  websocket, socket-io
Flutter socket io
Socket IO supprt for flutter. Looking for contributors Swift and Java.
Stars: ✭ 170 (+400%)
Mutual labels:  websocket, socket-io
Wechat
聊天系统、Vue.js、React.js、node.js、MongoDB、websocket、socket.io、前后端分离、毕业设计。
Stars: ✭ 188 (+452.94%)
Mutual labels:  websocket, socket-io
Flask Socketio
Socket.IO integration for Flask applications.
Stars: ✭ 4,523 (+13202.94%)
Mutual labels:  websocket, socket-io
Websocket Chat
Websocket based group chat app built with socket.io and react.
Stars: ✭ 689 (+1926.47%)
Mutual labels:  websocket, socket-io

vuex-socketio-plugin

Vuex plugin to integrate socket.io client

Install

npm install vuex-socketio-plugin --save

Simple Example

store.ts

import Vuex, { Store } from 'vuex'
import Vue from 'vue'
import { createSocketioPlugin } from 'vuex-socketio-plugin'
import * as io from 'socket.io-client'

Vue.use(Vuex)

let _client: (typeof io.Socket) | null = null;
export type State = { messages: string[] }
const store = new Vuex.Store<State>({
  plugins: [createSocketioPlugin('http://localhost:3000')],
  state: {
    messages: []
  },
  mutations: {
    SOCKET_CONNECT(state, { client }) {
      console.log('connected')
      _client = client;
    },
    SOCKET_CHAT_MESSAGE(state, { data }) {
      state.messages = state.messages.concat([data[0]])
    }
  },
  actions: {
    postMessage(context, payload: { message: string }) {
      if (!_client) {
        throw new Error("don't have connection")
      }
      _client.emit('CHAT_MESSAGE', payload.message)
    }
  }
})

export default store

Usage

createSocketioPlugin

Creates a new instance of the plugin. You can give an URL string or custom socket.io-client instance.

createSocketioPlugin('http://localhost:3000') // apply default as socket-io(auto-connect)
createSocketioPlugin(io('http://localhost:3000', { autoConnect: false }) // if you want to customize you can give any socket.io instance

If you want to use multi connection, you can give an array of it.

createSocketioPlugin([
  'http://localhost:3000/function1',
  'http://localhost:3000/function2',
  'http://localhost:3000/function3'
])

Prefix are set automatically to each Mutation and Action.(See Mutation And Action) If you want to change prefix name, you can give actionPrefix and mutationPrefix options.

createSocketioPlugin([
  'http://localhost:3000/function1',
  'http://localhost:3000/function2',
  'http://localhost:3000/function3'
], {
  actionPrefix: 'socket/soc_',
  mutationPrefix: 'socket/SOC_'
})

Mutation and Action

When receive SocketIO event, vuex-socketio-plugin triggered Mutation and Action. MutationName is added prefix SOCKET_. ActionName is added prefix socket_. MutationName and ActionName are prefix + EventName.

  mutations: {
    SOCKET_CONNECT(state, payload) {
      console.log('connected on mutation')
    },
  },
  actions: {
    socket_connect(context, payload) {
      console.log('connected on action')
    }
  }

Note: In case of mutation, default socket.io events are UpperCase. Pleae ref socket.io docs about type of default events.

Both of mutation and action payload includes client and data parameters. client is socket.io instance. You can emit any event via this. data is received message. It is always array type.

Socket.io Namespaces and Vuex Namespaced Modules

Socket.io namespaces is mapped Vuex namespaced Modules.

If you use socket.io namespaces, you can receive which one of below types.

{
  plugins: [
    createSocketioPlugin('http://localhost:3000/bar')
  ],
  mutations: {
    SOCKET_CONNECT: { ... } // default
    SOCKET_bar_CONNECT: { ... } // prefix + namespace + event name
  },
  modules: {
    bar: {
      SOCKET_CONNECT: { ... } // namespaced module + prefix + event name
    }
  }
}

Because this is a convention you don't have to set any configtation. It is triggered to be found mutation and action at first.

getClients

If you get socket.io clients on your any context, you can use getClients API.

Example

import { getClients } from 'vuex-socketio-plugin'
getClients().forEach(v => v.connect())

Example

example

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].