mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-10-06 16:07:11 +08:00
Initial commit, pt. 26
This commit is contained in:
@@ -32,6 +32,7 @@ type StreamD interface {
|
|||||||
EndStream(ctx context.Context, platID streamcontrol.PlatformName) error
|
EndStream(ctx context.Context, platID streamcontrol.PlatformName) error
|
||||||
GitRelogin(ctx context.Context) error
|
GitRelogin(ctx context.Context) error
|
||||||
GetBackendData(ctx context.Context, platID streamcontrol.PlatformName) (any, error)
|
GetBackendData(ctx context.Context, platID streamcontrol.PlatformName) (any, error)
|
||||||
|
Restart(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type BackendDataOBS struct{}
|
type BackendDataOBS struct{}
|
||||||
|
@@ -2,27 +2,57 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/xaionaro-go/streamctl/pkg/streamcontrol"
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol"
|
||||||
"github.com/xaionaro-go/streamctl/pkg/streamd/api"
|
"github.com/xaionaro-go/streamctl/pkg/streamd/api"
|
||||||
"github.com/xaionaro-go/streamctl/pkg/streamd/config"
|
"github.com/xaionaro-go/streamctl/pkg/streamd/config"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamd/grpc/go/streamd_grpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct{}
|
type Client struct {
|
||||||
|
URL *url.URL
|
||||||
|
}
|
||||||
|
|
||||||
var _ api.StreamD = (*Client)(nil)
|
var _ api.StreamD = (*Client)(nil)
|
||||||
|
|
||||||
func New(url *url.URL) *Client {
|
func New(url *url.URL) *Client {
|
||||||
panic("not implemented")
|
return &Client{URL: url}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) grpcClient() (streamd_grpc.StreamDClient, *grpc.ClientConn, error) {
|
||||||
|
conn, err := grpc.NewClient(c.URL.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("unable to initialize a gRPC client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
client := streamd_grpc.NewStreamDClient(conn)
|
||||||
|
return client, conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) FetchConfig(ctx context.Context) error {
|
func (c *Client) FetchConfig(ctx context.Context) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.OBSOLETE_FetchConfig(ctx, &streamd_grpc.OBSOLETE_FetchConfigRequest{})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) InitCache(ctx context.Context) error {
|
func (c *Client) InitCache(ctx context.Context) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.InitCache(ctx, &streamd_grpc.InitCacheRequest{})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SetPlatformConfig(
|
func (c *Client) SetPlatformConfig(
|
||||||
@@ -34,27 +64,94 @@ func (c *Client) SetPlatformConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SaveConfig(ctx context.Context) error {
|
func (c *Client) SaveConfig(ctx context.Context) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.SaveConfig(ctx, &streamd_grpc.SaveConfigRequest{})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ResetCache(ctx context.Context) error {
|
func (c *Client) ResetCache(ctx context.Context) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.ResetCache(ctx, &streamd_grpc.ResetCacheRequest{})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetConfig(ctx context.Context) (*config.Config, error) {
|
func (c *Client) GetConfig(ctx context.Context) (*config.Config, error) {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
reply, err := client.GetConfig(ctx, &streamd_grpc.GetConfigRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to request the config: %w", err)
|
||||||
|
}
|
||||||
|
var config config.Config
|
||||||
|
err = json.Unmarshal([]byte(reply.Config), &config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to unserialize the received config: %w", err)
|
||||||
|
}
|
||||||
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SetConfig(ctx context.Context, cfg *config.Config) error {
|
func (c *Client) SetConfig(ctx context.Context, cfg *config.Config) error {
|
||||||
panic("not implemented")
|
b, err := json.Marshal(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to serialize the config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req := &streamd_grpc.SetConfigRequest{
|
||||||
|
Config: string(b),
|
||||||
|
}
|
||||||
|
|
||||||
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.SetConfig(ctx, req)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) IsBackendEnabled(ctx context.Context, id streamcontrol.PlatformName) (bool, error) {
|
func (c *Client) IsBackendEnabled(ctx context.Context, id streamcontrol.PlatformName) (bool, error) {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
reply, err := client.GetBackendInfo(ctx, &streamd_grpc.GetBackendInfoRequest{
|
||||||
|
PlatID: string(id),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("unable to get backend info: %w", err)
|
||||||
|
}
|
||||||
|
return reply.IsInitialized, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) IsGITInitialized(ctx context.Context) (bool, error) {
|
func (c *Client) IsGITInitialized(ctx context.Context) (bool, error) {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
reply, err := client.OBSOLETE_GitInfo(ctx, &streamd_grpc.OBSOLETE_GetGitInfoRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("unable to get backend info: %w", err)
|
||||||
|
}
|
||||||
|
return reply.IsInitialized, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) StartStream(
|
func (c *Client) StartStream(
|
||||||
@@ -64,16 +161,74 @@ func (c *Client) StartStream(
|
|||||||
profile streamcontrol.AbstractStreamProfile,
|
profile streamcontrol.AbstractStreamProfile,
|
||||||
customArgs ...any,
|
customArgs ...any,
|
||||||
) error {
|
) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
b, err := json.Marshal(profile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to serialize the profile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.StartStream(ctx, &streamd_grpc.StartStreamRequest{
|
||||||
|
PlatID: string(platID),
|
||||||
|
Title: title,
|
||||||
|
Description: description,
|
||||||
|
Profile: string(b),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to start the stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func (c *Client) EndStream(ctx context.Context, platID streamcontrol.PlatformName) error {
|
func (c *Client) EndStream(ctx context.Context, platID streamcontrol.PlatformName) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.EndStream(ctx, &streamd_grpc.EndStreamRequest{PlatID: string(platID)})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to end the stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GitRelogin(ctx context.Context) error {
|
func (c *Client) GitRelogin(ctx context.Context) error {
|
||||||
panic("not implemented")
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.OBSOLETE_GitRelogin(ctx, &streamd_grpc.OBSOLETE_GitReloginRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable force git relogin: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetBackendData(ctx context.Context, platID streamcontrol.PlatformName) (any, error) {
|
func (c *Client) GetBackendData(ctx context.Context, platID streamcontrol.PlatformName) (any, error) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Restart(ctx context.Context) error {
|
||||||
|
client, conn, err := c.grpcClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = client.Restart(ctx, &streamd_grpc.RestartRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable restart the server: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
6
pkg/streamd/grpc/Makefile
Normal file
6
pkg/streamd/grpc/Makefile
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
all: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
protoc --go_out=. --go-grpc_out=. streamd.proto
|
||||||
|
|
1520
pkg/streamd/grpc/go/streamd_grpc/streamd.pb.go
Normal file
1520
pkg/streamd/grpc/go/streamd_grpc/streamd.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
501
pkg/streamd/grpc/go/streamd_grpc/streamd_grpc.pb.go
Normal file
501
pkg/streamd/grpc/go/streamd_grpc/streamd_grpc.pb.go
Normal file
@@ -0,0 +1,501 @@
|
|||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.2.0
|
||||||
|
// - protoc v3.21.12
|
||||||
|
// source: streamd.proto
|
||||||
|
|
||||||
|
package streamd_grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.32.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion7
|
||||||
|
|
||||||
|
// StreamDClient is the client API for StreamD service.
|
||||||
|
//
|
||||||
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
|
type StreamDClient interface {
|
||||||
|
GetConfig(ctx context.Context, in *GetConfigRequest, opts ...grpc.CallOption) (*GetConfigReply, error)
|
||||||
|
SetConfig(ctx context.Context, in *SetConfigRequest, opts ...grpc.CallOption) (*SetConfigReply, error)
|
||||||
|
SaveConfig(ctx context.Context, in *SaveConfigRequest, opts ...grpc.CallOption) (*SaveConfigReply, error)
|
||||||
|
ResetCache(ctx context.Context, in *ResetCacheRequest, opts ...grpc.CallOption) (*ResetCacheReply, error)
|
||||||
|
InitCache(ctx context.Context, in *InitCacheRequest, opts ...grpc.CallOption) (*InitCacheReply, error)
|
||||||
|
StartStream(ctx context.Context, in *StartStreamRequest, opts ...grpc.CallOption) (*StartStreamReply, error)
|
||||||
|
EndStream(ctx context.Context, in *EndStreamRequest, opts ...grpc.CallOption) (*EndStreamReply, error)
|
||||||
|
GetBackendInfo(ctx context.Context, in *GetBackendInfoRequest, opts ...grpc.CallOption) (*GetBackendInfoReply, error)
|
||||||
|
Restart(ctx context.Context, in *RestartRequest, opts ...grpc.CallOption) (*RestartReply, error)
|
||||||
|
OBSOLETE_FetchConfig(ctx context.Context, in *OBSOLETE_FetchConfigRequest, opts ...grpc.CallOption) (*OBSOLETE_FetchConfigReply, error)
|
||||||
|
OBSOLETE_GitInfo(ctx context.Context, in *OBSOLETE_GetGitInfoRequest, opts ...grpc.CallOption) (*OBSOLETE_GetGitInfoReply, error)
|
||||||
|
OBSOLETE_GitRelogin(ctx context.Context, in *OBSOLETE_GitReloginRequest, opts ...grpc.CallOption) (*OBSOLETE_GitReloginReply, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type streamDClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStreamDClient(cc grpc.ClientConnInterface) StreamDClient {
|
||||||
|
return &streamDClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) GetConfig(ctx context.Context, in *GetConfigRequest, opts ...grpc.CallOption) (*GetConfigReply, error) {
|
||||||
|
out := new(GetConfigReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/GetConfig", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) SetConfig(ctx context.Context, in *SetConfigRequest, opts ...grpc.CallOption) (*SetConfigReply, error) {
|
||||||
|
out := new(SetConfigReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/SetConfig", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) SaveConfig(ctx context.Context, in *SaveConfigRequest, opts ...grpc.CallOption) (*SaveConfigReply, error) {
|
||||||
|
out := new(SaveConfigReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/SaveConfig", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) ResetCache(ctx context.Context, in *ResetCacheRequest, opts ...grpc.CallOption) (*ResetCacheReply, error) {
|
||||||
|
out := new(ResetCacheReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/ResetCache", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) InitCache(ctx context.Context, in *InitCacheRequest, opts ...grpc.CallOption) (*InitCacheReply, error) {
|
||||||
|
out := new(InitCacheReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/InitCache", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) StartStream(ctx context.Context, in *StartStreamRequest, opts ...grpc.CallOption) (*StartStreamReply, error) {
|
||||||
|
out := new(StartStreamReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/StartStream", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) EndStream(ctx context.Context, in *EndStreamRequest, opts ...grpc.CallOption) (*EndStreamReply, error) {
|
||||||
|
out := new(EndStreamReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/EndStream", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) GetBackendInfo(ctx context.Context, in *GetBackendInfoRequest, opts ...grpc.CallOption) (*GetBackendInfoReply, error) {
|
||||||
|
out := new(GetBackendInfoReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/GetBackendInfo", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) Restart(ctx context.Context, in *RestartRequest, opts ...grpc.CallOption) (*RestartReply, error) {
|
||||||
|
out := new(RestartReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/Restart", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) OBSOLETE_FetchConfig(ctx context.Context, in *OBSOLETE_FetchConfigRequest, opts ...grpc.CallOption) (*OBSOLETE_FetchConfigReply, error) {
|
||||||
|
out := new(OBSOLETE_FetchConfigReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/OBSOLETE_FetchConfig", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) OBSOLETE_GitInfo(ctx context.Context, in *OBSOLETE_GetGitInfoRequest, opts ...grpc.CallOption) (*OBSOLETE_GetGitInfoReply, error) {
|
||||||
|
out := new(OBSOLETE_GetGitInfoReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/OBSOLETE_GitInfo", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *streamDClient) OBSOLETE_GitRelogin(ctx context.Context, in *OBSOLETE_GitReloginRequest, opts ...grpc.CallOption) (*OBSOLETE_GitReloginReply, error) {
|
||||||
|
out := new(OBSOLETE_GitReloginReply)
|
||||||
|
err := c.cc.Invoke(ctx, "/StreamD/OBSOLETE_GitRelogin", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StreamDServer is the server API for StreamD service.
|
||||||
|
// All implementations must embed UnimplementedStreamDServer
|
||||||
|
// for forward compatibility
|
||||||
|
type StreamDServer interface {
|
||||||
|
GetConfig(context.Context, *GetConfigRequest) (*GetConfigReply, error)
|
||||||
|
SetConfig(context.Context, *SetConfigRequest) (*SetConfigReply, error)
|
||||||
|
SaveConfig(context.Context, *SaveConfigRequest) (*SaveConfigReply, error)
|
||||||
|
ResetCache(context.Context, *ResetCacheRequest) (*ResetCacheReply, error)
|
||||||
|
InitCache(context.Context, *InitCacheRequest) (*InitCacheReply, error)
|
||||||
|
StartStream(context.Context, *StartStreamRequest) (*StartStreamReply, error)
|
||||||
|
EndStream(context.Context, *EndStreamRequest) (*EndStreamReply, error)
|
||||||
|
GetBackendInfo(context.Context, *GetBackendInfoRequest) (*GetBackendInfoReply, error)
|
||||||
|
Restart(context.Context, *RestartRequest) (*RestartReply, error)
|
||||||
|
OBSOLETE_FetchConfig(context.Context, *OBSOLETE_FetchConfigRequest) (*OBSOLETE_FetchConfigReply, error)
|
||||||
|
OBSOLETE_GitInfo(context.Context, *OBSOLETE_GetGitInfoRequest) (*OBSOLETE_GetGitInfoReply, error)
|
||||||
|
OBSOLETE_GitRelogin(context.Context, *OBSOLETE_GitReloginRequest) (*OBSOLETE_GitReloginReply, error)
|
||||||
|
mustEmbedUnimplementedStreamDServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedStreamDServer must be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedStreamDServer struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedStreamDServer) GetConfig(context.Context, *GetConfigRequest) (*GetConfigReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetConfig not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) SetConfig(context.Context, *SetConfigRequest) (*SetConfigReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method SetConfig not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) SaveConfig(context.Context, *SaveConfigRequest) (*SaveConfigReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method SaveConfig not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) ResetCache(context.Context, *ResetCacheRequest) (*ResetCacheReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method ResetCache not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) InitCache(context.Context, *InitCacheRequest) (*InitCacheReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method InitCache not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) StartStream(context.Context, *StartStreamRequest) (*StartStreamReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method StartStream not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) EndStream(context.Context, *EndStreamRequest) (*EndStreamReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method EndStream not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) GetBackendInfo(context.Context, *GetBackendInfoRequest) (*GetBackendInfoReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetBackendInfo not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) Restart(context.Context, *RestartRequest) (*RestartReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method Restart not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) OBSOLETE_FetchConfig(context.Context, *OBSOLETE_FetchConfigRequest) (*OBSOLETE_FetchConfigReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method OBSOLETE_FetchConfig not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) OBSOLETE_GitInfo(context.Context, *OBSOLETE_GetGitInfoRequest) (*OBSOLETE_GetGitInfoReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method OBSOLETE_GitInfo not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) OBSOLETE_GitRelogin(context.Context, *OBSOLETE_GitReloginRequest) (*OBSOLETE_GitReloginReply, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method OBSOLETE_GitRelogin not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedStreamDServer) mustEmbedUnimplementedStreamDServer() {}
|
||||||
|
|
||||||
|
// UnsafeStreamDServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to StreamDServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeStreamDServer interface {
|
||||||
|
mustEmbedUnimplementedStreamDServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterStreamDServer(s grpc.ServiceRegistrar, srv StreamDServer) {
|
||||||
|
s.RegisterService(&StreamD_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_GetConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetConfigRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).GetConfig(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/GetConfig",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).GetConfig(ctx, req.(*GetConfigRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_SetConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SetConfigRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).SetConfig(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/SetConfig",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).SetConfig(ctx, req.(*SetConfigRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_SaveConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SaveConfigRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).SaveConfig(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/SaveConfig",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).SaveConfig(ctx, req.(*SaveConfigRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_ResetCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ResetCacheRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).ResetCache(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/ResetCache",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).ResetCache(ctx, req.(*ResetCacheRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_InitCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(InitCacheRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).InitCache(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/InitCache",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).InitCache(ctx, req.(*InitCacheRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_StartStream_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(StartStreamRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).StartStream(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/StartStream",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).StartStream(ctx, req.(*StartStreamRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_EndStream_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(EndStreamRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).EndStream(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/EndStream",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).EndStream(ctx, req.(*EndStreamRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_GetBackendInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetBackendInfoRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).GetBackendInfo(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/GetBackendInfo",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).GetBackendInfo(ctx, req.(*GetBackendInfoRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_Restart_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(RestartRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).Restart(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/Restart",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).Restart(ctx, req.(*RestartRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_OBSOLETE_FetchConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OBSOLETE_FetchConfigRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).OBSOLETE_FetchConfig(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/OBSOLETE_FetchConfig",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).OBSOLETE_FetchConfig(ctx, req.(*OBSOLETE_FetchConfigRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_OBSOLETE_GitInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OBSOLETE_GetGitInfoRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).OBSOLETE_GitInfo(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/OBSOLETE_GitInfo",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).OBSOLETE_GitInfo(ctx, req.(*OBSOLETE_GetGitInfoRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _StreamD_OBSOLETE_GitRelogin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(OBSOLETE_GitReloginRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StreamDServer).OBSOLETE_GitRelogin(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/StreamD/OBSOLETE_GitRelogin",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StreamDServer).OBSOLETE_GitRelogin(ctx, req.(*OBSOLETE_GitReloginRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StreamD_ServiceDesc is the grpc.ServiceDesc for StreamD service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var StreamD_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "StreamD",
|
||||||
|
HandlerType: (*StreamDServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "GetConfig",
|
||||||
|
Handler: _StreamD_GetConfig_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SetConfig",
|
||||||
|
Handler: _StreamD_SetConfig_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SaveConfig",
|
||||||
|
Handler: _StreamD_SaveConfig_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ResetCache",
|
||||||
|
Handler: _StreamD_ResetCache_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "InitCache",
|
||||||
|
Handler: _StreamD_InitCache_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "StartStream",
|
||||||
|
Handler: _StreamD_StartStream_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "EndStream",
|
||||||
|
Handler: _StreamD_EndStream_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetBackendInfo",
|
||||||
|
Handler: _StreamD_GetBackendInfo_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "Restart",
|
||||||
|
Handler: _StreamD_Restart_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "OBSOLETE_FetchConfig",
|
||||||
|
Handler: _StreamD_OBSOLETE_FetchConfig_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "OBSOLETE_GitInfo",
|
||||||
|
Handler: _StreamD_OBSOLETE_GitInfo_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "OBSOLETE_GitRelogin",
|
||||||
|
Handler: _StreamD_OBSOLETE_GitRelogin_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "streamd.proto",
|
||||||
|
}
|
63
pkg/streamd/grpc/streamd.proto
Normal file
63
pkg/streamd/grpc/streamd.proto
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
option go_package = "go/streamd_grpc";
|
||||||
|
|
||||||
|
service StreamD {
|
||||||
|
rpc GetConfig(GetConfigRequest) returns (GetConfigReply) {}
|
||||||
|
rpc SetConfig(SetConfigRequest) returns (SetConfigReply) {}
|
||||||
|
rpc SaveConfig(SaveConfigRequest) returns (SaveConfigReply) {}
|
||||||
|
rpc ResetCache(ResetCacheRequest) returns (ResetCacheReply) {}
|
||||||
|
rpc InitCache(InitCacheRequest) returns (InitCacheReply) {}
|
||||||
|
rpc StartStream(StartStreamRequest) returns (StartStreamReply) {}
|
||||||
|
rpc EndStream(EndStreamRequest) returns (EndStreamReply) {}
|
||||||
|
rpc GetBackendInfo(GetBackendInfoRequest) returns (GetBackendInfoReply) {}
|
||||||
|
rpc Restart(RestartRequest) returns (RestartReply) {}
|
||||||
|
|
||||||
|
rpc OBSOLETE_FetchConfig(OBSOLETE_FetchConfigRequest) returns (OBSOLETE_FetchConfigReply) {}
|
||||||
|
rpc OBSOLETE_GitInfo(OBSOLETE_GetGitInfoRequest) returns (OBSOLETE_GetGitInfoReply) {}
|
||||||
|
rpc OBSOLETE_GitRelogin(OBSOLETE_GitReloginRequest) returns (OBSOLETE_GitReloginReply) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetConfigRequest {}
|
||||||
|
message GetConfigReply {
|
||||||
|
string config = 1;
|
||||||
|
}
|
||||||
|
message SetConfigRequest {
|
||||||
|
string config = 1;
|
||||||
|
}
|
||||||
|
message SetConfigReply {}
|
||||||
|
message SaveConfigRequest {}
|
||||||
|
message SaveConfigReply {}
|
||||||
|
message ResetCacheRequest {}
|
||||||
|
message ResetCacheReply {}
|
||||||
|
message InitCacheRequest {}
|
||||||
|
message InitCacheReply {}
|
||||||
|
message StartStreamRequest {
|
||||||
|
string platID = 1;
|
||||||
|
string title = 2;
|
||||||
|
string description = 3;
|
||||||
|
string profile = 4;
|
||||||
|
}
|
||||||
|
message StartStreamReply {}
|
||||||
|
message EndStreamRequest {
|
||||||
|
string platID = 1;
|
||||||
|
}
|
||||||
|
message EndStreamReply {}
|
||||||
|
message GetBackendInfoRequest {
|
||||||
|
string platID = 1;
|
||||||
|
}
|
||||||
|
message GetBackendInfoReply {
|
||||||
|
bool isInitialized = 1;
|
||||||
|
string data = 2;
|
||||||
|
}
|
||||||
|
message RestartRequest {}
|
||||||
|
message RestartReply {}
|
||||||
|
|
||||||
|
message OBSOLETE_FetchConfigRequest {}
|
||||||
|
message OBSOLETE_FetchConfigReply {}
|
||||||
|
message OBSOLETE_GetGitInfoRequest {}
|
||||||
|
message OBSOLETE_GetGitInfoReply {
|
||||||
|
bool isInitialized = 1;
|
||||||
|
}
|
||||||
|
message OBSOLETE_GitReloginRequest {}
|
||||||
|
message OBSOLETE_GitReloginReply {}
|
||||||
|
|
213
pkg/streamd/server/grpc.go
Normal file
213
pkg/streamd/server/grpc.go
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol/obs"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol/twitch"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol/youtube"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamd/api"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamd/config"
|
||||||
|
"github.com/xaionaro-go/streamctl/pkg/streamd/grpc/go/streamd_grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GRPCServer struct {
|
||||||
|
streamd_grpc.StreamDServer
|
||||||
|
StreamD api.StreamD
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ streamd_grpc.StreamDServer = (*GRPCServer)(nil)
|
||||||
|
|
||||||
|
func NewGRPCServer(streamd api.StreamD) *GRPCServer {
|
||||||
|
return &GRPCServer{
|
||||||
|
StreamD: streamd,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) GetConfig(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.GetConfigRequest,
|
||||||
|
) (*streamd_grpc.GetConfigReply, error) {
|
||||||
|
config, err := grpc.StreamD.GetConfig(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get the config: %w", err)
|
||||||
|
}
|
||||||
|
b, err := json.Marshal(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to serialize the config: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.GetConfigReply{
|
||||||
|
Config: string(b),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) SetConfig(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.SetConfigRequest,
|
||||||
|
) (*streamd_grpc.SetConfigReply, error) {
|
||||||
|
var config config.Config
|
||||||
|
err := json.Unmarshal([]byte(req.Config), &config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to unserialize the config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = grpc.StreamD.SetConfig(ctx, &config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to set the config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &streamd_grpc.SetConfigReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) SaveConfig(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.SaveConfigRequest,
|
||||||
|
) (*streamd_grpc.SaveConfigReply, error) {
|
||||||
|
err := grpc.StreamD.SaveConfig(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to save the config: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.SaveConfigReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) ResetCache(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.ResetCacheRequest,
|
||||||
|
) (*streamd_grpc.ResetCacheReply, error) {
|
||||||
|
err := grpc.StreamD.ResetCache(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to reset the cache: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.ResetCacheReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) InitCache(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.InitCacheRequest,
|
||||||
|
) (*streamd_grpc.InitCacheReply, error) {
|
||||||
|
err := grpc.StreamD.InitCache(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to init the cache: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.InitCacheReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) StartStream(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.StartStreamRequest,
|
||||||
|
) (*streamd_grpc.StartStreamReply, error) {
|
||||||
|
var profile streamcontrol.AbstractStreamProfile
|
||||||
|
var err error
|
||||||
|
platID := streamcontrol.PlatformName(req.GetPlatID())
|
||||||
|
switch platID {
|
||||||
|
case obs.ID:
|
||||||
|
profile = &obs.StreamProfile{}
|
||||||
|
case twitch.ID:
|
||||||
|
profile = &twitch.StreamProfile{}
|
||||||
|
case youtube.ID:
|
||||||
|
profile = &youtube.StreamProfile{}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected platform ID: '%s'", platID)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal([]byte(req.GetProfile()), &profile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to unserialize the profile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = grpc.StreamD.StartStream(
|
||||||
|
ctx,
|
||||||
|
platID,
|
||||||
|
req.GetTitle(),
|
||||||
|
req.GetDescription(),
|
||||||
|
profile,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to start the stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &streamd_grpc.StartStreamReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) EndStream(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.EndStreamRequest,
|
||||||
|
) (*streamd_grpc.EndStreamReply, error) {
|
||||||
|
err := grpc.StreamD.EndStream(ctx, streamcontrol.PlatformName(req.GetPlatID()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to end the stream: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.EndStreamReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) GetBackendInfo(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.GetBackendInfoRequest,
|
||||||
|
) (*streamd_grpc.GetBackendInfoReply, error) {
|
||||||
|
platID := streamcontrol.PlatformName(req.GetPlatID())
|
||||||
|
isEnabled, err := grpc.StreamD.IsBackendEnabled(ctx, platID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to check if the backend is enabled: %w", err)
|
||||||
|
}
|
||||||
|
data, err := grpc.StreamD.GetBackendData(ctx, platID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get the backend info: %w", err)
|
||||||
|
}
|
||||||
|
dataSerialized, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to serialize the backend info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &streamd_grpc.GetBackendInfoReply{
|
||||||
|
IsInitialized: isEnabled,
|
||||||
|
Data: string(dataSerialized),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) Restart(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.RestartRequest,
|
||||||
|
) (*streamd_grpc.RestartReply, error) {
|
||||||
|
err := grpc.StreamD.Restart(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to restart: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.RestartReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) OBSOLETE_FetchConfig(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.OBSOLETE_FetchConfigRequest,
|
||||||
|
) (*streamd_grpc.OBSOLETE_FetchConfigReply, error) {
|
||||||
|
err := grpc.StreamD.FetchConfig(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to fetch the config: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.OBSOLETE_FetchConfigReply{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) OBSOLETE_GitInfo(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.OBSOLETE_GetGitInfoRequest,
|
||||||
|
) (*streamd_grpc.OBSOLETE_GetGitInfoReply, error) {
|
||||||
|
isEnabled, err := grpc.StreamD.IsGITInitialized(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get the git info: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.OBSOLETE_GetGitInfoReply{
|
||||||
|
IsInitialized: isEnabled,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (grpc *GRPCServer) OBSOLETE_GitRelogin(
|
||||||
|
ctx context.Context,
|
||||||
|
req *streamd_grpc.OBSOLETE_GitReloginRequest,
|
||||||
|
) (*streamd_grpc.OBSOLETE_GitReloginReply, error) {
|
||||||
|
err := grpc.StreamD.GitRelogin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to relogin: %w", err)
|
||||||
|
}
|
||||||
|
return &streamd_grpc.OBSOLETE_GitReloginReply{}, nil
|
||||||
|
}
|
@@ -401,3 +401,8 @@ func (d *StreamD) GetBackendData(ctx context.Context, platID streamcontrol.Platf
|
|||||||
return nil, fmt.Errorf("unexpected platform ID '%s'", platID)
|
return nil, fmt.Errorf("unexpected platform ID '%s'", platID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *StreamD) Restart(ctx context.Context) error {
|
||||||
|
d.UI.Restart(ctx, "A restart was requested")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user