nathantsoi / vue-native-websocket

native websocket with vuex integration
943 stars 162 forks source link

Manuall connection doesn't work with nuxt #96

Open IngvarListard opened 5 years ago

IngvarListard commented 5 years ago

I'm using Nuxt and manual socket connection management seems not working to me. Methods .$connect and .$disconnect just doesn't appear in the context.

To reproduce I've installed the plugin like documentation of nuxt and vue-native-websocket says:

// nuxt.config.js
plugins: [
  { src: '@/plugins/vue-native-websocket.js', ssr: false },
],
// @/plugins/vue-native-websocket.js
import Vue from 'vue'
import VueNativeSock from 'vue-native-websocket'

export default ({ store }, inject) => {
  Vue.use(VueNativeSock, 'ws://localhost:8000/ws/notifications/room1/', {
    format: 'json',
    reconnection: true,
    reconnectionAttempts: 5,
    reconnectionDelay: 3000,
    store: store,
    connectManually: true
  })
}

Am I doing something wrong?

Amaurgit commented 5 years ago

Have you tried connecting withthis._vm.$connect('ws://localhost:8000/ws/notifications/room1/') ? 😄

mjmnagy commented 4 years ago

Having the same issue

Essentially want to make sure that i can create separate endpoints therefore wanting to connect manually and set the end points

@Amaurgit this yields a type error

fredrikasberg commented 4 years ago

Using Vue.prototype.$connect() works

KashyapFero commented 3 years ago

@fredrikasberg

Having the same issue. How to connect manually from a component? Using "this.$connect()" throws an error that it's not defined. Even "Vue.prototype.connect()" throws the same error.

Cannot read property '$connect' of undefined