Skip to content

Commit

Permalink
chore: remove useSocket and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Nov 11, 2024
1 parent bbfef37 commit b4f2cb8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export default defineNuxtConfig({

```vue
<script setup>
// Default
const socket = useSocket()
const { $io } = useNuxtApp()
const connected = ref(false)
onMounted(() => {
const socket = $io('http://localhost:3000')
socket.on('connect', () => {
connected.value = socket.connected
})
Expand All @@ -44,13 +45,6 @@ onMounted(() => {
connected.value = socket.connected
})
})
// Custom
const { $io } = useNuxtApp()
onMounted(() => {
const socket2 = $io('http://localhost:3069')
})
</script>
<template>
Expand Down
22 changes: 6 additions & 16 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fg from 'fast-glob'
import { Server as SocketServer, type ServerOptions } from 'socket.io'

export interface ModuleOptions {
addPlugin: boolean
serverOptions: Partial<ServerOptions>
}

Expand All @@ -15,7 +14,6 @@ export default defineNuxtModule<ModuleOptions>({
configKey: 'socket',
},
defaults: {
addPlugin: true,
serverOptions: {},
},
async setup(options, nuxt) {
Expand Down Expand Up @@ -74,20 +72,12 @@ export default defineNuxtModule<ModuleOptions>({
})
}

if (options.addPlugin) {
addPlugin(resolve(runtimeDir, 'plugin.client'))

addImports([
{
name: 'useSocket',
from: resolve(runtimeDir, 'composables'),
},
{
name: 'useIO',
from: resolve(runtimeDir, 'composables'),
},
])
}
addPlugin(resolve(runtimeDir, 'plugin.client'))

addImports({
name: 'useIO',
from: resolve(runtimeDir, 'composables'),
})

addServerHandler({
middleware: true,
Expand Down
3 changes: 0 additions & 3 deletions src/runtime/plugin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import { defineNuxtPlugin } from '#app'

export default defineNuxtPlugin(async (nuxtApp) => {
const { io } = await import('socket.io-client')
const socket = io()

nuxtApp.provide('socket', socket)
nuxtApp.provide('io', io)
})

declare module '#app' {
interface NuxtApp {
$io: typeof import('socket.io-client')['io']
$socket: ReturnType<typeof import('socket.io-client')['io']>
}
}

0 comments on commit b4f2cb8

Please sign in to comment.