Merge branch 'main' of github.com:github/go-liveshare

This commit is contained in:
Jose Garcia 2021-07-21 18:54:13 -04:00
commit 71a55b2126
3 changed files with 24 additions and 18 deletions

View file

@ -96,7 +96,7 @@ func (c *Client) openStreamingChannel(ctx context.Context, streamName, condition
if err != nil {
return nil, fmt.Errorf("error opening ssh channel for transport: %v", err)
}
go c.processChannelRequests(ctx, reqs)
go ssh.DiscardRequests(reqs)
requestType := fmt.Sprintf("stream-transport-%s", streamID)
_, err = channel.SendRequest(requestType, true, nil)
@ -106,16 +106,3 @@ func (c *Client) openStreamingChannel(ctx context.Context, streamName, condition
return channel, nil
}
func (c *Client) processChannelRequests(ctx context.Context, reqs <-chan *ssh.Request) {
for {
select {
case req := <-reqs:
if req != nil {
// TODO(josebalius): Handle
}
case <-ctx.Done():
break
}
}
}

View file

@ -53,8 +53,8 @@ func (l *LocalPortForwarder) handleConnection(ctx context.Context, conn net.Conn
copyConn := func(writer io.Writer, reader io.Reader) {
_, err := io.Copy(writer, reader)
if err != nil {
log.Println("errrrr copyConn")
log.Println(err) //TODO(josebalius): handle this somehow
channel.Close()
conn.Close()
}
}

View file

@ -21,7 +21,7 @@ func (c *Client) NewServer() (*Server, error) {
return &Server{client: c}, nil
}
type serverSharingResponse struct {
type Port struct {
SourcePort int `json:"sourcePort"`
DestinationPort int `json:"destinationPort"`
SessionName string `json:"sessionName"`
@ -36,7 +36,7 @@ type serverSharingResponse struct {
func (s *Server) StartSharing(ctx context.Context, protocol string, port int) error {
s.port = port
var response serverSharingResponse
var response Port
if err := s.client.rpc.do(ctx, "serverSharing.startSharing", []interface{}{
port, protocol, fmt.Sprintf("http://localhost:%s", strconv.Itoa(port)),
}, &response); err != nil {
@ -48,3 +48,22 @@ func (s *Server) StartSharing(ctx context.Context, protocol string, port int) er
return nil
}
type Ports []*Port
func (s *Server) GetSharedServers(ctx context.Context) (Ports, error) {
var response Ports
if err := s.client.rpc.do(ctx, "serverSharing.getSharedServers", []string{}, &response); err != nil {
return nil, err
}
return response, nil
}
func (s *Server) UpdateSharedVisibility(ctx context.Context, port int, public bool) error {
if err := s.client.rpc.do(ctx, "serverSharing.updateSharedServerVisibility", []interface{}{port, public}, nil); err != nil {
return err
}
return nil
}