Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile to WebAssembly #68

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ _testmain.go
.vscode/

*.orig
examples/wasm/assets/example.wasm
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func newClient(endpoint string, isProtobuf bool, config Config) *Client {
config.WriteTimeout = time.Second
}
if config.HandshakeTimeout == 0 {
config.HandshakeTimeout = time.Second
config.HandshakeTimeout = 5 * time.Second
}
if config.MaxServerPingDelay == 0 {
config.MaxServerPingDelay = 10 * time.Second
Expand Down Expand Up @@ -1120,6 +1120,7 @@ func (c *Client) startReconnecting() error {
}
c.resubscribe()
})

if err != nil {
_ = t.Close()
c.reconnectAttempts++
Expand Down
7 changes: 6 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
Version string
// NetDialContext specifies the dial function for creating TCP connections. If
// NetDialContext is nil, net.DialContext is used.
// Not used in WASM environment.
NetDialContext func(ctx context.Context, network, addr string) (net.Conn, error)
// ReadTimeout is how long to wait read operations to complete.
// Zero value means 5 * time.Second.
Expand All @@ -36,23 +37,27 @@ type Config struct {
// Zero value means 1 * time.Second.
WriteTimeout time.Duration
// HandshakeTimeout specifies the duration for the handshake to complete.
// Zero value means 1 * time.Second.
// Zero value means 5 * time.Second.
HandshakeTimeout time.Duration
// MaxServerPingDelay used to set maximum delay of ping from server.
// Zero value means 10 * time.Second.
MaxServerPingDelay time.Duration
// TLSConfig specifies the TLS configuration to use with tls.Client.
// If nil, the default configuration is used.
// Not used in WASM environment.
TLSConfig *tls.Config
// EnableCompression specifies if the client should attempt to negotiate
// per message compression (RFC 7692). Setting this value to true does not
// guarantee that compression will be supported. Currently, only "no context
// takeover" modes are supported.
// Not used in WASM environment.
EnableCompression bool
// CookieJar specifies the cookie jar.
// If CookieJar is nil, cookies are not sent in requests and ignored
// in responses.
// Not used in WASM environment.
CookieJar http.CookieJar
// Header specifies custom HTTP Header to send.
// Not used in WASM environment.
Header http.Header
}
Binary file added examples/wasm/assets/example.wasm
Binary file not shown.
13 changes: 13 additions & 0 deletions examples/wasm/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<meta charset="utf-8"/>
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("example.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
</head>
<body></body>
</html>
Loading