-
-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <tukon479@gmail.com>
- Loading branch information
Showing
13 changed files
with
207 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
"tv\\(([^)]*)\\)", | ||
"[\"'`]([^\"'`]*).*?[\"'`]" | ||
] | ||
] | ||
], | ||
} |
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,2 @@ | ||
export * from './online' | ||
export * from './viewport' |
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,13 @@ | ||
import { atom, useAtomValue } from 'jotai' | ||
|
||
import { jotaiStore } from '~/lib/store' | ||
|
||
const onlineCountAtom = atom(0) | ||
|
||
export const setOnlineCount = (count: number) => { | ||
jotaiStore.set(onlineCountAtom, count) | ||
} | ||
|
||
export const useOnlineCount = () => { | ||
return useAtomValue(onlineCountAtom) | ||
} |
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 |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import { ThemeSwitcher } from '~/components/ui/theme-switcher' | ||
|
||
import { FooterInfo } from './FooterInfo' | ||
|
||
export const Footer = () => { | ||
return ( | ||
<footer className="relative z-[1] mt-32 border-t border-uk-separator-opaque-light bg-uk-grouped-primary-light py-6 dark:border-uk-separator-opaque-dark dark:bg-uk-grouped-secondary-dark"> | ||
<FooterInfo /> | ||
|
||
<div className="mt-6 block text-center md:absolute md:bottom-6 md:right-6 md:mt-0"> | ||
<ThemeSwitcher /> | ||
</div> | ||
</footer> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
'use client' | ||
|
||
import { useOnlineCount } from '~/atoms' | ||
|
||
export const GatewayCount = () => { | ||
return '1' | ||
return useOnlineCount() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client' | ||
|
||
import { createContext, useEffect } from 'react' | ||
|
||
import { socketClient } from '~/socket' | ||
|
||
const Context = createContext<typeof socketClient>(null as any) | ||
export const SocketProvider: Component = ({ children }) => { | ||
useEffect(() => { | ||
socketClient.initIO() | ||
}, []) | ||
|
||
return <Context.Provider value={socketClient}>{children}</Context.Provider> | ||
} |
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,20 @@ | ||
import { setOnlineCount } from '~/atoms' | ||
import { EventTypes } from '~/types/events' | ||
import { isDev } from '~/utils/env' | ||
|
||
export const eventHandler = (type: EventTypes, data: any) => { | ||
switch (type) { | ||
case EventTypes.VISITOR_ONLINE: | ||
case EventTypes.VISITOR_OFFLINE: { | ||
const { online } = data | ||
setOnlineCount(online) | ||
break | ||
} | ||
|
||
default: { | ||
if (isDev) { | ||
console.log(type, data) | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
export { socketClient } from './socket-client' |
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,67 @@ | ||
import { io } from 'socket.io-client' | ||
import type { EventTypes } from '~/types/events' | ||
import type { Socket } from 'socket.io-client' | ||
|
||
import { simpleCamelcaseKeys as camelcaseKeys } from '@mx-space/api-client' | ||
|
||
import { GATEWAY_URL } from '~/constants/env' | ||
import { isDev } from '~/utils/env' | ||
|
||
import { eventHandler } from './handler' | ||
|
||
class SocketClient { | ||
public socket!: Socket | ||
|
||
constructor() { | ||
this.socket = io(`${GATEWAY_URL}/web`, { | ||
timeout: 10000, | ||
reconnectionDelay: 3000, | ||
autoConnect: false, | ||
reconnectionAttempts: 3, | ||
transports: ['websocket'], | ||
}) | ||
} | ||
initIO() { | ||
if (!this.socket) { | ||
return | ||
} | ||
this.socket.close() | ||
this.socket.open() | ||
this.socket.on( | ||
'message', | ||
(payload: string | Record<'type' | 'data', any>) => { | ||
if (typeof payload !== 'string') { | ||
return this.handleEvent(payload.type, camelcaseKeys(payload.data)) | ||
} | ||
const { data, type } = JSON.parse(payload) as { | ||
data: any | ||
type: EventTypes | ||
} | ||
this.handleEvent(type, camelcaseKeys(data)) | ||
}, | ||
) | ||
} | ||
reconnect() { | ||
this.socket.open() | ||
} | ||
handleEvent(type: EventTypes, data: any) { | ||
if (isDev) { | ||
console.log(data) | ||
} | ||
|
||
window.dispatchEvent(new CustomEvent(type, { detail: data })) | ||
|
||
eventHandler(type, data) | ||
} | ||
emit(event: EventTypes, payload: any) { | ||
return new Promise((resolve) => { | ||
if (this.socket && this.socket.connected) { | ||
this.socket.emit(event, payload, (payload: any) => { | ||
resolve(payload) | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export const socketClient = new SocketClient() |
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,30 @@ | ||
export enum EventTypes { | ||
GATEWAY_CONNECT = 'GATEWAY_CONNECT', | ||
GATEWAY_DISCONNECT = 'GATEWAY_DISCONNECT', | ||
|
||
VISITOR_ONLINE = 'VISITOR_ONLINE', | ||
VISITOR_OFFLINE = 'VISITOR_OFFLINE', | ||
|
||
AUTH_FAILED = 'AUTH_FAILED', | ||
|
||
COMMENT_CREATE = 'COMMENT_CREATE', | ||
|
||
POST_CREATE = 'POST_CREATE', | ||
POST_UPDATE = 'POST_UPDATE', | ||
POST_DELETE = 'POST_DELETE', | ||
|
||
NOTE_CREATE = 'NOTE_CREATE', | ||
NOTE_UPDATE = 'NOTE_UPDATE', | ||
NOTE_DELETE = 'NOTE_DELETE', | ||
|
||
PAGE_UPDATED = 'PAGE_UPDATED', | ||
|
||
SAY_CREATE = 'SAY_CREATE', | ||
SAY_DELETE = 'SAY_DELETE', | ||
SAY_UPDATE = 'SAY_UPDATE', | ||
|
||
DANMAKU_CREATE = 'DANMAKU_CREATE', | ||
|
||
RECENTLY_CREATE = 'RECENTLY_CREATE', | ||
RECENTLY_DElETE = 'RECENTLY_DElETE', | ||
} |
fa8d704
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:
springtide – ./
springtide-innei.vercel.app
springtide.vercel.app
springtide-git-main-innei.vercel.app