This commit is contained in:
Binary file not shown.
3
client/app/components.d.ts
vendored
3
client/app/components.d.ts
vendored
@@ -15,6 +15,8 @@ declare module 'vue' {
|
||||
PrimeCard: typeof import('primevue/card')['default']
|
||||
PrimeDivider: typeof import('primevue/divider')['default']
|
||||
PrimeFloatLabel: typeof import('primevue/floatlabel')['default']
|
||||
PrimeInputGroup: typeof import('primevue/inputgroup')['default']
|
||||
PrimeInputGroupAddon: typeof import('primevue/inputgroupaddon')['default']
|
||||
PrimeInputText: typeof import('primevue/inputtext')['default']
|
||||
PrimePassword: typeof import('primevue/password')['default']
|
||||
PrimeProgressBar: typeof import('primevue/progressbar')['default']
|
||||
@@ -23,6 +25,7 @@ declare module 'vue' {
|
||||
PrimeSelectButton: typeof import('primevue/selectbutton')['default']
|
||||
PrimeSlider: typeof import('primevue/slider')['default']
|
||||
PrimeTag: typeof import('primevue/tag')['default']
|
||||
PrimeTextarea: typeof import('primevue/textarea')['default']
|
||||
PrimeToast: typeof import('primevue/toast')['default']
|
||||
PrimeToggleSwitch: typeof import('primevue/toggleswitch')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
|
||||
55
client/app/composables/use-chat.ts
Normal file
55
client/app/composables/use-chat.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { createGlobalState } from '@vueuse/core'
|
||||
|
||||
export interface ChatClientMessage {
|
||||
text: string
|
||||
replyTo?: {
|
||||
messageId: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
sender: string
|
||||
text: string
|
||||
createdAt: string
|
||||
replyTo?: {
|
||||
messageId: string
|
||||
sender: string
|
||||
text: string
|
||||
}
|
||||
}
|
||||
|
||||
export const useChat = createGlobalState(() => {
|
||||
const signaling = useSignaling()
|
||||
const { emit } = useEventBus()
|
||||
|
||||
const messages = shallowRef<ChatMessage[]>([])
|
||||
|
||||
watch(signaling.socket, (socket) => {
|
||||
if (!socket)
|
||||
return
|
||||
|
||||
socket.on('chat:new-message', (message: ChatMessage) => {
|
||||
messages.value.push(message)
|
||||
triggerRef(messages)
|
||||
|
||||
emit('chat:new-message')
|
||||
})
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
messages.value = []
|
||||
})
|
||||
}, { immediate: true })
|
||||
|
||||
function sendMessage(message: ChatClientMessage) {
|
||||
if (!signaling.connected.value)
|
||||
return
|
||||
|
||||
signaling.socket.value!.emit('chat:message', message)
|
||||
}
|
||||
|
||||
return {
|
||||
messages,
|
||||
sendMessage,
|
||||
}
|
||||
})
|
||||
@@ -29,6 +29,8 @@ export interface AppEvents extends Record<EventType, unknown> {
|
||||
'video:disabled': void
|
||||
'share:enabled': void
|
||||
'share:disabled': void
|
||||
|
||||
'chat:new-message': void
|
||||
}
|
||||
|
||||
const emitter = mitt<AppEvents>()
|
||||
|
||||
@@ -15,7 +15,7 @@ function hashStringToNumber(str: string, cap: number): number {
|
||||
|
||||
const oneShots: Howl[] = []
|
||||
|
||||
type SfxEvent = 'mic-on' | 'mic-off' | 'stream-on' | 'stream-off' | 'connection'
|
||||
type SfxEvent = 'mic-on' | 'mic-off' | 'stream-on' | 'stream-off' | 'connection' | 'message'
|
||||
|
||||
const EVENT_VOLUME: Record<SfxEvent, number> = {
|
||||
'mic-on': 0.2,
|
||||
|
||||
@@ -66,7 +66,7 @@ export const useSignaling = createSharedComposable(() => {
|
||||
|
||||
const uri = host ? `${protocol}//${host}` : ``
|
||||
|
||||
socket.value = io(`${uri}/webrtc`, {
|
||||
socket.value = io(uri, {
|
||||
path: `${pathname}/ws`,
|
||||
transports: ['websocket'],
|
||||
withCredentials: true,
|
||||
|
||||
@@ -56,11 +56,9 @@
|
||||
</div>
|
||||
</PrimeScrollPanel>
|
||||
|
||||
<PrimeScrollPanel class="bg-surface-900 rounded-xl overflow-hidden" style="min-height: 0">
|
||||
<div class="p-3">
|
||||
<div class="bg-surface-900 rounded-xl overflow-hidden p-3 flex flex-col min-h-full">
|
||||
<slot />
|
||||
</div>
|
||||
</PrimeScrollPanel>
|
||||
</div>
|
||||
|
||||
<FullscreenGallery />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="grid grid-cols-[1fr_1fr] gap-2">
|
||||
<PrimeScrollPanel class="grid grid-cols-[1fr_1fr] gap-2 min-h-0">
|
||||
<GalleryCard
|
||||
v-for="producer in producers"
|
||||
:key="`producer-${producer.id}`"
|
||||
@@ -13,7 +13,7 @@
|
||||
:client="consumer.client"
|
||||
:consumer="consumer.consumer"
|
||||
/>
|
||||
</div>
|
||||
</PrimeScrollPanel>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@@ -1,17 +1,85 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="flex items-center justify-center">
|
||||
<PrimeCard>
|
||||
<template #content>
|
||||
The chat is under development.
|
||||
</template>
|
||||
</PrimeCard>
|
||||
<PrimeScrollPanel class="flex-1 min-h-0">
|
||||
<div v-auto-animate class="flex flex-col gap-3">
|
||||
<div
|
||||
v-for="message in messages"
|
||||
:key="message.id"
|
||||
class="min-w-64 w-fit max-w-[60%]"
|
||||
:class="{
|
||||
'ml-auto': message.sender === me?.username,
|
||||
}"
|
||||
>
|
||||
<p
|
||||
v-if="message.sender !== me?.username"
|
||||
class="text-sm text-muted-color mb-1"
|
||||
>
|
||||
{{ message.sender }}
|
||||
</p>
|
||||
|
||||
<div
|
||||
class="px-2 py-1 rounded-lg"
|
||||
:class="{
|
||||
'bg-surface-800': message.sender !== me?.username,
|
||||
'bg-surface-700': message.sender === me?.username,
|
||||
}"
|
||||
>
|
||||
<p v-html="parseMessageText(message.text)" />
|
||||
<p class="text-right text-sm text-muted-color">
|
||||
{{ formatDate(message.createdAt) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PrimeScrollPanel>
|
||||
|
||||
<div class="pt-3 mt-auto">
|
||||
<PrimeInputGroup>
|
||||
<!-- <PrimeInputGroupAddon> -->
|
||||
<!-- <PrimeButton severity="secondary" class="shrink-0" disabled> -->
|
||||
<!-- <template #icon> -->
|
||||
<!-- <Paperclip /> -->
|
||||
<!-- </template> -->
|
||||
<!-- </PrimeButton> -->
|
||||
<!-- </PrimeInputGroupAddon> -->
|
||||
|
||||
<PrimeInputText v-model="text" placeholder="Write a message..." fluid @keydown.enter="sendMessage" />
|
||||
|
||||
<PrimeButton class="shrink-0" label="Send" severity="contrast" @click="sendMessage" />
|
||||
</PrimeInputGroup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { format } from 'date-fns'
|
||||
import linkifyStr from 'linkify-string'
|
||||
import { useChat } from '~/composables/use-chat'
|
||||
|
||||
definePageMeta({
|
||||
name: 'Index',
|
||||
})
|
||||
|
||||
const { me } = useClients()
|
||||
const chat = useChat()
|
||||
const { messages } = chat
|
||||
|
||||
const text = ref('')
|
||||
|
||||
function parseMessageText(text: string) {
|
||||
return linkifyStr(text, { className: 'underline', rel: 'noopener noreferrer', target: '_blank' })
|
||||
}
|
||||
|
||||
function formatDate(date: string) {
|
||||
return format(date, 'HH:mm')
|
||||
}
|
||||
|
||||
function sendMessage() {
|
||||
if (!text.value)
|
||||
return
|
||||
|
||||
chat.sendMessage({
|
||||
text: text.value,
|
||||
})
|
||||
|
||||
text.value = ''
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
<PrimeScrollPanel class="min-h-0">
|
||||
<PrimeDivider align="left">
|
||||
Audio
|
||||
</PrimeDivider>
|
||||
@@ -132,7 +132,7 @@
|
||||
@click="checkForUpdates"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</PrimeScrollPanel>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
@@ -54,4 +54,8 @@ export default defineNuxtPlugin(() => {
|
||||
sfx.playEvent('stream-off')
|
||||
}
|
||||
})
|
||||
|
||||
on('chat:new-message', () => {
|
||||
sfx.playEvent('message')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,12 +14,15 @@
|
||||
"@nuxt/fonts": "^0.11.4",
|
||||
"@primeuix/themes": "^1.2.5",
|
||||
"@tailwindcss/vite": "^4.1.14",
|
||||
"@tauri-apps/plugin-global-shortcut": "~2",
|
||||
"@tauri-apps/plugin-process": "~2",
|
||||
"@tauri-apps/plugin-updater": "~2",
|
||||
"@tauri-apps/plugin-global-shortcut": "^2.3.1",
|
||||
"@tauri-apps/plugin-process": "^2.3.1",
|
||||
"@tauri-apps/plugin-updater": "^2.10.1",
|
||||
"@vueuse/core": "^13.9.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"hotkeys-js": "^4.0.0",
|
||||
"howler": "^2.2.4",
|
||||
"linkify-string": "^4.3.2",
|
||||
"linkifyjs": "^4.3.2",
|
||||
"lucide-vue-next": "^0.562.0",
|
||||
"mediasoup-client": "^3.18.6",
|
||||
"mitt": "^3.0.1",
|
||||
|
||||
2297
client/src-tauri/Cargo.lock
generated
2297
client/src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,7 @@ log = "0.4"
|
||||
tauri = { version = "2.8.5", features = [] }
|
||||
tauri-plugin-log = "2"
|
||||
tauri-plugin-process = "2"
|
||||
windows = { version = "0.52", features = ["Win32_UI_Shell"] }
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-global-shortcut = "2"
|
||||
|
||||
@@ -4,7 +4,7 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_single_instance::init(|_, _, _| {}))
|
||||
// .plugin(tauri_plugin_single_instance::init(|_, _, _| {}))
|
||||
.setup(|app| {
|
||||
if cfg!(debug_assertions) {
|
||||
app.handle().plugin(
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn set_app_user_model_id() {
|
||||
use windows::core::HSTRING;
|
||||
use windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID;
|
||||
|
||||
unsafe {
|
||||
SetCurrentProcessExplicitAppUserModelID(
|
||||
&HSTRING::from("xyz.koptilnya.chad")
|
||||
).ok().expect("Failed to set AppUserModelID");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(target_os = "windows")]
|
||||
set_app_user_model_id();
|
||||
|
||||
app_lib::run();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||
"productName": "Chad",
|
||||
"version": "0.2.35",
|
||||
"version": "0.3.0-rc.1",
|
||||
"identifier": "xyz.koptilnya.chad",
|
||||
"build": {
|
||||
"frontendDist": "../.output/public",
|
||||
@@ -23,12 +23,8 @@
|
||||
"fullscreen": false,
|
||||
"center": true,
|
||||
"theme": "Dark",
|
||||
"additionalBrowserArgs": "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --autoplay-policy=no-user-gesture-required",
|
||||
"incognito": false,
|
||||
"minimizable": false,
|
||||
"contentProtected": true,
|
||||
"skipTaskbar": true,
|
||||
"alwaysOnBottom": true
|
||||
"additionalBrowserArgs": "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --autoplay-policy=no-user-gesture-required --lang=en",
|
||||
"incognito": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
|
||||
@@ -2824,10 +2824,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@tauri-apps/api@npm:^2.6.0":
|
||||
version: 2.8.0
|
||||
resolution: "@tauri-apps/api@npm:2.8.0"
|
||||
checksum: 10c0/fb111e4d7572372997b440ebe6879543fa8c4765151878e3fddfbfe809b18da29eed142ce83061d14a9ca6d896b3266dc8a4927c642d71cdc0b4277dc7e3aabf
|
||||
"@tauri-apps/api@npm:^2.10.1":
|
||||
version: 2.10.1
|
||||
resolution: "@tauri-apps/api@npm:2.10.1"
|
||||
checksum: 10c0/f3c0b2ba67a0b887440a7faa1e0589e847760ee30ec29b964f22573a46b817cb3af2199d6f5f7dfdda54d65b465ebaaa280454c610a5c53d808a0911fa15e45d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2959,7 +2959,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@tauri-apps/plugin-global-shortcut@npm:~2":
|
||||
"@tauri-apps/plugin-global-shortcut@npm:^2.3.1":
|
||||
version: 2.3.1
|
||||
resolution: "@tauri-apps/plugin-global-shortcut@npm:2.3.1"
|
||||
dependencies:
|
||||
@@ -2968,21 +2968,21 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@tauri-apps/plugin-process@npm:~2":
|
||||
version: 2.3.0
|
||||
resolution: "@tauri-apps/plugin-process@npm:2.3.0"
|
||||
"@tauri-apps/plugin-process@npm:^2.3.1":
|
||||
version: 2.3.1
|
||||
resolution: "@tauri-apps/plugin-process@npm:2.3.1"
|
||||
dependencies:
|
||||
"@tauri-apps/api": "npm:^2.6.0"
|
||||
checksum: 10c0/ef50344a7436d92278c2ef4526f72daaf3171c4d65743bbc1f7a00fa581644a8583bb8680f637a34af5c7e6a0e8722c22189290e903584fef70ed83b64b6e9c0
|
||||
"@tauri-apps/api": "npm:^2.8.0"
|
||||
checksum: 10c0/2e5086898f1c9f25f6426a752404c788727237142bbb7c8f418b97c76c5360874d06203150d136e51114df9e720022e4fa3681fd1d4cb6f777dc83c3553f8670
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@tauri-apps/plugin-updater@npm:~2":
|
||||
version: 2.9.0
|
||||
resolution: "@tauri-apps/plugin-updater@npm:2.9.0"
|
||||
"@tauri-apps/plugin-updater@npm:^2.10.1":
|
||||
version: 2.10.1
|
||||
resolution: "@tauri-apps/plugin-updater@npm:2.10.1"
|
||||
dependencies:
|
||||
"@tauri-apps/api": "npm:^2.6.0"
|
||||
checksum: 10c0/72ce83d1c241308a13b9929f0900e4d33453875877009166e3998e3e75a1003ac48c3641086b4d3230f0f18c64f475ad6c3556d1603fc641ca50dc9c18d61866
|
||||
"@tauri-apps/api": "npm:^2.10.1"
|
||||
checksum: 10c0/5d3813851ccbbf90253ad4647dbd97501c2bb75db864175693322fa6eb062b6e1bae03890810ad0bbe7f6da4e020af35e8c787e6999f8c7c645121164587dc29
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -4059,15 +4059,18 @@ __metadata:
|
||||
"@primevue/nuxt-module": "npm:^4.4.0"
|
||||
"@tailwindcss/vite": "npm:^4.1.14"
|
||||
"@tauri-apps/cli": "npm:^2.8.4"
|
||||
"@tauri-apps/plugin-global-shortcut": "npm:~2"
|
||||
"@tauri-apps/plugin-process": "npm:~2"
|
||||
"@tauri-apps/plugin-updater": "npm:~2"
|
||||
"@tauri-apps/plugin-global-shortcut": "npm:^2.3.1"
|
||||
"@tauri-apps/plugin-process": "npm:^2.3.1"
|
||||
"@tauri-apps/plugin-updater": "npm:^2.10.1"
|
||||
"@types/howler": "npm:^2"
|
||||
"@vueuse/core": "npm:^13.9.0"
|
||||
date-fns: "npm:^4.1.0"
|
||||
eslint: "npm:^9.36.0"
|
||||
eslint-plugin-format: "npm:^1.0.2"
|
||||
hotkeys-js: "npm:^4.0.0"
|
||||
howler: "npm:^2.2.4"
|
||||
linkify-string: "npm:^4.3.2"
|
||||
linkifyjs: "npm:^4.3.2"
|
||||
lucide-vue-next: "npm:^0.562.0"
|
||||
mediasoup-client: "npm:^3.18.6"
|
||||
mitt: "npm:^3.0.1"
|
||||
@@ -4566,6 +4569,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"date-fns@npm:^4.1.0":
|
||||
version: 4.1.0
|
||||
resolution: "date-fns@npm:4.1.0"
|
||||
checksum: 10c0/b79ff32830e6b7faa009590af6ae0fb8c3fd9ffad46d930548fbb5acf473773b4712ae887e156ba91a7b3dc30591ce0f517d69fd83bd9c38650fdc03b4e0bac8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"db0@npm:^0.3.4":
|
||||
version: 0.3.4
|
||||
resolution: "db0@npm:0.3.4"
|
||||
@@ -6953,6 +6963,22 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"linkify-string@npm:^4.3.2":
|
||||
version: 4.3.2
|
||||
resolution: "linkify-string@npm:4.3.2"
|
||||
peerDependencies:
|
||||
linkifyjs: ^4.0.0
|
||||
checksum: 10c0/674e908b46aa6da3ee7e5c0749464d8de55f4d44933d7e9dea4d2f9bb5af0137d45142494288cd120335e21d8298c76ec4524ab6e67edede4613adb5f17f7dc6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"linkifyjs@npm:^4.3.2":
|
||||
version: 4.3.2
|
||||
resolution: "linkifyjs@npm:4.3.2"
|
||||
checksum: 10c0/1a85e6b368304a4417567fe5e38651681e3e82465590836942d1b4f3c834cc35532898eb1e2479f6337d9144b297d418eb708b6be8ed0b3dc3954a3588e07971
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"listhen@npm:^1.9.0":
|
||||
version: 1.9.0
|
||||
resolution: "listhen@npm:1.9.0"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"@fastify/autoload": "^6.3.1",
|
||||
"@fastify/cookie": "^11.0.2",
|
||||
"@fastify/cors": "^11.1.0",
|
||||
"@fastify/multipart": "^10.0.0",
|
||||
"@lucia-auth/adapter-prisma": "^4.0.1",
|
||||
"@prisma/client": "^6.17.0",
|
||||
"bcrypt": "^6.0.0",
|
||||
@@ -21,6 +22,7 @@
|
||||
"mediasoup": "^3.19.3",
|
||||
"prisma": "^6.17.0",
|
||||
"socket.io": "^4.8.1",
|
||||
"uuid": "^13.0.0",
|
||||
"ws": "^8.18.3",
|
||||
"zod": "^4.1.12"
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { FastifyInstance } from 'fastify'
|
||||
import type { ServerOptions } from 'socket.io'
|
||||
import fp from 'fastify-plugin'
|
||||
import { Server } from 'socket.io'
|
||||
import registerChatSocket from '../socket/chat.ts'
|
||||
import registerWebrtcSocket from '../socket/webrtc.ts'
|
||||
|
||||
declare module 'fastify' {
|
||||
@@ -24,6 +25,7 @@ export default fp<Partial<ServerOptions>>(
|
||||
|
||||
fastify.ready(async () => {
|
||||
await registerWebrtcSocket(fastify.io, fastify.mediasoupRouter)
|
||||
await registerChatSocket(fastify.io)
|
||||
})
|
||||
},
|
||||
{ name: 'socket-io', dependencies: ['mediasoup-worker', 'mediasoup-router'] },
|
||||
|
||||
33
server/routes/attachments.ts
Normal file
33
server/routes/attachments.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { FastifyInstance } from 'fastify'
|
||||
import bcrypt from 'bcrypt'
|
||||
import { z } from 'zod'
|
||||
|
||||
export default function (fastify: FastifyInstance) {
|
||||
fastify.post('/attachments/upload', async (req, reply) => {
|
||||
try {
|
||||
const schema = z.object({
|
||||
file: z.file(),
|
||||
})
|
||||
const input = schema.parse(req.body)
|
||||
|
||||
// const file = req.file({ limits: { } })
|
||||
|
||||
const id = await bcrypt.hash(input.file, 10)
|
||||
|
||||
return {
|
||||
id,
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
fastify.log.error(err)
|
||||
reply.code(400)
|
||||
|
||||
if (err instanceof z.ZodError) {
|
||||
reply.send({ error: z.prettifyError(err) })
|
||||
}
|
||||
else {
|
||||
reply.send({ error: err.message })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -3,9 +3,12 @@ import { fileURLToPath } from 'node:url'
|
||||
import FastifyAutoLoad from '@fastify/autoload'
|
||||
import FastifyCookie from '@fastify/cookie'
|
||||
import FastifyCors from '@fastify/cors'
|
||||
import FastifyMultipart from '@fastify/multipart'
|
||||
import Fastify from 'fastify'
|
||||
import prisma from './prisma/client.ts'
|
||||
|
||||
console.log(process.env.DATABASE_URL)
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
@@ -25,6 +28,7 @@ fastify.register(FastifyCors, {
|
||||
})
|
||||
|
||||
fastify.register(FastifyCookie)
|
||||
fastify.register(FastifyMultipart)
|
||||
|
||||
fastify.register(FastifyAutoLoad, {
|
||||
dir: join(__dirname, 'plugins'),
|
||||
|
||||
28
server/socket/chat.ts
Normal file
28
server/socket/chat.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { Server as SocketServer } from 'socket.io'
|
||||
import type { ChatClientMessage, ChatMessage } from '../types/chat.ts'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export default async function (io: SocketServer) {
|
||||
const messages: ChatMessage[] = []
|
||||
|
||||
io.on('connection', async (socket) => {
|
||||
socket.on('chat:message', async (clientMessage: ChatClientMessage, cb) => {
|
||||
const message: ChatMessage = {
|
||||
id: uuidv4(),
|
||||
createdAt: new Date().toISOString(),
|
||||
sender: socket.data.username,
|
||||
text: clientMessage.text,
|
||||
}
|
||||
|
||||
console.log(message)
|
||||
|
||||
messages.push(message)
|
||||
|
||||
if (messages.length > 5000) {
|
||||
messages.shift()
|
||||
}
|
||||
|
||||
io.emit('chat:new-message', message)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import type { types } from 'mediasoup'
|
||||
import type { Server as SocketServer } from 'socket.io'
|
||||
import type {
|
||||
ChadClient,
|
||||
Namespace,
|
||||
SomeSocket,
|
||||
} from '../types/webrtc.ts'
|
||||
import { consola } from 'consola'
|
||||
@@ -10,8 +9,6 @@ import prisma from '../prisma/client.ts'
|
||||
import { socketToClient } from '../utils/socket-to-client.ts'
|
||||
|
||||
export default async function (io: SocketServer, router: types.Router) {
|
||||
const namespace: Namespace = io.of('/webrtc')
|
||||
|
||||
const audioLevelObserver = await router.createAudioLevelObserver({
|
||||
maxEntries: 10,
|
||||
threshold: -80,
|
||||
@@ -21,7 +18,7 @@ export default async function (io: SocketServer, router: types.Router) {
|
||||
const activeSpeakerObserver = await router.createActiveSpeakerObserver()
|
||||
|
||||
audioLevelObserver.on('volumes', async (volumes: types.AudioLevelObserverVolume[]) => {
|
||||
namespace.emit('speakingPeers', volumes.map(({ producer, volume }) => {
|
||||
io.emit('speakingPeers', volumes.map(({ producer, volume }) => {
|
||||
const { socketId } = producer.appData as { socketId: ChadClient['socketId'] }
|
||||
|
||||
return {
|
||||
@@ -32,17 +29,17 @@ export default async function (io: SocketServer, router: types.Router) {
|
||||
})
|
||||
|
||||
audioLevelObserver.on('silence', () => {
|
||||
namespace.emit('speakingPeers', [])
|
||||
namespace.emit('activeSpeaker', undefined)
|
||||
io.emit('speakingPeers', [])
|
||||
io.emit('activeSpeaker', undefined)
|
||||
})
|
||||
|
||||
activeSpeakerObserver.on('dominantspeaker', ({ producer }) => {
|
||||
const { socketId } = producer.appData as { socketId: ChadClient['socketId'] }
|
||||
|
||||
namespace.emit('activeSpeaker', socketId)
|
||||
io.emit('activeSpeaker', socketId)
|
||||
})
|
||||
|
||||
namespace.on('connection', async (socket) => {
|
||||
io.on('connection', async (socket) => {
|
||||
consola.info('[WebRtc]', 'Client connected', socket.id)
|
||||
|
||||
socket.data.joined = false
|
||||
@@ -350,7 +347,7 @@ export default async function (io: SocketServer, router: types.Router) {
|
||||
|
||||
cb(socketToClient(socket))
|
||||
|
||||
namespace.emit('clientChanged', socket.id, socketToClient(socket))
|
||||
io.emit('clientChanged', socket.id, socketToClient(socket))
|
||||
})
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
@@ -367,7 +364,7 @@ export default async function (io: SocketServer, router: types.Router) {
|
||||
})
|
||||
|
||||
async function getJoinedSockets(excludeId?: string) {
|
||||
const sockets = await namespace.fetchSockets()
|
||||
const sockets = await io.fetchSockets()
|
||||
|
||||
return sockets.filter(socket => socket.data.joined && (excludeId ? excludeId !== socket.id : true))
|
||||
}
|
||||
|
||||
18
server/types/chat.ts
Normal file
18
server/types/chat.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export interface ChatClientMessage {
|
||||
text: string
|
||||
replyTo?: {
|
||||
messageId: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
sender: string
|
||||
text: string
|
||||
createdAt: string
|
||||
replyTo?: {
|
||||
messageId: string
|
||||
sender: string
|
||||
text: string
|
||||
}
|
||||
}
|
||||
@@ -331,6 +331,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/busboy@npm:^3.0.0":
|
||||
version: 3.2.0
|
||||
resolution: "@fastify/busboy@npm:3.2.0"
|
||||
checksum: 10c0/3e4fb00a27e3149d1c68de8ff14007d2bbcbbc171a9d050d0a8772e836727329d4d3f130995ebaa19cf537d5d2f5ce2a88000366e6192e751457bfcc2125f351
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/cookie@npm:^11.0.2":
|
||||
version: 11.0.2
|
||||
resolution: "@fastify/cookie@npm:11.0.2"
|
||||
@@ -351,6 +358,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/deepmerge@npm:^3.0.0":
|
||||
version: 3.2.1
|
||||
resolution: "@fastify/deepmerge@npm:3.2.1"
|
||||
checksum: 10c0/2c0f8b627537834822ec761842e3a57965d3fb59e011ac5f2215b618ce34698e277bcbe4f586b09e4f03347391f292cfef9dccb6bda7b019ea9420d8767ade49
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/error@npm:^4.0.0":
|
||||
version: 4.2.0
|
||||
resolution: "@fastify/error@npm:4.2.0"
|
||||
@@ -383,6 +397,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/multipart@npm:^10.0.0":
|
||||
version: 10.0.0
|
||||
resolution: "@fastify/multipart@npm:10.0.0"
|
||||
dependencies:
|
||||
"@fastify/busboy": "npm:^3.0.0"
|
||||
"@fastify/deepmerge": "npm:^3.0.0"
|
||||
"@fastify/error": "npm:^4.0.0"
|
||||
fastify-plugin: "npm:^5.0.0"
|
||||
secure-json-parse: "npm:^4.0.0"
|
||||
checksum: 10c0/49e09135599a59aab761b71f65ab5f9ad63c3ea28ede04389c308dea1149b1fd7779693230f5bc0ffc9063c42484e99a2d1d38c0fd73b074c9ed3216db12e9da
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@fastify/proxy-addr@npm:^5.0.0":
|
||||
version: 5.1.0
|
||||
resolution: "@fastify/proxy-addr@npm:5.1.0"
|
||||
@@ -4265,6 +4292,7 @@ __metadata:
|
||||
"@fastify/autoload": "npm:^6.3.1"
|
||||
"@fastify/cookie": "npm:^11.0.2"
|
||||
"@fastify/cors": "npm:^11.1.0"
|
||||
"@fastify/multipart": "npm:^10.0.0"
|
||||
"@lucia-auth/adapter-prisma": "npm:^4.0.1"
|
||||
"@prisma/client": "npm:^6.17.0"
|
||||
"@types/bcrypt": "npm:^6"
|
||||
@@ -4281,6 +4309,7 @@ __metadata:
|
||||
socket.io: "npm:^4.8.1"
|
||||
ts-node: "npm:^10.9.2"
|
||||
typescript: "npm:^5.9.3"
|
||||
uuid: "npm:^13.0.0"
|
||||
ws: "npm:^8.18.3"
|
||||
zod: "npm:^4.1.12"
|
||||
languageName: unknown
|
||||
@@ -4787,6 +4816,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"uuid@npm:^13.0.0":
|
||||
version: 13.0.0
|
||||
resolution: "uuid@npm:13.0.0"
|
||||
bin:
|
||||
uuid: dist-node/bin/uuid
|
||||
checksum: 10c0/950e4c18d57fef6c69675344f5700a08af21e26b9eff2bf2180427564297368c538ea11ac9fb2e6528b17fc3966a9fd2c5049361b0b63c7d654f3c550c9b3d67
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"v8-compile-cache-lib@npm:^3.0.1":
|
||||
version: 3.0.1
|
||||
resolution: "v8-compile-cache-lib@npm:3.0.1"
|
||||
|
||||
Reference in New Issue
Block a user