diff --git a/api.go b/api.go index a101823df..55b6e6e93 100644 --- a/api.go +++ b/api.go @@ -52,7 +52,6 @@ type workspaceAccessResponse struct { func (a *api) workspaceAccess() (*workspaceAccessResponse, error) { url := fmt.Sprintf("%s/workspace/%s/user", a.serviceURI, a.workspaceID) - fmt.Println(url) req, err := http.NewRequest(http.MethodPut, url, nil) if err != nil { diff --git a/client.go b/client.go index 88c91ba01..0af904b92 100644 --- a/client.go +++ b/client.go @@ -3,7 +3,6 @@ package liveshare import ( "context" "fmt" - "log" "golang.org/x/crypto/ssh" ) @@ -100,11 +99,10 @@ func (c *Client) openStreamingChannel(ctx context.Context, streamName, condition go c.processChannelRequests(ctx, reqs) requestType := fmt.Sprintf("stream-transport-%s", streamID) - acked, err := channel.SendRequest(requestType, true, nil) + _, err = channel.SendRequest(requestType, true, nil) if err != nil { return nil, fmt.Errorf("error sending channel request: %v", err) } - fmt.Println("ACKED: ", acked) return channel, nil } @@ -114,8 +112,7 @@ func (c *Client) processChannelRequests(ctx context.Context, reqs <-chan *ssh.Re select { case req := <-reqs: if req != nil { - fmt.Printf("REQ: %+v\n\n", req) - log.Println("streaming channel requests are not supported") + // TODO(josebalius): Handle } case <-ctx.Done(): break diff --git a/config.go b/config.go deleted file mode 100644 index 74eb5b178..000000000 --- a/config.go +++ /dev/null @@ -1,56 +0,0 @@ -package liveshare - -import ( - "errors" - "strings" -) - -type Option func(configuration *Configuration) error - -func WithWorkspaceID(id string) Option { - return func(configuration *Configuration) error { - configuration.WorkspaceID = id - return nil - } -} - -func WithLiveShareEndpoint(liveShareEndpoint string) Option { - return func(configuration *Configuration) error { - configuration.LiveShareEndpoint = liveShareEndpoint - return nil - } -} - -func WithToken(token string) Option { - return func(configuration *Configuration) error { - configuration.Token = token - return nil - } -} - -type Configuration struct { - WorkspaceID, LiveShareEndpoint, Token string -} - -func NewConfiguration() *Configuration { - return &Configuration{ - LiveShareEndpoint: "https://prod.liveshare.vsengsaas.visualstudio.com", - } -} - -func (c *Configuration) Validate() error { - errs := []string{} - if c.WorkspaceID == "" { - errs = append(errs, "WorkspaceID is required") - } - - if c.Token == "" { - errs = append(errs, "Token is required") - } - - if len(errs) > 0 { - return errors.New(strings.Join(errs, ", ")) - } - - return nil -} diff --git a/liveshare.go b/liveshare.go index 38222957a..3c4be5c05 100644 --- a/liveshare.go +++ b/liveshare.go @@ -1,7 +1,9 @@ package liveshare import ( + "errors" "fmt" + "strings" ) type LiveShare struct { @@ -23,3 +25,53 @@ func New(opts ...Option) (*LiveShare, error) { return &LiveShare{Configuration: configuration}, nil } + +type Option func(configuration *Configuration) error + +func WithWorkspaceID(id string) Option { + return func(configuration *Configuration) error { + configuration.WorkspaceID = id + return nil + } +} + +func WithLiveShareEndpoint(liveShareEndpoint string) Option { + return func(configuration *Configuration) error { + configuration.LiveShareEndpoint = liveShareEndpoint + return nil + } +} + +func WithToken(token string) Option { + return func(configuration *Configuration) error { + configuration.Token = token + return nil + } +} + +type Configuration struct { + WorkspaceID, LiveShareEndpoint, Token string +} + +func NewConfiguration() *Configuration { + return &Configuration{ + LiveShareEndpoint: "https://prod.liveshare.vsengsaas.visualstudio.com", + } +} + +func (c *Configuration) Validate() error { + errs := []string{} + if c.WorkspaceID == "" { + errs = append(errs, "WorkspaceID is required") + } + + if c.Token == "" { + errs = append(errs, "Token is required") + } + + if len(errs) > 0 { + return errors.New(strings.Join(errs, ", ")) + } + + return nil +} diff --git a/rpc.go b/rpc.go index e90f71ba6..de427cda9 100644 --- a/rpc.go +++ b/rpc.go @@ -2,7 +2,6 @@ package liveshare import ( "context" - "encoding/json" "fmt" "io" "sync" @@ -26,8 +25,6 @@ func (r *rpc) connect(ctx context.Context) { } func (r *rpc) do(ctx context.Context, method string, args interface{}, result interface{}) error { - b, _ := json.Marshal(args) - fmt.Println("rpc sent: ", method, string(b)) waiter, err := r.Conn.DispatchCall(ctx, method, args) if err != nil { return fmt.Errorf("error on dispatch call: %v", err) @@ -69,12 +66,6 @@ func (r *rpcHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonr r.mutex.Lock() defer r.mutex.Unlock() - fmt.Println("REQUEST") - fmt.Println("Method:", req.Method) - b, _ := req.MarshalJSON() - fmt.Println(string(b)) - fmt.Println("----") - fmt.Printf("%+v\n\n", r.eventHandlers) if handlers, ok := r.eventHandlers[req.Method]; ok { go func() { for _, handler := range handlers { @@ -88,10 +79,6 @@ func (r *rpcHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonr r.eventHandlers[req.Method] = []chan *jsonrpc2.Request{} }() } else { - fmt.Println("UNHANDLED REQUEST") - fmt.Println("Method:", req.Method) - b, _ := req.MarshalJSON() - fmt.Println(string(b)) - fmt.Println("----") + // TODO(josebalius): Handle } } diff --git a/server.go b/server.go index 65e03d584..b0f3996c9 100644 --- a/server.go +++ b/server.go @@ -36,14 +36,12 @@ type serverSharingResponse struct { func (s *Server) StartSharing(ctx context.Context, protocol string, port int) error { s.port = port - sharingStarted := s.client.rpc.handler.registerEventHandler("serverSharing.sharingStarted") var response serverSharingResponse if err := s.client.rpc.do(ctx, "serverSharing.startSharing", []interface{}{ port, protocol, fmt.Sprintf("http://localhost:%s", strconv.Itoa(port)), }, &response); err != nil { return err } - <-sharingStarted s.streamName = response.StreamName s.streamCondition = response.StreamCondition