hook up wsh router to wps

This commit is contained in:
sawka 2024-08-13 18:19:29 -07:00
parent 844451ea0d
commit c962391b71
3 changed files with 22 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import (
"github.com/wavetermdev/thenextwave/pkg/wcloud"
"github.com/wavetermdev/thenextwave/pkg/wconfig"
"github.com/wavetermdev/thenextwave/pkg/web"
"github.com/wavetermdev/thenextwave/pkg/wps"
"github.com/wavetermdev/thenextwave/pkg/wshrpc/wshserver"
"github.com/wavetermdev/thenextwave/pkg/wshutil"
"github.com/wavetermdev/thenextwave/pkg/wstore"
@ -151,6 +152,7 @@ func createMainWshClient() {
rpc := wshserver.GetMainRpcClient()
wshutil.DefaultRouter.RegisterRoute("wavesrv", rpc)
wshutil.DefaultRouter.SetDefaultRoute("wavesrv")
wps.Broker.SetClient(wshutil.DefaultRouter)
}
func main() {

View File

@ -49,6 +49,7 @@ const (
Command_Test = "test"
Command_RemoteStreamFile = "remotestreamfile"
Command_RemoteFileInfo = "remotefileinfo"
Command_Event = "event"
)
type RespOrErrorUnion[T any] struct {

View File

@ -47,6 +47,25 @@ func noRouteErr(routeId string) error {
return fmt.Errorf("no route for %q", routeId)
}
func (router *WshRouter) SendEvent(fullRoute string, event wshrpc.WaveEvent) {
nextRoute, routeId := popRoute(fullRoute)
rpc := router.GetRpc(routeId)
if rpc == nil {
return
}
msg := RpcMessage{
Command: wshrpc.Command_Event,
Route: nextRoute,
Data: event,
}
msgBytes, err := json.Marshal(msg)
if err != nil {
// nothing to do
return
}
rpc.SendRpcMessage(msgBytes)
}
func (router *WshRouter) handleNoRoute(msg RpcMessage) {
nrErr := noRouteErr(msg.Route)
if msg.ReqId == "" {