Merge pull request #53 from github/jg/perf-improvements
Liveshare client upgrade to v0.6.0
This commit is contained in:
commit
ebc8ce5adb
4 changed files with 24 additions and 19 deletions
|
|
@ -133,8 +133,10 @@ const (
|
|||
)
|
||||
|
||||
type CodespaceEnvironmentConnection struct {
|
||||
SessionID string `json:"sessionId"`
|
||||
SessionToken string `json:"sessionToken"`
|
||||
SessionID string `json:"sessionId"`
|
||||
SessionToken string `json:"sessionToken"`
|
||||
RelayEndpoint string `json:"relayEndpoint"`
|
||||
RelaySAS string `json:"relaySas"`
|
||||
}
|
||||
|
||||
func (a *API) ListCodespaces(ctx context.Context, user *User) (Codespaces, error) {
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ func Ports() error {
|
|||
|
||||
}
|
||||
|
||||
func getPorts(ctx context.Context, liveShareClient *liveshare.Client) (liveshare.Ports, error) {
|
||||
server, err := liveShareClient.NewServer()
|
||||
func getPorts(ctx context.Context, lsclient *liveshare.Client) (liveshare.Ports, error) {
|
||||
server, err := liveshare.NewServer(lsclient)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating server: %v", err)
|
||||
}
|
||||
|
|
@ -214,12 +214,12 @@ func updatePortVisibility(codespaceName, sourcePort string, public bool) error {
|
|||
return fmt.Errorf("error getting codespace: %v", err)
|
||||
}
|
||||
|
||||
liveShareClient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to liveshare: %v", err)
|
||||
}
|
||||
|
||||
server, err := liveShareClient.NewServer()
|
||||
server, err := liveshare.NewServer(lsclient)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating server: %v", err)
|
||||
}
|
||||
|
|
@ -276,12 +276,12 @@ func forwardPort(codespaceName, sourcePort, destPort string) error {
|
|||
return fmt.Errorf("error getting codespace: %v", err)
|
||||
}
|
||||
|
||||
liveShareClient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to liveshare: %v", err)
|
||||
}
|
||||
|
||||
server, err := liveShareClient.NewServer()
|
||||
server, err := liveshare.NewServer(lsclient)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating server: %v", err)
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ func forwardPort(codespaceName, sourcePort, destPort string) error {
|
|||
}
|
||||
|
||||
fmt.Println("Forwarding port: " + sourcePort + " -> " + destPort)
|
||||
portForwarder := liveshare.NewLocalPortForwarder(liveShareClient, server, dstPortInt)
|
||||
portForwarder := liveshare.NewPortForwarder(lsclient, server, dstPortInt)
|
||||
if err := portForwarder.Start(ctx); err != nil {
|
||||
return fmt.Errorf("error forwarding port: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,12 +82,12 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
}
|
||||
}
|
||||
|
||||
liveShareClient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to liveshare: %v", err)
|
||||
}
|
||||
|
||||
terminal, err := liveShareClient.NewTerminal()
|
||||
terminal, err := liveshare.NewTerminal(lsclient)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating liveshare terminal: %v", err)
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
server, err := liveShareClient.NewServer()
|
||||
server, err := liveshare.NewServer(lsclient)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating server: %v", err)
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
return fmt.Errorf("error sharing sshd port: %v", err)
|
||||
}
|
||||
|
||||
portForwarder := liveshare.NewLocalPortForwarder(liveShareClient, server, port)
|
||||
portForwarder := liveshare.NewPortForwarder(lsclient, server, port)
|
||||
go func() {
|
||||
if err := portForwarder.Start(ctx); err != nil {
|
||||
panic(fmt.Errorf("error forwarding port: %v", err))
|
||||
|
|
|
|||
|
|
@ -93,18 +93,21 @@ func ConnectToLiveshare(ctx context.Context, apiClient *api.API, token string, c
|
|||
|
||||
fmt.Println("Connecting to your codespace...")
|
||||
|
||||
liveShare, err := liveshare.New(
|
||||
liveshare.WithWorkspaceID(codespace.Environment.Connection.SessionID),
|
||||
liveshare.WithToken(codespace.Environment.Connection.SessionToken),
|
||||
lsclient, err := liveshare.NewClient(
|
||||
liveshare.WithConnection(liveshare.Connection{
|
||||
SessionID: codespace.Environment.Connection.SessionID,
|
||||
SessionToken: codespace.Environment.Connection.SessionToken,
|
||||
RelaySAS: codespace.Environment.Connection.RelaySAS,
|
||||
RelayEndpoint: codespace.Environment.Connection.RelayEndpoint,
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating live share: %v", err)
|
||||
}
|
||||
|
||||
liveShareClient := liveShare.NewClient()
|
||||
if err := liveShareClient.Join(ctx); err != nil {
|
||||
if err := lsclient.Join(ctx); err != nil {
|
||||
return nil, fmt.Errorf("error joining liveshare client: %v", err)
|
||||
}
|
||||
|
||||
return liveShareClient, nil
|
||||
return lsclient, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue