You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<scriptsetup>
import {onMounted,inject} from "vue";
import {useSocketIO} from "@hlf01/vue3-socket.io";
const socketIO = useSocketIO();
const socket = inject("socket");
onMounted(() =>{socketIO.subscribe("connect",()=>{console.log("Socket connected:",socket.id);});// Custom event namesocketIO.subscribe("getMessages",(messages)=>{console.log("Received messages:",messages);});});
// All event listeners will be unsubscribed automatically once the component is unmounted
function unsubscribeEvent(eventName) {// Unsubscribe event for current instancesocketIO.unsubscribe(eventName);}
function removeEvent(eventName) {// Unsubscribe event for all instancesocketIO.removeEvent(eventName);}
function sendMessage(message) {// Emit eventsocket.emit("sendMessage",message);}</script>