3.0.13 • Published 2 years ago

nuxt-socket-io v3.0.13

Weekly downloads
2,003
License
MIT
Repository
github
Last release
2 years ago

npm npm GitHub Workflow Status npm.io NPM

📖 Release Notes

nuxt-socket-io

Socket.io client and server module for Nuxt

Features

  • Configuration of multiple IO sockets
  • Configuration of per-socket namespaces (simplified format)
  • Automatic IO Server Registration
  • Socket IO Status
  • Automatic Error Handling
  • Debug logging, enabled with localStorage item 'debug' set to 'nuxt-socket-io'
  • Automatic Teardown, enabled by default
  • $nuxtSocket vuex module and socket persistence in vuex
  • Support for dynamic APIs using the KISS API format
  • Support for the IO config in the new Nuxt runtime config (for Nuxt versions >= 2.13)
  • Automatic middleware registration
  • ES module
  • Experimental support for ioRedis

Important updates

  • v3.x has been tested against Nuxt3 stable and socket.io@4.1.1. If you absolutely require socket.io@4.5.3 it's recommended to install it and follow the workaround.
  • v2.x may contain breaking changes in it's attempt to get Nuxt3 reaady. npm i nuxt-socket@1 should help revert any breaking changes in your code.
    • VuexOpts types and Namespace configuration types changed. Entries with the Record<string, string> have been deprecated in favor of string-only entries, which are easier to work with.
    • Package type is now "module". Entirely ESM.
    • Tested against node lts (16.x).
  • v1.1.17+ uses socket.io 4.x. You may find the migration here
  • v1.1.14+ uses socket.io 3.x. You may find the migration here
  • v1.1.13 uses socket.io 2.x.

Setup

  1. Add nuxt-socket-io dependency to your project
  • Nuxt 3.x:
npm i nuxt-socket-io
  • Nuxt 2.x:
npm i nuxt-socket-io@2
  1. Add nuxt-socket-io to the modules section of nuxt.config.js
{
  modules: [
    'nuxt-socket-io',
  ],
  io: {
    // module options
    sockets: [{
      name: 'main',
      url: 'http://localhost:3000'
    }]
  }
}
  1. Use it in your components:
{
  mounted() {
    this.socket = this.$nuxtSocket({
      channel: '/index'
    })
    /* Listen for events: */
    this.socket
    .on('someEvent', (msg, cb) => {
      /* Handle event */
    })
  },
  methods: {
    method1() {
      /* Emit events */
      this.socket.emit('method1', {
        hello: 'world' 
      }, (resp) => {
        /* Handle response, if any */
      })
    }
  }
}

Documentation

But WAIT! There's so much more you can do!! Check out the documentation:

https://nuxt-socket-io.netlify.app/

There you will see:

  • More details about the features, configuration and usage

Resources

  • Follow me and the series on medium.com
  • Socket.io Client docs here
  • Socket.io Server docs here

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using yarn dev or npm run dev
3.0.13

2 years ago

3.0.12

3 years ago

3.0.10

3 years ago

3.0.11

3 years ago

3.0.8

3 years ago

3.0.7

3 years ago

3.0.9

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.0

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.16

4 years ago

1.1.17

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago