Skip to content

Commit

Permalink
log the side with connection state
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Mar 13, 2024
1 parent 8f1fc36 commit 7a38e53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions p2p/transport/webrtc/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (l *listener) setupConnection(
return nil, fmt.Errorf("instantiating peer connection failed: %w", err)
}

errC := addOnConnectionStateChangeCallback(w.PeerConnection)
errC := addOnConnectionStateChangeCallback(w.PeerConnection, "listener")
// Infer the client SDP from the incoming STUN message by setting the ice-ufrag.
if err := w.PeerConnection.SetRemoteDescription(webrtc.SessionDescription{
SDP: createClientSDP(candidate.Addr, candidate.Ufrag),
Expand Down Expand Up @@ -320,11 +320,11 @@ func (l *listener) Multiaddr() ma.Multiaddr {
// addOnConnectionStateChangeCallback adds the OnConnectionStateChange to the PeerConnection.
// If the connection establishment errors, an error is written to the channel before closing.
// If the connection establishment is successful, the channel is closed without writing anything.
func addOnConnectionStateChangeCallback(pc *webrtc.PeerConnection) <-chan error {
func addOnConnectionStateChangeCallback(pc *webrtc.PeerConnection, side string) <-chan error {
errC := make(chan error, 1)
var once sync.Once
pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
fmt.Println("connection state: ", state)
fmt.Println(side, "connection state: ", state)
switch state {
case webrtc.PeerConnectionStateConnected:
once.Do(func() { close(errC) })
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webrtc/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (t *WebRTCTransport) dial(ctx context.Context, scope network.ConnManagement
return nil, fmt.Errorf("instantiating peer connection failed: %w", err)
}

errC := addOnConnectionStateChangeCallback(w.PeerConnection)
errC := addOnConnectionStateChangeCallback(w.PeerConnection, "dialer")

// do offer-answer exchange
offer, err := w.PeerConnection.CreateOffer(nil)
Expand Down

0 comments on commit 7a38e53

Please sign in to comment.