Add data channel state monitoring and increase send delay

- Increase delay to 500ms before sending identify
- Monitor channel state before sending
- Log bufferedAmount after send
- Add onclose handler for debugging
This commit is contained in:
2025-12-12 21:32:08 +01:00
parent ac4826e92f
commit d7caa81042

View File

@@ -93,8 +93,14 @@ async function main() {
console.log(' ✓ Data channel opened!')
console.log(` Data channel state: ${dc.readyState}`)
// Small delay to ensure both sides are ready
// Longer delay to ensure both sides are ready
setTimeout(() => {
console.log(` Data channel state before send: ${dc.readyState}`)
if (dc.readyState !== 'open') {
console.error(` ❌ Data channel not open: ${dc.readyState}`)
return
}
// Send identify message (demo protocol)
console.log(`📤 Sending identify message...`)
const identifyMsg = JSON.stringify({
@@ -103,8 +109,17 @@ async function main() {
})
console.log(` Message:`, identifyMsg)
dc.send(identifyMsg)
console.log(` ✓ Identify message sent`)
}, 100)
console.log(` ✓ Identify message sent, bufferedAmount: ${dc.bufferedAmount}`)
}, 500)
}
dc.onclose = () => {
console.log(' ❌ Data channel closed!')
}
dc.onerror = (error) => {
console.error('❌ Data channel error:', error)
process.exit(1)
}
dc.onmessage = (event) => {