diff --git a/README.md b/README.md index dc33e194cd0b6b827549edb92f09e27d0385cbdb..c5b8c9071c4907f8bbcfb81d685df155cfee1ffe 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ go get nhooyr.io/websocket - JSON and ProtoBuf helpers in the [wsjson](https://godoc.org/nhooyr.io/websocket/wsjson) and [wspb](https://godoc.org/nhooyr.io/websocket/wspb) subpackages - Highly optimized by default - Concurrent writes out of the box -- [Complete WASM](https://godoc.org/nhooyr.io/websocket#hdr-WASM) support +- [Complete Wasm](https://godoc.org/nhooyr.io/websocket#hdr-Wasm) support ## Roadmap @@ -130,7 +130,7 @@ The ping API is also nicer. gorilla/websocket requires registering a pong handle which results in awkward control flow. With nhooyr/websocket you use the Ping method on the Conn that sends a ping and also waits for the pong. -Additionally, nhooyr.io/websocket can compile to [WASM](https://godoc.org/nhooyr.io/websocket#hdr-WASM) for the browser. +Additionally, nhooyr.io/websocket can compile to [Wasm](https://godoc.org/nhooyr.io/websocket#hdr-Wasm) for the browser. In terms of performance, the differences mostly depend on your application code. nhooyr/websocket reuses message buffers out of the box if you use the wsjson and wspb subpackages. diff --git a/assert_test.go b/assert_test.go index cddae99d5d44351bc9f3f63f0d5ce31e38799846..8970c5437588bd835fc4cbf89b79d50790d28879 100644 --- a/assert_test.go +++ b/assert_test.go @@ -2,10 +2,10 @@ package websocket_test import ( "context" - "encoding/hex" "fmt" "math/rand" "reflect" + "strings" "github.com/google/go-cmp/cmp" @@ -99,7 +99,16 @@ func randBytes(n int) []byte { } func randString(n int) string { - return hex.EncodeToString(randBytes(n))[:n] + s := strings.ToValidUTF8(string(randBytes(n)), "_") + if len(s) > n { + return s[:n] + } + if len(s) < n { + // Pad with = + extra := n - len(s) + return s + strings.Repeat("=", extra) + } + return s } func assertEcho(ctx context.Context, c *websocket.Conn, typ websocket.MessageType, n int) error { diff --git a/conn_common.go b/conn_common.go index 771db26b4c5688108cabe86b6b2ec7f3766d1004..1429b47d75e6f372517f2e4f8945535323a2efbe 100644 --- a/conn_common.go +++ b/conn_common.go @@ -1,5 +1,5 @@ // This file contains *Conn symbols relevant to both -// WASM and non WASM builds. +// Wasm and non Wasm builds. package websocket diff --git a/doc.go b/doc.go index 7753afc7f2cf0603d39c7296bc5c552706f4ef45..a17bfb05f7438956789413d57c3e839ba37ad2a9 100644 --- a/doc.go +++ b/doc.go @@ -18,14 +18,14 @@ // Use the errors.As function new in Go 1.13 to check for websocket.CloseError. // See the CloseError example. // -// WASM +// Wasm // -// The client side fully supports compiling to WASM. +// The client side fully supports compiling to Wasm. // It wraps the WebSocket browser API. // // See https://developer.mozilla.org/en-US/docs/Web/API/WebSocket // -// Thus the unsupported features (not compiled in) for WASM are: +// Thus the unsupported features (not compiled in) for Wasm are: // // - Accept and AcceptOptions // - Conn.Ping diff --git a/frame.go b/frame.go index 84a18e02e7c5a59e86ea401b51df729360ba03a1..95061f5afc395dbdf9929e4307bff70af07ea8d3 100644 --- a/frame.go +++ b/frame.go @@ -213,8 +213,8 @@ const ( StatusNoStatusRcvd - // This StatusCode is only exported for use with WASM. - // In non WASM Go, the returned error will indicate whether the connection was closed or not or what happened. + // This StatusCode is only exported for use with Wasm. + // In non Wasm Go, the returned error will indicate whether the connection was closed or not or what happened. StatusAbnormalClosure StatusInvalidFramePayloadData @@ -226,8 +226,8 @@ const ( StatusTryAgainLater StatusBadGateway - // This StatusCode is only exported for use with WASM. - // In non WASM Go, the returned error will indicate whether there was a TLS handshake failure. + // This StatusCode is only exported for use with Wasm. + // In non Wasm Go, the returned error will indicate whether there was a TLS handshake failure. StatusTLSHandshake ) diff --git a/internal/wsjs/wsjs.go b/internal/wsjs/wsjs_js.go similarity index 100% rename from internal/wsjs/wsjs.go rename to internal/wsjs/wsjs_js.go diff --git a/websocket_js_test.go b/websocket_js_test.go index e68ba6f3e0b1dd4faae9b1dfe1ab8cca154808f2..ba9431d40637d56ce8fefff48c5ccdf30ba1247d 100644 --- a/websocket_js_test.go +++ b/websocket_js_test.go @@ -36,12 +36,12 @@ func TestConn(t *testing.T) { t.Fatal(err) } - err = assertJSONEcho(ctx, c, 16) + err = assertJSONEcho(ctx, c, 1024) if err != nil { t.Fatal(err) } - err = assertEcho(ctx, c, websocket.MessageBinary, 16) + err = assertEcho(ctx, c, websocket.MessageBinary, 1024) if err != nil { t.Fatal(err) }