Add SDP validation to publishService()

Validation: Add comprehensive offer validation
- Validate each offer is an object
- Validate each offer has sdp property
- Validate sdp is a string
- Validate sdp is not empty/whitespace

Impact: Prevents runtime errors from malformed offers
Improves error messages with specific index information
This commit is contained in:
2025-12-12 22:52:46 +01:00
parent 05fe34be01
commit 7e2e8c703e

View File

@@ -336,6 +336,19 @@ const handlers: Record<string, RpcHandler> = {
);
}
// Validate each offer has valid SDP
offers.forEach((offer, index) => {
if (!offer || typeof offer !== 'object') {
throw new Error(`Invalid offer at index ${index}: must be an object`);
}
if (!offer.sdp || typeof offer.sdp !== 'string') {
throw new Error(`Invalid offer at index ${index}: missing or invalid SDP`);
}
if (!offer.sdp.trim()) {
throw new Error(`Invalid offer at index ${index}: SDP cannot be empty`);
}
});
// Create service with offers
const now = Date.now();
const offerTtl =