diff --git a/analyze/nodejs.html b/analyze/nodejs.html
new file mode 100644
index 0000000..fcb1d89
--- /dev/null
+++ b/analyze/nodejs.html
@@ -0,0 +1,39 @@
+
+
+
+
diff --git a/src/components/message-dialog.tsx b/src/components/message-dialog.tsx
index 8087740..f6015b0 100644
--- a/src/components/message-dialog.tsx
+++ b/src/components/message-dialog.tsx
@@ -16,7 +16,7 @@ interface MessageProps {
onClose: () => void
}
-export function MessageDialog({ open, url, onClose }: MessageProps) {
+export default function MessageDialog({ open, url, onClose }: MessageProps) {
// memos
const message = React.useMemo(() => {
return `Hey, this is a SecureShare link. It will self-destruct after viewing. Make sure to copy it before closing it: ${url}`
diff --git a/src/components/message-form.tsx b/src/components/message-form.tsx
index 2af45f8..3b24988 100644
--- a/src/components/message-form.tsx
+++ b/src/components/message-form.tsx
@@ -1,5 +1,5 @@
import React from 'react'
-import * as z from 'zod'
+import { z } from 'zod'
import { zodResolver } from '@hookform/resolvers/zod'
import { Loader2, Paperclip, X } from 'lucide-react'
import { useForm } from 'react-hook-form'
@@ -61,7 +61,7 @@ interface MessageFormProps {
onSubmit?: (url: string) => void
}
-export function MessageForm({ onSubmit: onFormSubmit }: MessageFormProps) {
+export default function MessageForm({ onSubmit: onFormSubmit }: MessageFormProps) {
// state
const [progress, setProgress] = React.useState(0)
const [status, setStatus] = React.useState('')
diff --git a/src/pages/api/chat/url.ts b/src/pages/api/chat/url.ts
deleted file mode 100644
index 81f900b..0000000
--- a/src/pages/api/chat/url.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { NextApiRequest, NextApiResponse } from 'next'
-import { getLiveKitURL } from '../../../shared/utils'
-
-export default async function handleServerUrl(
- req: NextApiRequest,
- res: NextApiResponse
-) {
- try {
- const { region } = req.query
-
- if (Array.isArray(region)) {
- throw Error('provide max one region string')
- }
- const url = getLiveKitURL(region)
- res.status(200).json({ url })
- } catch (e) {
- res.statusMessage = (e as Error).message
- res.status(500).end()
- }
-}
diff --git a/src/pages/chats/[roomName].tsx b/src/pages/chats/[roomName].tsx
index 25ab66f..90235b4 100644
--- a/src/pages/chats/[roomName].tsx
+++ b/src/pages/chats/[roomName].tsx
@@ -1,11 +1,14 @@
import React from 'react'
+import dynamic from 'next/dynamic'
import { ExternalE2EEKeyProvider, Room, RoomOptions } from 'livekit-client'
import { LiveKitRoom, useToken } from '@livekit/components-react'
import MainLayout from '../../layouts/main'
-import { HomeContent } from '../../components/home-content'
+
import { useRouter } from 'next/router'
import { LiveKitChat } from '../../components/livekit-chat'
import { NewChatDialog } from '../../components/new-chat-dialog'
+const HomeContent = dynamic(() => import('../../components/home-content'), { ssr: true })
+
export default function ChatPage() {
const [isClient, setIsClient] = React.useState(false)
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index df7b655..8e6a7b7 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,8 +1,9 @@
import React from 'react'
-import { HomeContent } from '../components/home-content'
+import dynamic from 'next/dynamic'
import MainLayout from '../layouts/main'
-import { MessageDialog } from '../components/message-dialog'
-import { MessageForm } from '../components/message-form'
+const HomeContent = dynamic(() => import('../components/home-content'), { ssr: true })
+const MessageDialog = dynamic(() => import('../components/message-dialog'), { ssr: false })
+const MessageForm = dynamic(() => import('../components/message-form'), { ssr: false })
export default function Home() {
// state
diff --git a/src/pages/messages/[publicId].tsx b/src/pages/messages/[publicId].tsx
index eabcb44..4225dd7 100644
--- a/src/pages/messages/[publicId].tsx
+++ b/src/pages/messages/[publicId].tsx
@@ -1,5 +1,6 @@
import React from 'react'
import { useRouter } from 'next/router'
+import dynamic from 'next/dynamic'
import { GetServerSideProps } from 'next'
import { Message, Prisma } from '@prisma/client'
import { getAuth } from '@clerk/nextjs/server'
@@ -12,10 +13,10 @@ import { EventType, MessageStatus } from '../../shared/enums'
import { decryptFile, decryptText } from '../../shared/encrypt-decrypt'
// components
-import { HomeContent } from '../../components/home-content'
import MainLayout from '../../layouts/main'
import { TextMessageDialog } from '../../components/text-message-dialog'
-import { MessageForm } from '../../components/message-form'
+const HomeContent = dynamic(() => import('../../components/home-content'), { ssr: true })
+const MessageForm = dynamic(() => import('../../components/message-form'), { ssr: false })
import { FileDownloadDialog } from '../../components/file-download-dialog'
import { CounterDialog } from '../../components/counter-dialog'
import { ErrorDialog } from '../../components/error-dialog'
diff --git a/src/shared/hooks.ts b/src/shared/hooks.ts
deleted file mode 100644
index fc4ef82..0000000
--- a/src/shared/hooks.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { useEffect, useState } from 'react';
-
-export function useServerUrl(region?: string) {
- const [serverUrl, setServerUrl] = useState();
- useEffect(() => {
- let endpoint = `/api/chat/url`;
- if (region) {
- endpoint += `?region=${region}`;
- }
- fetch(endpoint).then(async (res) => {
- if (res.ok) {
- const body = await res.json();
- console.log(body);
- setServerUrl(body.url);
- } else {
- throw Error('Error fetching server url, check server logs');
- }
- });
- });
- return serverUrl;
-}
-
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 1d4c781..e5f41fb 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -1,4 +1,3 @@
-import { LocalAudioTrack, LocalVideoTrack } from 'livekit-client';
import { Prisma } from '@prisma/client';
export interface EncryptionDetails {
version: number
@@ -29,16 +28,6 @@ export interface MessageEvent extends ClientInfo {
}
-export interface SessionProps {
- roomName: string;
- identity: string;
- audioTrack?: LocalAudioTrack;
- videoTrack?: LocalVideoTrack;
- region?: string;
- // turnServer?: RTCIceServer;
- forceRelay?: boolean;
-}
-
export interface TokenResult {
identity: string;
accessToken: string;
diff --git a/src/shared/utils.ts b/src/shared/utils.ts
index e30b148..42863aa 100644
--- a/src/shared/utils.ts
+++ b/src/shared/utils.ts
@@ -1,4 +1,3 @@
-import { RoomServiceClient } from 'livekit-server-sdk'
import { addDays, addWeeks, addMonths } from 'date-fns'
import { NextApiRequest } from 'next'
import { ClientInfo, IpAddressInfo } from './types'
@@ -147,33 +146,6 @@ export function generateRoomId(length: number = 10): string {
return randomString
}
-function checkKeys() {
- if (typeof process.env.LIVEKIT_API_KEY === 'undefined') {
- throw new Error('LIVEKIT_API_KEY is not defined')
- }
- if (typeof process.env.LIVEKIT_API_SECRET === 'undefined') {
- throw new Error('LIVEKIT_API_SECRET is not defined')
- }
-}
-
-export function getRoomClient(): RoomServiceClient {
- checkKeys()
- return new RoomServiceClient(getLiveKitURL())
-}
-
-export function getLiveKitURL(region?: string | string[]): string {
- let targetKey = 'LIVEKIT_URL'
- if (region && !Array.isArray(region)) {
- targetKey = `LIVEKIT_URL_${region}`.toUpperCase()
- }
- const url = process.env[targetKey]
- if (!url) {
- throw new Error(`${targetKey} is not defined`)
- }
- return url
-}
-
-// add return type
export async function getIpAddressInfo(): Promise {
try {