mirror of
https://github.com/xtr-dev/rondevu-demo.git
synced 2025-12-15 20:43:23 +00:00
Fix: Use ondatachannel instead of createDataChannel for answerer
CRITICAL BUG FIX: As the answerer, we should NOT create our own data channel. The host (offerer) creates the channel, and we receive it via ondatachannel event. This was causing messages to be sent on a different channel than the one the host was listening to, so no messages were being received. Changes: - Remove pc.createDataChannel() call - Add pc.ondatachannel event handler - Wrap data channel setup in setupDataChannel() function - Called when channel is received from host
This commit is contained in:
@@ -82,13 +82,15 @@ async function main() {
|
|||||||
console.log('\n3. Creating WebRTC peer connection...')
|
console.log('\n3. Creating WebRTC peer connection...')
|
||||||
const pc = new RTCPeerConnection(RTC_CONFIG)
|
const pc = new RTCPeerConnection(RTC_CONFIG)
|
||||||
|
|
||||||
// 4. Create data channel
|
// 4. Wait for data channel (we're the answerer, host creates the channel)
|
||||||
console.log('4. Creating data channel...')
|
console.log('4. Waiting for data channel from host...')
|
||||||
const dc = pc.createDataChannel('chat')
|
let dc = null
|
||||||
|
|
||||||
// Set up data channel handlers
|
|
||||||
let identified = false
|
let identified = false
|
||||||
|
|
||||||
|
// Function to setup data channel handlers
|
||||||
|
const setupDataChannel = (channel) => {
|
||||||
|
dc = channel
|
||||||
|
|
||||||
dc.onopen = () => {
|
dc.onopen = () => {
|
||||||
console.log(' ✓ Data channel opened!')
|
console.log(' ✓ Data channel opened!')
|
||||||
console.log(` Data channel state: ${dc.readyState}`)
|
console.log(` Data channel state: ${dc.readyState}`)
|
||||||
@@ -117,11 +119,6 @@ async function main() {
|
|||||||
console.log(' ❌ Data channel closed!')
|
console.log(' ❌ Data channel closed!')
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.onerror = (error) => {
|
|
||||||
console.error('❌ Data channel error:', error)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.onmessage = (event) => {
|
dc.onmessage = (event) => {
|
||||||
console.log(`📥 RAW DATA:`, event.data)
|
console.log(`📥 RAW DATA:`, event.data)
|
||||||
try {
|
try {
|
||||||
@@ -161,6 +158,13 @@ async function main() {
|
|||||||
console.error('❌ Data channel error:', error)
|
console.error('❌ Data channel error:', error)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receive data channel from host (we're the answerer)
|
||||||
|
pc.ondatachannel = (event) => {
|
||||||
|
console.log(' ✓ Data channel received from host!')
|
||||||
|
setupDataChannel(event.channel)
|
||||||
|
}
|
||||||
|
|
||||||
// 5. Set up ICE candidate exchange FIRST
|
// 5. Set up ICE candidate exchange FIRST
|
||||||
console.log('5. Setting up ICE candidate exchange...')
|
console.log('5. Setting up ICE candidate exchange...')
|
||||||
|
|||||||
Reference in New Issue
Block a user