more tweaks

This commit is contained in:
Alan Donovan 2021-09-02 11:39:29 -04:00
parent 4cceda1af0
commit 05a3d90a99
4 changed files with 13 additions and 10 deletions

View file

@ -86,11 +86,11 @@ type joinWorkspaceResult struct {
SessionNumber int `json:"sessionNumber"`
}
func (client *Client) joinWorkspace(ctx context.Context, rpc *rpcClient) (*joinWorkspaceResult, error) {
func (c *Client) joinWorkspace(ctx context.Context, rpc *rpcClient) (*joinWorkspaceResult, error) {
args := joinWorkspaceArgs{
ID: client.connection.SessionID,
ID: c.connection.SessionID,
ConnectionMode: "local",
JoiningUserSessionToken: client.connection.SessionToken,
JoiningUserSessionToken: c.connection.SessionToken,
ClientCapabilities: clientCapabilities{
IsNonInteractive: false,
},
@ -104,14 +104,14 @@ func (client *Client) joinWorkspace(ctx context.Context, rpc *rpcClient) (*joinW
return &result, nil
}
func (session *Session) openStreamingChannel(ctx context.Context, streamName, condition string) (ssh.Channel, error) {
func (s *Session) openStreamingChannel(ctx context.Context, streamName, condition string) (ssh.Channel, error) {
args := getStreamArgs{streamName, condition}
var streamID string
if err := session.rpc.do(ctx, "streamManager.getStream", args, &streamID); err != nil {
if err := s.rpc.do(ctx, "streamManager.getStream", args, &streamID); err != nil {
return nil, fmt.Errorf("error getting stream id: %v", err)
}
channel, reqs, err := session.ssh.conn.OpenChannel("session", nil)
channel, reqs, err := s.ssh.conn.OpenChannel("session", nil)
if err != nil {
return nil, fmt.Errorf("error opening ssh channel for transport: %v", err)
}

View file

@ -46,7 +46,8 @@ func TestPortForwarderStart(t *testing.T) {
}
defer testServer.Close()
ctx, _ := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
pf := NewPortForwarder(session, 8000)
done := make(chan error)

View file

@ -15,7 +15,8 @@ func TestRPCHandlerEvents(t *testing.T) {
time.Sleep(1 * time.Second)
rpcHandler.Handle(context.Background(), nil, &jsonrpc2.Request{Method: "somethingHappened"})
}()
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
defer cancel()
select {
case event := <-eventCh:
if event.Method != "somethingHappened" {

View file

@ -3,7 +3,6 @@ package liveshare
import (
"context"
"fmt"
"strconv"
)
// A Session represents the session between a connected Live Share client and server.
@ -25,6 +24,8 @@ type Port struct {
IsPublic bool `json:"isPublic"`
IsTCPServerConnectionEstablished bool `json:"isTCPServerConnectionEstablished"`
HasTSLHandshakePassed bool `json:"hasTSLHandshakePassed"`
// ^^^
// TODO(adonovan): fix possible typo in field name, and audit others.
}
// StartSharing tells the liveshare host to start sharing the port from the container
@ -33,7 +34,7 @@ func (s *Session) StartSharing(ctx context.Context, protocol string, port int) e
var response Port
if err := s.rpc.do(ctx, "serverSharing.startSharing", []interface{}{
port, protocol, fmt.Sprintf("http://localhost:%s", strconv.Itoa(port)),
port, protocol, fmt.Sprintf("http://localhost:%d", port),
}, &response); err != nil {
return err
}