.github/workflows/go.yml | 2 +- webtorrent/setting-engine.go | 24 ++++++++++++++++++++++++ webtorrent/setting-engine_js.go | 13 +++++++++++++ webtorrent/transport.go | 2 -- diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index af1530ffe3d72ae78d29c769414e151e6429496a..4b12c90744eb482bcf9b3faaa5a57e3c0f3bb0ba 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -60,7 +60,7 @@ steps: - uses: actions/checkout@v2 - uses: ./.github/actions/go-common - name: Some packages compile for WebAssembly - run: GOOS=js GOARCH=wasm go build -v . ./storage ./tracker/... + run: GOOS=js GOARCH=wasm go build . ./storage ./tracker/... torrentfs: runs-on: ubuntu-latest diff --git a/webtorrent/setting-engine.go b/webtorrent/setting-engine.go new file mode 100644 index 0000000000000000000000000000000000000000..a84ee02044f6a817271cf2d1abcaccc6e3f303b3 --- /dev/null +++ b/webtorrent/setting-engine.go @@ -0,0 +1,24 @@ +// These build constraints are copied from webrtc's settingengine.go. +//go:build !js +// +build !js + +package webtorrent + +import ( + "io" + + "github.com/pion/logging" + "github.com/pion/webrtc/v3" +) + +var s = webrtc.SettingEngine{ + // This could probably be done with better integration into anacrolix/log, but I'm not sure if + // it's worth the effort. + LoggerFactory: discardLoggerFactory{}, +} + +type discardLoggerFactory struct{} + +func (discardLoggerFactory) NewLogger(scope string) logging.LeveledLogger { + return logging.NewDefaultLeveledLoggerForScope(scope, logging.LogLevelInfo, io.Discard) +} diff --git a/webtorrent/setting-engine_js.go b/webtorrent/setting-engine_js.go new file mode 100644 index 0000000000000000000000000000000000000000..ea42d11aec106af5707131289d464ec4c0ccc7e5 --- /dev/null +++ b/webtorrent/setting-engine_js.go @@ -0,0 +1,13 @@ +// These build constraints are copied from webrtc's settingengine_js.go. +//go:build js && wasm +// +build js,wasm + +package webtorrent + +import ( + "github.com/pion/webrtc/v3" +) + +// I'm not sure what to do for logging for JS. See +// https://gophers.slack.com/archives/CAK2124AG/p1649651943947579. +var s = webrtc.SettingEngine{} diff --git a/webtorrent/transport.go b/webtorrent/transport.go index 62ca5fdb4b80fcac7a0b840165077b6529a024a3..e4c3b73d88dd9d55094523b8992c44d7613a93d9 100644 --- a/webtorrent/transport.go +++ b/webtorrent/transport.go @@ -8,7 +8,6 @@ "sync" "github.com/anacrolix/missinggo/v2/pproffd" "github.com/pion/datachannel" - "github.com/pion/webrtc/v3" ) @@ -16,7 +15,6 @@ var ( metrics = expvar.NewMap("webtorrent") api = func() *webrtc.API { // Enable the detach API (since it's non-standard but more idiomatic). - s := webrtc.SettingEngine{} s.DetachDataChannels() return webrtc.NewAPI(webrtc.WithSettingEngine(s)) }()