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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ dev: build/linux
-rm ./coder
@echo "untarring..."
@tar -xzf ./ci/bin/coder-cli-linux-amd64.tar.gz
@echo "new dev binary ready"
@echo "new dev binary ready"
6 changes: 5 additions & 1 deletion coder-sdk/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"

"cdr.dev/wsep"
"github.com/pion/webrtc/v3"
"nhooyr.io/websocket"
)

Expand Down Expand Up @@ -242,7 +243,7 @@ type Client interface {
// SetPolicyTemplate sets the workspace policy template
SetPolicyTemplate(ctx context.Context, templateID string, templateScope TemplateScope, dryRun bool) (*SetPolicyTemplateResponse, error)

// satellites fetches all satellitess known to the Coder control plane.
// Satellites fetches all satellitess known to the Coder control plane.
Satellites(ctx context.Context) ([]Satellite, error)

// CreateSatellite creates a new satellite entity.
Expand All @@ -253,4 +254,7 @@ type Client interface {

// UpdateLastConnectionAt updates the last connection at attribute of a workspace.
UpdateLastConnectionAt(ctx context.Context, workspaceID string) error

// ICEServers fetches the list of ICE servers advertised by the deployment.
ICEServers(ctx context.Context) ([]webrtc.ICEServer, error)
}
23 changes: 23 additions & 0 deletions coder-sdk/webrtc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package coder

import (
"context"
"net/http"

"github.com/pion/webrtc/v3"
)

type getICEServersRes struct {
Data []webrtc.ICEServer `json:"data"`
}

// ICEServers fetches the list of ICE servers advertised by the deployment.
func (c *DefaultClient) ICEServers(ctx context.Context) ([]webrtc.ICEServer, error) {
var res getICEServersRes
err := c.requestBody(ctx, http.MethodGet, "/api/private/webrtc/ice", nil, &res)
if err != nil {
return nil, err
}

return res.Data, nil
}
10 changes: 9 additions & 1 deletion internal/cmd/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ coder tunnel my-dev 3000 3000
return xerrors.Errorf("No workspace found by name '%s'", args[0])
}

iceServers, err := sdk.ICEServers(ctx)
if err != nil {
return xerrors.Errorf("get ICE servers: %w", err)
}
log.Debug(ctx, "got ICE servers", slog.F("ice", iceServers))

c := &tunnneler{
log: log,
brokerAddr: &baseURL,
token: sdk.Token(),
workspaceID: workspaceID,
iceServers: iceServers,
stdio: args[2] == "stdio",
localPort: uint16(localPort),
remotePort: uint16(remotePort),
Expand All @@ -102,6 +109,7 @@ type tunnneler struct {
brokerAddr *url.URL
token string
workspaceID string
iceServers []webrtc.ICEServer
remotePort uint16
localPort uint16
stdio bool
Expand All @@ -119,7 +127,7 @@ func (c *tunnneler) start(ctx context.Context) error {
TURNProxyAuthToken: c.token,
TURNRemoteProxyURL: c.brokerAddr,
TURNLocalProxyURL: c.brokerAddr,
ICEServers: []webrtc.ICEServer{wsnet.TURNProxyICECandidate()},
ICEServers: c.iceServers,
},
nil,
)
Expand Down