Skip to content

feat: Add web terminal with reconnecting TTYs #1186

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

Merged
merged 8 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Merge branch 'main' into webterm
  • Loading branch information
kylecarbs committed Apr 29, 2022
commit 19c7b54e166586c0158d02aae734110aefb6fcce
5 changes: 2 additions & 3 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ func (api *api) workspaceAgentDial(rw http.ResponseWriter, r *http.Request) {
return
}

conn, err := websocket.Accept(rw, r, &websocket.AcceptOptions{
CompressionMode: websocket.CompressionDisabled,
})
conn, err := websocket.Accept(rw, r, nil)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("accept websocket: %s", err),
Expand Down Expand Up @@ -378,6 +376,7 @@ func (api *api) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
wsNetConn := websocket.NetConn(r.Context(), conn, websocket.MessageBinary)
agentConn, err := api.dialWorkspaceAgent(r, workspaceAgent.ID)
if err != nil {
_ = conn.Close(websocket.StatusInternalError, httpapi.WebsocketCloseSprintf("dial workspace agent: %s", err))
return
}
defer agentConn.Close()
Expand Down
2 changes: 0 additions & 2 deletions codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ func (c *Client) WorkspaceAgentReconnectingPTY(ctx context.Context, agentID, rec
}
conn, res, err := websocket.Dial(ctx, serverURL.String(), &websocket.DialOptions{
HTTPClient: httpClient,
// Need to disable compression to avoid a data-race.
CompressionMode: websocket.CompressionDisabled,
})
if err != nil {
if res == nil {
Expand Down
5 changes: 3 additions & 2 deletions site/src/pages/TerminalPage/TerminalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const TerminalPage: React.FC<{
},
})
const isConnected = terminalState.matches("connected")
const isDisconnected = terminalState.matches("disconnected")
const { organizationsError, workspaceError, workspaceAgentError, workspaceAgent, websocketError } =
terminalState.context

Expand Down Expand Up @@ -191,7 +192,7 @@ export const TerminalPage: React.FC<{
<>
{/* This overlay makes it more obvious that the terminal is disconnected. */}
{/* It's nice for situations where Coder restarts, and they are temporarily disconnected. */}
<div className={`${styles.overlay} ${isConnected ? "connected" : ""}`}>
<div className={`${styles.overlay} ${isDisconnected ? "" : "connected"}`}>
<span>Disconnected</span>
</div>
<div className={styles.terminal} ref={xtermRef} data-testid="terminal" />
Expand All @@ -214,7 +215,7 @@ const useStyles = makeStyles(() => ({
color: "white",
fontFamily: MONOSPACE_FONT_FAMILY,
fontSize: 18,
backgroundColor: "rgba(0, 0, 0, 0.5)",
backgroundColor: "rgba(0, 0, 0, 0.2)",
"&.connected": {
opacity: 0,
},
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.