Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clientcore/broflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func NewBroflake(bfOpt *BroflakeOptions, rtcOpt *WebRTCOptions, egOpt *EgressOpt
// Step 3: Init the UI (this constructs and exposes the JavaScript API as required)
ui.Init(broflake)

// Set optional connection change callback before UI is copied to bus handlers
if bfOpt.OnConnectionChangeFunc != nil {
ui.OnConnectionChangeFunc = bfOpt.OnConnectionChangeFunc
}

// Step 4: Set up the bus, bind upstream and downstream UI handlers
var bus = NewIpcObserver(
bfOpt.BusBufferSz,
Expand Down
18 changes: 13 additions & 5 deletions clientcore/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"math/rand"
"net"
"net/http"
"time"

Expand Down Expand Up @@ -59,12 +60,19 @@ func NewDefaultEgressOptions() *EgressOptions {
}
}

// ConnectionChangeFunc is a callback for consumer connection state changes.
// state: 1 = connected, -1 = disconnected.
// When state == 1 (connected), addr is the IPv4 or IPv6 address of the new consumer.
// When state == -1 (disconnected), addr may be nil and should not be assumed to be non-nil.
type ConnectionChangeFunc func(state int, workerIdx int, addr net.IP)

type BroflakeOptions struct {
ClientType string
CTableSize int
PTableSize int
BusBufferSz int
Netstated string
ClientType string
CTableSize int
PTableSize int
BusBufferSz int
Netstated string
OnConnectionChangeFunc ConnectionChangeFunc
}

func NewDefaultBroflakeOptions() *BroflakeOptions {
Expand Down
7 changes: 5 additions & 2 deletions clientcore/ui_default_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

type UIImpl struct {
UI
BroflakeEngine *BroflakeEngine
BroflakeEngine *BroflakeEngine
OnConnectionChangeFunc ConnectionChangeFunc
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 OnConnectionChangeFunc field is only added to the non-WASM UIImpl struct but not to the WASM version in ui_wasm_impl.go. Since both implementations share the same BroflakeOptions struct and NewBroflake function (which sets ui.OnConnectionChangeFunc at line 171 in broflake.go), this will cause a compilation error for WASM builds. The field needs to be added to the UIImpl struct in ui_wasm_impl.go as well, and the OnConsumerConnectionChange method in that file should also be updated to call the callback if set.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

}

func (ui *UIImpl) Init(bf *BroflakeEngine) {
Expand Down Expand Up @@ -45,5 +46,7 @@ func (ui UIImpl) OnDownstreamThroughput(bytesPerSec int) {
}

func (ui UIImpl) OnConsumerConnectionChange(state int, workerIdx int, addr net.IP) {
// TODO: do something?
if ui.OnConnectionChangeFunc != nil {
ui.OnConnectionChangeFunc(state, workerIdx, addr)
}
}
9 changes: 7 additions & 2 deletions clientcore/ui_wasm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (

type UIImpl struct {
UI
BroflakeEngine *BroflakeEngine
ID string
BroflakeEngine *BroflakeEngine
ID string
OnConnectionChangeFunc ConnectionChangeFunc
}

func (ui *UIImpl) Init(bf *BroflakeEngine) {
Expand Down Expand Up @@ -93,6 +94,10 @@ func (ui UIImpl) OnDownstreamThroughput(bytesPerSec int) {
// consumer (or a 0-length string indicating that address extraction failed); when state == -1,
// addr == "<nil>"
func (ui UIImpl) OnConsumerConnectionChange(state int, workerIdx int, addr net.IP) {
if ui.OnConnectionChangeFunc != nil {
ui.OnConnectionChangeFunc(state, workerIdx, addr)
}

addrString := ""
if addr != nil {
addrString = addr.String()
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ replace github.com/enobufs/go-nats => github.com/noahlevenson/go-nats v0.0.0-202
replace github.com/quic-go/quic-go => github.com/getlantern/quic-go-unbounded-fork v0.51.3-unbounded

require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/coder/websocket v1.8.12
github.com/elazarl/goproxy v1.7.2
github.com/enobufs/go-nats v0.0.1
github.com/getlantern/geo v0.0.0-20240108161311-50692a1b69a9
github.com/getlantern/telemetry v0.0.0-20250606052628-8960164ec1f5
github.com/google/uuid v1.6.0
github.com/pion/transport/v3 v3.0.7
github.com/pion/webrtc/v4 v4.1.2
github.com/quic-go/quic-go v0.51.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
Expand All @@ -24,7 +26,6 @@ require (

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
Expand Down Expand Up @@ -68,7 +69,6 @@ require (
github.com/pion/stun/v3 v3.0.0 // indirect
github.com/pion/transport v0.14.1 // indirect
github.com/pion/transport/v2 v2.2.10 // indirect
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pion/turn v1.3.7 // indirect
github.com/pion/turn/v4 v4.0.2 // indirect
github.com/pkg/errors v0.8.1 // indirect
Expand Down
Loading