-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add presence indicator (#1327)
- Loading branch information
Showing
7 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<template> | ||
<div | ||
class="fixed bottom-[1rem] right-[1rem] p-1 bg-background rounded-full overflow-hidden z-10" | ||
> | ||
<component | ||
:is="status === 'live' ? 'a' : 'span'" | ||
:href="status === 'live' ? 'https://twitch.tv/danielroe' : null" | ||
:target="status === 'live' ? '_blank' : null" | ||
class="pl-2 pr-2 py-1 rounded-full flex flex-row items-center shadow tracking-none border-1 text-xs transition-opacity" | ||
:class="colorSet[status].badge" | ||
:title=" | ||
status === 'live' ? 'Live now on Twitch' : `${count} viewers on website` | ||
" | ||
> | ||
<span | ||
class="rounded-full inline-block h-2 w-2 animate-pulse shadow" | ||
:class="colorSet[status].block" | ||
/> | ||
<span | ||
class="ml-2 tabular-nums flex flex-row items-center gap-1 font-bold uppercase tracking-wider" | ||
> | ||
<template v-if="status === 'live'"> live now </template> | ||
<template v-else> | ||
{{ count || ' ' }} | ||
<span v-if="count" class="sr-only">viewers on website</span> | ||
</template> | ||
</span> | ||
​ | ||
</component> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import PartySocket from 'partysocket' | ||
const colorSet = { | ||
live: { | ||
badge: | ||
'light:border-red-800 dark:border-red-400 light:shadow-red-400 dark:shadow-red-800 text-red-400 light:text-red-800', | ||
block: 'light:bg-red-800 dark:bg-red dark:shadow-red-800', | ||
}, | ||
default: { | ||
badge: | ||
'light:border-green-800 dark:border-green-400 light:shadow-green-400 dark:shadow-green-800 opacity-50 hover:opacity-100 focus:opacity-100', | ||
block: 'light:bg-green-800 dark:bg-green dark:shadow-green-800', | ||
}, | ||
} | ||
const status = ref<keyof typeof colorSet>('default') | ||
const count = ref<null | number>(null) | ||
if (import.meta.client) { | ||
const partySocket = new PartySocket({ | ||
host: import.meta.dev ? 'localhost:1999' : 'v.danielroe.partykit.dev', | ||
room: 'site', | ||
}) | ||
partySocket.onmessage = evt => { | ||
const data = evt.data as string | ||
const [type, value] = data.split(':') | ||
if (type === 'connections') { | ||
count.value = parseInt(value) | ||
} | ||
} | ||
onBeforeUnmount(() => partySocket.close()) | ||
onDeactivated(() => partySocket.close()) | ||
onActivated(() => partySocket.reconnect()) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6734a7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
roe.dev – ./
danielroe.me
danielcroe.com
danielroe.com
nuxt.ninja
iocalho.st
roe.dev
www.nuxt.ninja
www.danielroe.me
www.danielroe.com
www.danielcroe.com
roedev-danielroe.vercel.app
roedev-git-main-danielroe.vercel.app