Fix WASM build: extract platform-specific WebRTC API creation#333
Fix WASM build: extract platform-specific WebRTC API creation#333noahlevenson merged 4 commits intomainfrom
Conversation
SettingEngine.SetNet() is gated by //go:build !js in pion/webrtc v4, so calling it in consumer.go breaks WASM compilation. Extract the WebRTC API setup into build-tagged helpers: native builds configure SetNet with stdnet, WASM builds use a plain webrtc.NewAPI() since the browser handles networking via its own RTCPeerConnection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes WASM compilation by extracting platform-specific WebRTC API creation logic into build-tagged helper functions. The issue arose because SettingEngine.SetNet() in pion/webrtc v4 is unavailable in JavaScript/WASM builds (gated by //go:build !js), causing compilation failures when called directly in consumer.go.
Changes:
- Created
webrtc_api.gofor native builds withSetNet()and stdnet support - Created
webrtc_api_js.gofor WASM builds with plainwebrtc.NewAPI() - Updated
consumer.goto use the newnewWebRTCAPI()helper and removed dead commented code
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
clientcore/webrtc_api.go |
Native build implementation with SettingEngine and SetNet support |
clientcore/webrtc_api_js.go |
WASM build implementation using plain webrtc.NewAPI() |
clientcore/consumer.go |
Refactored to use newWebRTCAPI helper, removed stdnet import and dead DTLS example code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
clientcore/webrtc_api_js.go
Outdated
| @@ -0,0 +1,12 @@ | |||
| //go:build js && wasm | |||
There was a problem hiding this comment.
The build tag //go:build js && wasm is more restrictive than the pattern used elsewhere in the codebase. Other WASM-specific files like ui_wasm_impl.go and client_wasm_impl.go use just //go:build wasm. For consistency with the existing codebase, consider using //go:build wasm instead of //go:build js && wasm. While js && wasm is more specific and technically correct for JavaScript-targeting WASM builds, consistency with existing patterns would be preferable unless there's a specific reason for this difference.
| //go:build js && wasm | |
| //go:build wasm |
clientcore/webrtc_api.go
Outdated
| @@ -0,0 +1,22 @@ | |||
| //go:build !js | |||
There was a problem hiding this comment.
For consistency with other build-tagged files in the codebase (like ui_default_impl.go which uses //go:build !wasm and ui_wasm_impl.go which uses //go:build wasm), consider using //go:build !wasm instead of //go:build !js. This would maintain consistency with the established pattern in the codebase.
| //go:build !js | |
| //go:build !wasm |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
SettingEngine.SetNet()in pion/webrtc v4 is gated by//go:build !js, so calling it inconsumer.gobreaks WASM compilationwebrtc_api.go(native, withSetNet/stdnet) andwebrtc_api_js.go(WASM, plainwebrtc.NewAPI())consumer.goTest plan
go build ./...passes (native)GOOS=js GOARCH=wasm go build ./cmd/passes🤖 Generated with Claude Code