Skip to content

Commit b4f2cb8

Browse files
committed
chore: remove useSocket and update readme
1 parent bbfef37 commit b4f2cb8

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ export default defineNuxtConfig({
3030

3131
```vue
3232
<script setup>
33-
// Default
34-
const socket = useSocket()
33+
const { $io } = useNuxtApp()
3534
3635
const connected = ref(false)
3736
3837
onMounted(() => {
38+
const socket = $io('http://localhost:3000')
39+
3940
socket.on('connect', () => {
4041
connected.value = socket.connected
4142
})
@@ -44,13 +45,6 @@ onMounted(() => {
4445
connected.value = socket.connected
4546
})
4647
})
47-
48-
// Custom
49-
const { $io } = useNuxtApp()
50-
51-
onMounted(() => {
52-
const socket2 = $io('http://localhost:3069')
53-
})
5448
</script>
5549
5650
<template>

src/module.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import fg from 'fast-glob'
55
import { Server as SocketServer, type ServerOptions } from 'socket.io'
66

77
export interface ModuleOptions {
8-
addPlugin: boolean
98
serverOptions: Partial<ServerOptions>
109
}
1110

@@ -15,7 +14,6 @@ export default defineNuxtModule<ModuleOptions>({
1514
configKey: 'socket',
1615
},
1716
defaults: {
18-
addPlugin: true,
1917
serverOptions: {},
2018
},
2119
async setup(options, nuxt) {
@@ -74,20 +72,12 @@ export default defineNuxtModule<ModuleOptions>({
7472
})
7573
}
7674

77-
if (options.addPlugin) {
78-
addPlugin(resolve(runtimeDir, 'plugin.client'))
79-
80-
addImports([
81-
{
82-
name: 'useSocket',
83-
from: resolve(runtimeDir, 'composables'),
84-
},
85-
{
86-
name: 'useIO',
87-
from: resolve(runtimeDir, 'composables'),
88-
},
89-
])
90-
}
75+
addPlugin(resolve(runtimeDir, 'plugin.client'))
76+
77+
addImports({
78+
name: 'useIO',
79+
from: resolve(runtimeDir, 'composables'),
80+
})
9181

9282
addServerHandler({
9383
middleware: true,

src/runtime/plugin.client.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { defineNuxtPlugin } from '#app'
22

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

7-
nuxtApp.provide('socket', socket)
86
nuxtApp.provide('io', io)
97
})
108

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

0 commit comments

Comments
 (0)