Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
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
3 changes: 3 additions & 0 deletions wsnet/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (d *Dialer) Close() error {

// Ping sends a ping through the control channel.
func (d *Dialer) Ping(ctx context.Context) error {
if d.ctrl.ReadyState() == webrtc.DataChannelStateClosed || d.ctrl.ReadyState() == webrtc.DataChannelStateClosing {
return webrtc.ErrConnectionClosed
}
// Since we control the client and server we could open this
// data channel with `Negotiated` true to reduce traffic being
// sent when the RTC connection is opened.
Expand Down
23 changes: 23 additions & 0 deletions wsnet/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ func TestDial(t *testing.T) {
return
}
})

t.Run("Disconnect", func(t *testing.T) {
connectAddr, listenAddr := createDumbBroker(t)
_, err := Listen(context.Background(), listenAddr)
if err != nil {
t.Error(err)
return
}
dialer, err := DialWebsocket(context.Background(), connectAddr, nil)
if err != nil {
t.Error(err)
return
}
err = dialer.Close()
if err != nil {
t.Error(err)
return
}
err = dialer.Ping(context.Background())
if err != webrtc.ErrConnectionClosed {
t.Error(err)
}
})
}

func BenchmarkThroughput(b *testing.B) {
Expand Down