fix: refactor signaler; fix logic for local watcher

This commit is contained in:
Charles Hathaway
2023-09-21 21:50:13 -07:00
parent 9bbe917e59
commit 7fbd4fff69
8 changed files with 920 additions and 1076 deletions
+67 -152
View File
@@ -42,24 +42,15 @@ const (
// SignalerServiceCreateSessionProcedure is the fully-qualified name of the SignalerService's
// CreateSession RPC.
SignalerServiceCreateSessionProcedure = "/signaler.SignalerService/CreateSession"
// SignalerServiceUpdateSessionProcedure is the fully-qualified name of the SignalerService's
// UpdateSession RPC.
SignalerServiceUpdateSessionProcedure = "/signaler.SignalerService/UpdateSession"
// SignalerServiceListSessionsProcedure is the fully-qualified name of the SignalerService's
// ListSessions RPC.
SignalerServiceListSessionsProcedure = "/signaler.SignalerService/ListSessions"
// SignalerServiceCreateIceCandidateProcedure is the fully-qualified name of the SignalerService's
// CreateIceCandidate RPC.
SignalerServiceCreateIceCandidateProcedure = "/signaler.SignalerService/CreateIceCandidate"
// SignalerServicePopIceCandidateProcedure is the fully-qualified name of the SignalerService's
// PopIceCandidate RPC.
SignalerServicePopIceCandidateProcedure = "/signaler.SignalerService/PopIceCandidate"
// SignalerServiceCreateIceSessionDescriptionProcedure is the fully-qualified name of the
// SignalerService's CreateIceSessionDescription RPC.
SignalerServiceCreateIceSessionDescriptionProcedure = "/signaler.SignalerService/CreateIceSessionDescription"
// SignalerServicePopIceSessionDescriptionProcedure is the fully-qualified name of the
// SignalerService's PopIceSessionDescription RPC.
SignalerServicePopIceSessionDescriptionProcedure = "/signaler.SignalerService/PopIceSessionDescription"
// SignalerServicePopSessionProcedure is the fully-qualified name of the SignalerService's
// PopSession RPC.
SignalerServicePopSessionProcedure = "/signaler.SignalerService/PopSession"
// SignalerServiceCreateIceMessageProcedure is the fully-qualified name of the SignalerService's
// CreateIceMessage RPC.
SignalerServiceCreateIceMessageProcedure = "/signaler.SignalerService/CreateIceMessage"
// SignalerServicePopIceMessageProcedure is the fully-qualified name of the SignalerService's
// PopIceMessage RPC.
SignalerServicePopIceMessageProcedure = "/signaler.SignalerService/PopIceMessage"
)
// SignalerServiceClient is a client for the signaler.SignalerService service.
@@ -71,21 +62,16 @@ type SignalerServiceClient interface {
// Optionally, wait_for_update can be set to prevent returning until the Camera has seen the
// session request, populated candidates, and returned a session offer.
CreateSession(context.Context, *connect.Request[gen.CreateSessionRequest]) (*connect.Response[gen.Session], error)
// UpdateSession updates the session
UpdateSession(context.Context, *connect.Request[gen.UpdateSessionRequest]) (*connect.Response[gen.Session], error)
// ListSessions lists all sessions the client should consider.
// PopSession deletes a session from the list of sessions, and returns it.
//
// TODO: it would be better if we could alert a camera to poll for sessions
// i.e., with websockets (or streaming RPCs).
ListSessions(context.Context, *connect.Request[gen.ListSessionsRequest]) (*connect.Response[gen.ListSessionsResponse], error)
// CreateIceCandidate adds the provided candidate to the list of candidates.
CreateIceCandidate(context.Context, *connect.Request[gen.CreateIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error)
// PopIceCandidate delete a candidate from the list of candidates and returns it.
// If there are no sessions, this blocks until one becomes available.
PopSession(context.Context, *connect.Request[gen.PopSessionRequest]) (*connect.Response[gen.Session], error)
// CreateIceMessage adds the provided message to the list of candidates.
CreateIceMessage(context.Context, *connect.Request[gen.CreateIceMessageRequest]) (*connect.Response[gen.IceMessage], error)
// PopIceCandidate delete a message from the list of messages and returns it.
//
// If there are no candidates, this blocks until one becomes available.
PopIceCandidate(context.Context, *connect.Request[gen.PopIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error)
CreateIceSessionDescription(context.Context, *connect.Request[gen.CreateIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error)
PopIceSessionDescription(context.Context, *connect.Request[gen.PopIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error)
// If there are no messages, this blocks until one becomes available.
PopIceMessage(context.Context, *connect.Request[gen.PopIceMessageRequest]) (*connect.Response[gen.IceMessage], error)
}
// NewSignalerServiceClient constructs a client for the signaler.SignalerService service. By
@@ -113,34 +99,19 @@ func NewSignalerServiceClient(httpClient connect.HTTPClient, baseURL string, opt
baseURL+SignalerServiceCreateSessionProcedure,
opts...,
),
updateSession: connect.NewClient[gen.UpdateSessionRequest, gen.Session](
popSession: connect.NewClient[gen.PopSessionRequest, gen.Session](
httpClient,
baseURL+SignalerServiceUpdateSessionProcedure,
baseURL+SignalerServicePopSessionProcedure,
opts...,
),
listSessions: connect.NewClient[gen.ListSessionsRequest, gen.ListSessionsResponse](
createIceMessage: connect.NewClient[gen.CreateIceMessageRequest, gen.IceMessage](
httpClient,
baseURL+SignalerServiceListSessionsProcedure,
baseURL+SignalerServiceCreateIceMessageProcedure,
opts...,
),
createIceCandidate: connect.NewClient[gen.CreateIceCandidateRequest, gen.IceCandidate](
popIceMessage: connect.NewClient[gen.PopIceMessageRequest, gen.IceMessage](
httpClient,
baseURL+SignalerServiceCreateIceCandidateProcedure,
opts...,
),
popIceCandidate: connect.NewClient[gen.PopIceCandidateRequest, gen.IceCandidate](
httpClient,
baseURL+SignalerServicePopIceCandidateProcedure,
opts...,
),
createIceSessionDescription: connect.NewClient[gen.CreateIceSessionDescriptionRequest, gen.IceSessionDescription](
httpClient,
baseURL+SignalerServiceCreateIceSessionDescriptionProcedure,
opts...,
),
popIceSessionDescription: connect.NewClient[gen.PopIceSessionDescriptionRequest, gen.IceSessionDescription](
httpClient,
baseURL+SignalerServicePopIceSessionDescriptionProcedure,
baseURL+SignalerServicePopIceMessageProcedure,
opts...,
),
}
@@ -148,15 +119,12 @@ func NewSignalerServiceClient(httpClient connect.HTTPClient, baseURL string, opt
// signalerServiceClient implements SignalerServiceClient.
type signalerServiceClient struct {
createAuthToken *connect.Client[gen.CreateAuthTokenRequest, gen.AuthToken]
listCameras *connect.Client[gen.ListCamerasRequest, gen.ListCamerasResponse]
createSession *connect.Client[gen.CreateSessionRequest, gen.Session]
updateSession *connect.Client[gen.UpdateSessionRequest, gen.Session]
listSessions *connect.Client[gen.ListSessionsRequest, gen.ListSessionsResponse]
createIceCandidate *connect.Client[gen.CreateIceCandidateRequest, gen.IceCandidate]
popIceCandidate *connect.Client[gen.PopIceCandidateRequest, gen.IceCandidate]
createIceSessionDescription *connect.Client[gen.CreateIceSessionDescriptionRequest, gen.IceSessionDescription]
popIceSessionDescription *connect.Client[gen.PopIceSessionDescriptionRequest, gen.IceSessionDescription]
createAuthToken *connect.Client[gen.CreateAuthTokenRequest, gen.AuthToken]
listCameras *connect.Client[gen.ListCamerasRequest, gen.ListCamerasResponse]
createSession *connect.Client[gen.CreateSessionRequest, gen.Session]
popSession *connect.Client[gen.PopSessionRequest, gen.Session]
createIceMessage *connect.Client[gen.CreateIceMessageRequest, gen.IceMessage]
popIceMessage *connect.Client[gen.PopIceMessageRequest, gen.IceMessage]
}
// CreateAuthToken calls signaler.SignalerService.CreateAuthToken.
@@ -174,34 +142,19 @@ func (c *signalerServiceClient) CreateSession(ctx context.Context, req *connect.
return c.createSession.CallUnary(ctx, req)
}
// UpdateSession calls signaler.SignalerService.UpdateSession.
func (c *signalerServiceClient) UpdateSession(ctx context.Context, req *connect.Request[gen.UpdateSessionRequest]) (*connect.Response[gen.Session], error) {
return c.updateSession.CallUnary(ctx, req)
// PopSession calls signaler.SignalerService.PopSession.
func (c *signalerServiceClient) PopSession(ctx context.Context, req *connect.Request[gen.PopSessionRequest]) (*connect.Response[gen.Session], error) {
return c.popSession.CallUnary(ctx, req)
}
// ListSessions calls signaler.SignalerService.ListSessions.
func (c *signalerServiceClient) ListSessions(ctx context.Context, req *connect.Request[gen.ListSessionsRequest]) (*connect.Response[gen.ListSessionsResponse], error) {
return c.listSessions.CallUnary(ctx, req)
// CreateIceMessage calls signaler.SignalerService.CreateIceMessage.
func (c *signalerServiceClient) CreateIceMessage(ctx context.Context, req *connect.Request[gen.CreateIceMessageRequest]) (*connect.Response[gen.IceMessage], error) {
return c.createIceMessage.CallUnary(ctx, req)
}
// CreateIceCandidate calls signaler.SignalerService.CreateIceCandidate.
func (c *signalerServiceClient) CreateIceCandidate(ctx context.Context, req *connect.Request[gen.CreateIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error) {
return c.createIceCandidate.CallUnary(ctx, req)
}
// PopIceCandidate calls signaler.SignalerService.PopIceCandidate.
func (c *signalerServiceClient) PopIceCandidate(ctx context.Context, req *connect.Request[gen.PopIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error) {
return c.popIceCandidate.CallUnary(ctx, req)
}
// CreateIceSessionDescription calls signaler.SignalerService.CreateIceSessionDescription.
func (c *signalerServiceClient) CreateIceSessionDescription(ctx context.Context, req *connect.Request[gen.CreateIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error) {
return c.createIceSessionDescription.CallUnary(ctx, req)
}
// PopIceSessionDescription calls signaler.SignalerService.PopIceSessionDescription.
func (c *signalerServiceClient) PopIceSessionDescription(ctx context.Context, req *connect.Request[gen.PopIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error) {
return c.popIceSessionDescription.CallUnary(ctx, req)
// PopIceMessage calls signaler.SignalerService.PopIceMessage.
func (c *signalerServiceClient) PopIceMessage(ctx context.Context, req *connect.Request[gen.PopIceMessageRequest]) (*connect.Response[gen.IceMessage], error) {
return c.popIceMessage.CallUnary(ctx, req)
}
// SignalerServiceHandler is an implementation of the signaler.SignalerService service.
@@ -213,21 +166,16 @@ type SignalerServiceHandler interface {
// Optionally, wait_for_update can be set to prevent returning until the Camera has seen the
// session request, populated candidates, and returned a session offer.
CreateSession(context.Context, *connect.Request[gen.CreateSessionRequest]) (*connect.Response[gen.Session], error)
// UpdateSession updates the session
UpdateSession(context.Context, *connect.Request[gen.UpdateSessionRequest]) (*connect.Response[gen.Session], error)
// ListSessions lists all sessions the client should consider.
// PopSession deletes a session from the list of sessions, and returns it.
//
// TODO: it would be better if we could alert a camera to poll for sessions
// i.e., with websockets (or streaming RPCs).
ListSessions(context.Context, *connect.Request[gen.ListSessionsRequest]) (*connect.Response[gen.ListSessionsResponse], error)
// CreateIceCandidate adds the provided candidate to the list of candidates.
CreateIceCandidate(context.Context, *connect.Request[gen.CreateIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error)
// PopIceCandidate delete a candidate from the list of candidates and returns it.
// If there are no sessions, this blocks until one becomes available.
PopSession(context.Context, *connect.Request[gen.PopSessionRequest]) (*connect.Response[gen.Session], error)
// CreateIceMessage adds the provided message to the list of candidates.
CreateIceMessage(context.Context, *connect.Request[gen.CreateIceMessageRequest]) (*connect.Response[gen.IceMessage], error)
// PopIceCandidate delete a message from the list of messages and returns it.
//
// If there are no candidates, this blocks until one becomes available.
PopIceCandidate(context.Context, *connect.Request[gen.PopIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error)
CreateIceSessionDescription(context.Context, *connect.Request[gen.CreateIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error)
PopIceSessionDescription(context.Context, *connect.Request[gen.PopIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error)
// If there are no messages, this blocks until one becomes available.
PopIceMessage(context.Context, *connect.Request[gen.PopIceMessageRequest]) (*connect.Response[gen.IceMessage], error)
}
// NewSignalerServiceHandler builds an HTTP handler from the service implementation. It returns the
@@ -251,34 +199,19 @@ func NewSignalerServiceHandler(svc SignalerServiceHandler, opts ...connect.Handl
svc.CreateSession,
opts...,
)
signalerServiceUpdateSessionHandler := connect.NewUnaryHandler(
SignalerServiceUpdateSessionProcedure,
svc.UpdateSession,
signalerServicePopSessionHandler := connect.NewUnaryHandler(
SignalerServicePopSessionProcedure,
svc.PopSession,
opts...,
)
signalerServiceListSessionsHandler := connect.NewUnaryHandler(
SignalerServiceListSessionsProcedure,
svc.ListSessions,
signalerServiceCreateIceMessageHandler := connect.NewUnaryHandler(
SignalerServiceCreateIceMessageProcedure,
svc.CreateIceMessage,
opts...,
)
signalerServiceCreateIceCandidateHandler := connect.NewUnaryHandler(
SignalerServiceCreateIceCandidateProcedure,
svc.CreateIceCandidate,
opts...,
)
signalerServicePopIceCandidateHandler := connect.NewUnaryHandler(
SignalerServicePopIceCandidateProcedure,
svc.PopIceCandidate,
opts...,
)
signalerServiceCreateIceSessionDescriptionHandler := connect.NewUnaryHandler(
SignalerServiceCreateIceSessionDescriptionProcedure,
svc.CreateIceSessionDescription,
opts...,
)
signalerServicePopIceSessionDescriptionHandler := connect.NewUnaryHandler(
SignalerServicePopIceSessionDescriptionProcedure,
svc.PopIceSessionDescription,
signalerServicePopIceMessageHandler := connect.NewUnaryHandler(
SignalerServicePopIceMessageProcedure,
svc.PopIceMessage,
opts...,
)
return "/signaler.SignalerService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -289,18 +222,12 @@ func NewSignalerServiceHandler(svc SignalerServiceHandler, opts ...connect.Handl
signalerServiceListCamerasHandler.ServeHTTP(w, r)
case SignalerServiceCreateSessionProcedure:
signalerServiceCreateSessionHandler.ServeHTTP(w, r)
case SignalerServiceUpdateSessionProcedure:
signalerServiceUpdateSessionHandler.ServeHTTP(w, r)
case SignalerServiceListSessionsProcedure:
signalerServiceListSessionsHandler.ServeHTTP(w, r)
case SignalerServiceCreateIceCandidateProcedure:
signalerServiceCreateIceCandidateHandler.ServeHTTP(w, r)
case SignalerServicePopIceCandidateProcedure:
signalerServicePopIceCandidateHandler.ServeHTTP(w, r)
case SignalerServiceCreateIceSessionDescriptionProcedure:
signalerServiceCreateIceSessionDescriptionHandler.ServeHTTP(w, r)
case SignalerServicePopIceSessionDescriptionProcedure:
signalerServicePopIceSessionDescriptionHandler.ServeHTTP(w, r)
case SignalerServicePopSessionProcedure:
signalerServicePopSessionHandler.ServeHTTP(w, r)
case SignalerServiceCreateIceMessageProcedure:
signalerServiceCreateIceMessageHandler.ServeHTTP(w, r)
case SignalerServicePopIceMessageProcedure:
signalerServicePopIceMessageHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
@@ -322,26 +249,14 @@ func (UnimplementedSignalerServiceHandler) CreateSession(context.Context, *conne
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.CreateSession is not implemented"))
}
func (UnimplementedSignalerServiceHandler) UpdateSession(context.Context, *connect.Request[gen.UpdateSessionRequest]) (*connect.Response[gen.Session], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.UpdateSession is not implemented"))
func (UnimplementedSignalerServiceHandler) PopSession(context.Context, *connect.Request[gen.PopSessionRequest]) (*connect.Response[gen.Session], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.PopSession is not implemented"))
}
func (UnimplementedSignalerServiceHandler) ListSessions(context.Context, *connect.Request[gen.ListSessionsRequest]) (*connect.Response[gen.ListSessionsResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.ListSessions is not implemented"))
func (UnimplementedSignalerServiceHandler) CreateIceMessage(context.Context, *connect.Request[gen.CreateIceMessageRequest]) (*connect.Response[gen.IceMessage], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.CreateIceMessage is not implemented"))
}
func (UnimplementedSignalerServiceHandler) CreateIceCandidate(context.Context, *connect.Request[gen.CreateIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.CreateIceCandidate is not implemented"))
}
func (UnimplementedSignalerServiceHandler) PopIceCandidate(context.Context, *connect.Request[gen.PopIceCandidateRequest]) (*connect.Response[gen.IceCandidate], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.PopIceCandidate is not implemented"))
}
func (UnimplementedSignalerServiceHandler) CreateIceSessionDescription(context.Context, *connect.Request[gen.CreateIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.CreateIceSessionDescription is not implemented"))
}
func (UnimplementedSignalerServiceHandler) PopIceSessionDescription(context.Context, *connect.Request[gen.PopIceSessionDescriptionRequest]) (*connect.Response[gen.IceSessionDescription], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.PopIceSessionDescription is not implemented"))
func (UnimplementedSignalerServiceHandler) PopIceMessage(context.Context, *connect.Request[gen.PopIceMessageRequest]) (*connect.Response[gen.IceMessage], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("signaler.SignalerService.PopIceMessage is not implemented"))
}