Skip to content

Commit a85f689

Browse files
committed
created playground application
1 parent c8bf353 commit a85f689

File tree

5 files changed

+108
-3
lines changed

5 files changed

+108
-3
lines changed

playground/app.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<template>
2-
<div>Nuxt module playground!</div>
2+
<NuxtLayout>
3+
<NuxtPage />
4+
</NuxtLayout>
35
</template>
46

57
<script setup></script>

playground/error.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
interface ErrorProps {
3+
error?: {
4+
url: string
5+
statusCode: number
6+
statusMessage: string
7+
message: string
8+
description: string
9+
data?: object
10+
}
11+
}
12+
13+
const props = defineProps<ErrorProps>()
14+
</script>
15+
16+
<template>
17+
<NuxtLoadingIndicator />
18+
19+
<h1>Nuxt - Laravel Echo application sample</h1>
20+
21+
<strong>Error</strong>
22+
23+
<p>{{ props.error }}</p>
24+
</template>
25+
26+
<style scoped></style>

playground/layouts/default.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts"></script>
2+
3+
<template>
4+
<h1>Laravel Echo - Sample application</h1>
5+
6+
<div>
7+
<slot />
8+
</div>
9+
</template>
10+
11+
<style scoped></style>

playground/nuxt.config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export default defineNuxtConfig({
2-
modules: ['../src/module'],
3-
echo: {},
42
devtools: { enabled: true },
53
compatibilityDate: '2024-07-03',
4+
5+
modules: ['../src/module'],
6+
7+
echo: {
8+
key: '9iaau1cgc7iqdt6ee97m',
9+
scheme: 'http',
10+
},
611
})

playground/pages/index.vue

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script setup lang="ts">
2+
const echo = useEcho()
3+
4+
const messages = ref<string[]>([])
5+
const writeNewMessage = (e: object) => messages.value.push(JSON.stringify(e))
6+
7+
function stopAllListeners() {
8+
echo.leaveAllChannels()
9+
}
10+
11+
function subscribeToPublicChannel() {
12+
const name = 'public'
13+
const event = '.PublicEvent'
14+
15+
echo
16+
.channel(name)
17+
.listen(event, (e: object) => writeNewMessage(e))
18+
.error((e: object) => {
19+
console.error('Public channel error', e)
20+
})
21+
}
22+
23+
function subscribeToPrivateChannel() {
24+
const name = 'users'
25+
const event = '.PrivateEvent'
26+
27+
echo
28+
.private(name)
29+
.listen(event, (e: object) => writeNewMessage(e))
30+
.error((e: object) => {
31+
console.error('Private channel error', e)
32+
})
33+
}
34+
</script>
35+
36+
<template>
37+
<div>
38+
<button @click="subscribeToPublicChannel">
39+
Subscribe to public channel
40+
</button>
41+
<button @click="subscribeToPrivateChannel">
42+
Subscribe to private channel
43+
</button>
44+
<button @click="stopAllListeners">
45+
Stop all listeners
46+
</button>
47+
</div>
48+
<div>
49+
<h2>Message history</h2>
50+
<ol>
51+
<li
52+
v-for="message in messages"
53+
:key="message"
54+
>
55+
{{ message }}
56+
</li>
57+
</ol>
58+
</div>
59+
</template>
60+
61+
<style scoped></style>

0 commit comments

Comments
 (0)