MetinSeylan / Vue-Socket.io

😻 Socket.io implementation for Vuejs and Vuex
https://metin.sh
MIT License
3.95k stars 499 forks source link

Anybody get this work with antfu/vitesse boiler plate? #328

Closed travbus closed 2 years ago

travbus commented 2 years ago

Frustrating. Getting back into coding and a vue 3 type script newbie. Very hard to get things working it seems I'm thinking of ditching it at this point. Here is my issue. I do have the latest dependency files from this repo installed. Still getting this error. I have no other code in the app other then these photos. I did not modify main.ts from boiler plate. I just added a new module file. Willing to donate some dollars to anybody with a solution.

Uncaught (in promise) TypeError: Cannot set properties of undefined (setting '$socket')

Screen Shot 2022-02-23 at 2 19 00 PM Screen Shot 2022-02-23 at 2 19 09 PM Screen Shot 2022-02-23 at 2 19 26 PM
travbus commented 2 years ago

While I never got this vue-socket.io to work i did get socket.io-client to work

this is in my user module

import type { UserModule } from '~/types'

import { io } from 'socket.io-client';

const options = {
        //path: '/test/',
       transports: ['websocket'],
        forceNew: true,
         auth: {
         token: "TOKEN 123"
         }
     }

export const install: UserModule = ({ app }) => {

   const socket = io('http://localhost:3000',options);
    app.config.globalProperties.$socket = socket;

    app.provide('socket', socket);

}

this is in my component

<script setup lang="ts">

import { ref,inject } from 'vue';
const socket:any = inject('socket');

 socket.on("testListener", (data:any) => {
      console.log(data);
    });

   const test = () =>{
     socket.emit("test", 5);
   }