nathantsoi/vue-native-websocket

How to: connectManually /w TypeScript, vuex and via button

DerKatzeLP opened this issue · 0 comments

Hello,

I am really new to vue and vuex and found this amazing plugin here.
When i use it (with JSON Format and Store ...) with automatic connection, everything works fine. But this is not what i need in the future.

As far as i understand the readme, it should go like this (my main.ts):

import VueNativeSock from 'vue-native-websocket';
import Vue from 'vue';
import App from './App.vue';
import store from './store';
import router from './router';

Vue.config.productionTip = false;

Vue.use(VueNativeSock, 'wss://echo.websocket.org', {
  store,
  format: 'json',
  connectManually: true,
});

const vm = new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');

and now it says to add the line
vm.$connect()
and it should work just fine. But it there is an error saying that $connect is no property.

Further more i need to connect via a mutation in the store like this

mutations: {
    SOCKET_CONNECT() {
      //connect command here
      console.log('SOCKET: connecting...');
    },

to use a button on the actual page to connect to a websocket.

Can someone please tell me what i haven't understood yet?
How to get this working?

Thank you =)