EasyVQD/internal/web/api/grpc_plugin.go
2026-01-15 19:32:33 +08:00

41 lines
986 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"easyvqd/internal/core/host"
"easyvqd/internal/core/media"
"encoding/json"
"log/slog"
)
type PluginGRPC struct {
Core *host.Core
Media *media.Core
uc *Usecase
}
func NewPluginGRPC(core *host.Core, mediaCore *media.Core, uc *Usecase) *PluginGRPC {
return &PluginGRPC{
Core: core,
Media: mediaCore,
uc: uc,
}
}
// 与Host刚建立连接就会通信如果回调函数放在了API层来不及注册回调影响通信
func RegisterPluginGRPC(hostCore *host.Core, mediaCore *media.Core, uc *Usecase) {
hostGRPC := NewPluginGRPC(hostCore, mediaCore, uc)
plugin := hostCore.Plugin
plugin.AddResponseHandler("start", hostGRPC.start)
// 这部分是主动处理Host的请求
}
func (pg PluginGRPC) start(requestID string, args json.RawMessage) (interface{}, error) {
slog.Info("Received 'start' from host", "request_id", requestID, "args", args)
return map[string]interface{}{
"status": "started",
"task": "task",
}, nil
}