Some polish and module replacement
This commit is contained in:
parent
04a6383ccb
commit
53fd96d22e
6 changed files with 55 additions and 78 deletions
1
api.go
1
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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
56
config.go
56
config.go
|
|
@ -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
|
||||
}
|
||||
52
liveshare.go
52
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
|
||||
}
|
||||
|
|
|
|||
15
rpc.go
15
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue