Video Chat app with webRTC and Elysia
Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
African Slender-snouted CrocodileOP
I have been developing a video Chat app but seems like I cannot get the users video, only the ice candidate message is neither sent from backend nor received from frontend I wonder where the problem might be arising
Frontend codes attached here
.ws('/ws/room/:roomId', {
body: t.Object({
type: t.String(),
peerId: t.Optional(t.String()),
offer: t.Optional(t.Any()),
answer: t.Optional(t.Any()),
candidate: t.Optional(t.Any()),
data: t.Optional(t.Any()),
}),
params: t.Object({
roomId: t.String(),
}),
message: (ws: Elysia.WebSocket<WSData>, message) => {
const { roomId } = ws.data.params
switch (message.type) {
case 'join-room':
const peerId = nanoid.nanoid()
ws.send(JSON.stringify({ type: 'your-id', peerId }))
ws.publish(roomId, JSON.stringify({ type: 'new-peer', peerId }))
ws.data.peerId = peerId
break
case 'offer':
case 'answer':
case 'ice-candidate':
if (message.peerId && ws.data.peerId) {
ws.publish(roomId, JSON.stringify({
...message,
senderId: ws.data.peerId
}))
}
break
case 'chat':
ws.publish(roomId, JSON.stringify(message))
break
default:
console.log('Unknown message type:', message.type)
}
},
open: (ws: Elysia.WebSocket<WSData>) => {
const { roomId } = ws.data.params
ws.subscribe(roomId)
console.log(`New connection in room ${roomId}`)
},
close: (ws: Elysia.WebSocket<WSData>) => {
const { roomId } = ws.data.params
if (ws.data.peerId) {
ws.publish(roomId, JSON.stringify({
type: 'peer-disconnected',
peerId: ws.data.peerId
}))
}
ws.unsubscribe(roomId)
console.log(`Connection closed in room ${roomId}`)
},
})Frontend codes attached here