From ebba9481c634047385b195545e27234399c37cde Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sat, 1 Nov 2025 02:04:04 +0100 Subject: [PATCH] chore: use peerjs stuff now --- README.md | 94 +-------------------------- app/pages/index.vue | 18 ++--- app/pages/stream.vue | 18 ++--- server/routes/api/turn/credentials.ts | 25 ------- 4 files changed, 12 insertions(+), 143 deletions(-) delete mode 100644 server/routes/api/turn/credentials.ts diff --git a/README.md b/README.md index be200ee..ac4f99b 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,3 @@ -# Helium +# helium -Effortless screensharing powered by WebRTC. - -## Prerequisites - -### TURN Server Setup - -To enable connections through restrictive NATs, you need a TURN server. We use [Metered's Open Relay](https://www.metered.ca/tools/openrelay/) which provides 50GB/month free. - -1. Sign up for a free account at https://dashboard.metered.ca/signup -2. Create a new app (you'll get an app name like `yourapp.metered.live`) -3. Copy your API key from the dashboard - -4. Fill in your credentials in `.env`: - -```bash -METERED_APP_NAME=yourapp -METERED_API_KEY=your_api_key_here -REDIS_URL=redis://localhost:6379 -``` - -## Setup - -Make sure to install dependencies: - -```bash -# npm -npm install - -# pnpm -pnpm install - -# yarn -yarn install - -# bun -bun install -``` - -## Development Server - -Start the development server on `http://localhost:3000`: - -```bash -# npm -npm run dev - -# pnpm -pnpm dev - -# yarn -yarn dev - -# bun -bun run dev -``` - -## Production - -Build the application for production: - -```bash -# npm -npm run build - -# pnpm -pnpm build - -# yarn -yarn build - -# bun -bun run build -``` - -Locally preview production build: - -```bash -# npm -npm run preview - -# pnpm -pnpm preview - -# yarn -yarn preview - -# bun -bun run preview -``` - -Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. +effortless webrtc screensharing \ No newline at end of file diff --git a/app/pages/index.vue b/app/pages/index.vue index 3da47dd..7155b0f 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -20,20 +20,12 @@ const { send } = useWebSocket(wsUrl, { toast.success('stream joined successfully') } if (message.event === 'offer') { - let iceServers: RTCIceServer[] = [ - { urls: 'stun:stun.l.google.com:19302' }, - { urls: 'stun:stun1.l.google.com:19302' }, - ]; - - try { - const turnCredentials = await $fetch('/api/turn/credentials'); - iceServers = turnCredentials as RTCIceServer[]; - } catch (error) { - console.warn('Failed to fetch TURN credentials, using STUN only:', error); - } - const peerConnection = new RTCPeerConnection({ - iceServers, + iceServers: [ + { urls: 'stun:stun.l.google.com:19302' }, + { urls: 'stun:stun1.l.google.com:19302' }, + { urls: "turn:0.peerjs.com:3478", username: "peerjs", credential: "peerjsp" }, + ], iceCandidatePoolSize: 10 }); viewerStore.setPeerConnection(peerConnection); diff --git a/app/pages/stream.vue b/app/pages/stream.vue index 06e015b..f3769f1 100644 --- a/app/pages/stream.vue +++ b/app/pages/stream.vue @@ -23,20 +23,12 @@ const { send } = useWebSocket(wsUrl, { } if (message.event === 'viewer-joined') { - let iceServers: RTCIceServer[] = [ - { urls: 'stun:stun.l.google.com:19302' }, - { urls: 'stun:stun1.l.google.com:19302' }, - ]; - - try { - const turnCredentials = await $fetch('/api/turn/credentials'); - iceServers = turnCredentials as RTCIceServer[]; - } catch (error) { - console.warn('Failed to fetch TURN credentials, using STUN only:', error); - } - const peerConnection = new RTCPeerConnection({ - iceServers, + iceServers: [ + { urls: 'stun:stun.l.google.com:19302' }, + { urls: 'stun:stun1.l.google.com:19302' }, + { urls: "turn:0.peerjs.com:3478", username: "peerjs", credential: "peerjsp" }, + ], iceCandidatePoolSize: 10 }); streamerStore.addPeerConnection(message.viewerId, peerConnection) diff --git a/server/routes/api/turn/credentials.ts b/server/routes/api/turn/credentials.ts deleted file mode 100644 index 68675ed..0000000 --- a/server/routes/api/turn/credentials.ts +++ /dev/null @@ -1,25 +0,0 @@ -export default defineEventHandler(async (event) => { - const apiKey = process.env.METERED_API_KEY || ''; - const appName = process.env.METERED_APP_NAME || ''; - - if (!apiKey || !appName) { - throw createError({ - statusCode: 500, - message: 'TURN server not configured.' - }); - } - - try { - const response = await $fetch( - `https://${appName}.metered.live/api/v1/turn/credentials?apiKey=${apiKey}` - ); - - return response; - } catch (error) { - console.error('Failed to fetch TURN credentials:', error); - throw createError({ - statusCode: 500, - message: 'Failed to fetch TURN credentials' - }); - } -});