mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-13 20:33:25 +00:00
Fix ICE candidate handling for Node.js compatibility
Handle both browser and Node.js (wrtc) environments when processing ICE candidates. Browsers provide toJSON() method on candidates, but wrtc library candidates are already plain objects. Check for toJSON() existence before calling it. Fixes: TypeError: event.candidate.toJSON is not a function in Node.js
This commit is contained in:
@@ -365,10 +365,17 @@ export class Rondevu {
|
||||
pc.onicecandidate = async (event) => {
|
||||
if (event.candidate) {
|
||||
try {
|
||||
// Handle both browser and Node.js (wrtc) environments
|
||||
// Browser: candidate.toJSON() exists
|
||||
// Node.js wrtc: candidate is already a plain object
|
||||
const candidateData = typeof event.candidate.toJSON === 'function'
|
||||
? event.candidate.toJSON()
|
||||
: event.candidate
|
||||
|
||||
await this.api.addOfferIceCandidates(
|
||||
serviceFqn,
|
||||
offerId,
|
||||
[event.candidate.toJSON()]
|
||||
[candidateData]
|
||||
)
|
||||
} catch (err) {
|
||||
console.error('[Rondevu] Failed to send ICE candidate:', err)
|
||||
|
||||
Reference in New Issue
Block a user