Skip to content

Fix WASM build: extract platform-specific WebRTC API creation#333

Merged
noahlevenson merged 4 commits intomainfrom
adam/fix-wasm-setnet
Feb 28, 2026
Merged

Fix WASM build: extract platform-specific WebRTC API creation#333
noahlevenson merged 4 commits intomainfrom
adam/fix-wasm-setnet

Conversation

@myleshorton
Copy link
Contributor

Summary

  • SettingEngine.SetNet() in pion/webrtc v4 is gated by //go:build !js, so calling it in consumer.go breaks WASM compilation
  • Extracts WebRTC API creation into build-tagged helpers: webrtc_api.go (native, with SetNet/stdnet) and webrtc_api_js.go (WASM, plain webrtc.NewAPI())
  • Removes dead commented-out DTLS example code from consumer.go

Test plan

  • go build ./... passes (native)
  • GOOS=js GOARCH=wasm go build ./cmd/ passes
  • Verify widget still connects via WebRTC in browser

🤖 Generated with Claude Code

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go for native builds with SetNet() and stdnet support
  • Created webrtc_api_js.go for WASM builds with plain webrtc.NewAPI()
  • Updated consumer.go to use the new newWebRTCAPI() 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.

@@ -0,0 +1,12 @@
//go:build js && wasm
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
//go:build js && wasm
//go:build wasm

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,22 @@
//go:build !js
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
//go:build !js
//go:build !wasm

Copilot uses AI. Check for mistakes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@noahlevenson noahlevenson merged commit 5dddeff into main Feb 28, 2026
1 check passed
@noahlevenson noahlevenson deleted the adam/fix-wasm-setnet branch February 28, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants