mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
020cacbe70
Or unless the new "ts_debug_websockets" build tag is set. Updates #1278 Change-Id: Ic4c4f81c1924250efd025b055585faec37a5491d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
35 lines
765 B
Go
35 lines
765 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build js || ((linux || darwin) && ts_debug_websockets)
|
|
|
|
package derphttp
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net"
|
|
|
|
"github.com/coder/websocket"
|
|
"tailscale.com/net/wsconn"
|
|
)
|
|
|
|
const canWebsockets = true
|
|
|
|
func init() {
|
|
dialWebsocketFunc = dialWebsocket
|
|
}
|
|
|
|
func dialWebsocket(ctx context.Context, urlStr string) (net.Conn, error) {
|
|
c, res, err := websocket.Dial(ctx, urlStr, &websocket.DialOptions{
|
|
Subprotocols: []string{"derp"},
|
|
})
|
|
if err != nil {
|
|
log.Printf("websocket Dial: %v, %+v", err, res)
|
|
return nil, err
|
|
}
|
|
log.Printf("websocket: connected to %v", urlStr)
|
|
netConn := wsconn.NetConn(context.Background(), c, websocket.MessageBinary, urlStr)
|
|
return netConn, nil
|
|
}
|