Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 8da2581

Browse files
authored
Use ICE servers from API (#406)
1 parent 8e81679 commit 8da2581

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ dev: build/linux
4848
-rm ./coder
4949
@echo "untarring..."
5050
@tar -xzf ./ci/bin/coder-cli-linux-amd64.tar.gz
51-
@echo "new dev binary ready"
51+
@echo "new dev binary ready"

coder-sdk/interface.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/url"
66

77
"cdr.dev/wsep"
8+
"github.com/pion/webrtc/v3"
89
"nhooyr.io/websocket"
910
)
1011

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

245-
// satellites fetches all satellitess known to the Coder control plane.
246+
// Satellites fetches all satellitess known to the Coder control plane.
246247
Satellites(ctx context.Context) ([]Satellite, error)
247248

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

254255
// UpdateLastConnectionAt updates the last connection at attribute of a workspace.
255256
UpdateLastConnectionAt(ctx context.Context, workspaceID string) error
257+
258+
// ICEServers fetches the list of ICE servers advertised by the deployment.
259+
ICEServers(ctx context.Context) ([]webrtc.ICEServer, error)
256260
}

coder-sdk/webrtc.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package coder
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
"github.com/pion/webrtc/v3"
8+
)
9+
10+
type getICEServersRes struct {
11+
Data []webrtc.ICEServer `json:"data"`
12+
}
13+
14+
// ICEServers fetches the list of ICE servers advertised by the deployment.
15+
func (c *DefaultClient) ICEServers(ctx context.Context) ([]webrtc.ICEServer, error) {
16+
var res getICEServersRes
17+
err := c.requestBody(ctx, http.MethodGet, "/api/private/webrtc/ice", nil, &res)
18+
if err != nil {
19+
return nil, err
20+
}
21+
22+
return res.Data, nil
23+
}

internal/cmd/tunnel.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,18 @@ coder tunnel my-dev 3000 3000
7575
return xerrors.Errorf("No workspace found by name '%s'", args[0])
7676
}
7777

78+
iceServers, err := sdk.ICEServers(ctx)
79+
if err != nil {
80+
return xerrors.Errorf("get ICE servers: %w", err)
81+
}
82+
log.Debug(ctx, "got ICE servers", slog.F("ice", iceServers))
83+
7884
c := &tunnneler{
7985
log: log,
8086
brokerAddr: &baseURL,
8187
token: sdk.Token(),
8288
workspaceID: workspaceID,
89+
iceServers: iceServers,
8390
stdio: args[2] == "stdio",
8491
localPort: uint16(localPort),
8592
remotePort: uint16(remotePort),
@@ -102,6 +109,7 @@ type tunnneler struct {
102109
brokerAddr *url.URL
103110
token string
104111
workspaceID string
112+
iceServers []webrtc.ICEServer
105113
remotePort uint16
106114
localPort uint16
107115
stdio bool
@@ -119,7 +127,7 @@ func (c *tunnneler) start(ctx context.Context) error {
119127
TURNProxyAuthToken: c.token,
120128
TURNRemoteProxyURL: c.brokerAddr,
121129
TURNLocalProxyURL: c.brokerAddr,
122-
ICEServers: []webrtc.ICEServer{wsnet.TURNProxyICECandidate()},
130+
ICEServers: c.iceServers,
123131
},
124132
nil,
125133
)

0 commit comments

Comments
 (0)