Skip to content

Commit d5c68ba

Browse files
committed
Move HTTPClient outside of JS compilation
1 parent d27e5d3 commit d5c68ba

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

derp/derphttp/websocket.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// Copyright (c) Tailscale Inc & AUTHORS
2-
// SPDX-License-Identifier: BSD-3-Clause
3-
4-
//go:build linux || js || darwin || windows
1+
//go:build !js
52

63
package derphttp
74

derp/derphttp/websocket_js.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Tailscale Inc & AUTHORS
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
//go:build js
5+
6+
package derphttp
7+
8+
import (
9+
"context"
10+
"crypto/tls"
11+
"log"
12+
"net"
13+
14+
"nhooyr.io/websocket"
15+
"tailscale.com/net/wsconn"
16+
)
17+
18+
func init() {
19+
dialWebsocketFunc = dialWebsocket
20+
}
21+
22+
func dialWebsocket(ctx context.Context, urlStr string, _ *tls.Config) (net.Conn, error) {
23+
c, res, err := websocket.Dial(ctx, urlStr, &websocket.DialOptions{
24+
Subprotocols: []string{"derp"},
25+
})
26+
if err != nil {
27+
log.Printf("websocket Dial: %v, %+v", err, res)
28+
return nil, err
29+
}
30+
log.Printf("websocket: connected to %v", urlStr)
31+
netConn := wsconn.NetConn(context.Background(), c, websocket.MessageBinary)
32+
return netConn, nil
33+
}

0 commit comments

Comments
 (0)