plugins

package
v0.0.0-...-fcbdc9d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Handshake = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "LIGHTSPEED_CHAT_PLUGIN",
	MagicCookieValue: "388d8ee683cf839480ca5ba518a867b4924d1738d57ac88f4d90ba0730aaed86",
}

Handshake is a common handshake that is shared by plugin and host.

View Source
var PluginMap = map[string]plugin.Plugin{
	"eventhandler": &EventHandlerPlugin{},
}

PluginMap is the map of plugins we can dispense.

Functions

This section is empty.

Types

type EmitEventsHelper

type EmitEventsHelper interface {
	EmitEvents([]*types.Event) error
	AuthenticateUser(string, string) (*types.User, error)
	GetUser(string) (*types.User, error)
	GetRoom(string) (*types.Room, error)
	ChangeUserTags(string, []*types.TagUpdate) (*types.User, []bool, error)
	ChangeRoomTags(string, []*types.TagUpdate) (*types.Room, []bool, error)
}

type EventHandler

type EventHandler interface {
	// Configure returns the cron spec and the events filter
	Configure(map[string]interface{}) (cronSpec string, eventsFilter string, err error)

	// Cron is invoked from the main process according to the cronSpec as returned by Configure.
	// Cron returns []types.Event to be emitted
	Cron(*types.Room) ([]*types.Event, error)

	// HandleEvents is invoked every time a new event occurs, currently defined events are
	// new chat message, new translation, new command, new user login
	// the plugin only receives events that pass the eventsFilter returned by Configure
	HandleEvents([]*types.Event) ([]*types.Event, error)

	// InitEmitEvents never exits, it creates a permanent connection between the main program an the plugin
	// allowing the plugin to emit events at will
	InitEmitEvents(room *types.Room, eh EmitEventsHelper) error
}

KV is the interface that we're exposing as a plugin.

type EventHandlerPlugin

type EventHandlerPlugin struct {
	plugin.NetRPCUnsupportedPlugin

	// Concrete implementation, written in Go. This is only used for plugins
	// that are written in Go.
	Impl EventHandler
}

This is the implementation of plugin.Plugin so we can serve/consume this. We also implement GRPCPlugin so that this plugin can be served over gRPC.

func (*EventHandlerPlugin) GRPCClient

func (p *EventHandlerPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

func (*EventHandlerPlugin) GRPCServer

func (p *EventHandlerPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

type GRPCClient

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient is the client part of the plugin implementation via GRPC

func (*GRPCClient) Configure

func (c *GRPCClient) Configure(val map[string]interface{}) (string, string, error)

func (*GRPCClient) Cron

func (c *GRPCClient) Cron(room *types.Room) ([]*types.Event, error)

func (*GRPCClient) HandleEvents

func (c *GRPCClient) HandleEvents(inEvents []*types.Event) ([]*types.Event, error)

func (*GRPCClient) InitEmitEvents

func (c *GRPCClient) InitEmitEvents(room *types.Room, eh EmitEventsHelper) error

InitEmitEvents is called once per hub from the main process and it opens a permanent data stream from the plugin to the main process (via GRPC/ EmitEventsHelper). It must be called from a go routine as it never returns.

type GRPCEmitEventsHelperClient

type GRPCEmitEventsHelperClient struct {
	// contains filtered or unexported fields
}

func (*GRPCEmitEventsHelperClient) AuthenticateUser

func (c *GRPCEmitEventsHelperClient) AuthenticateUser(idToken, provider string) (*types.User, error)

func (*GRPCEmitEventsHelperClient) ChangeRoomTags

func (c *GRPCEmitEventsHelperClient) ChangeRoomTags(roomId string, updates []*types.TagUpdate) (*types.Room, []bool, error)

func (*GRPCEmitEventsHelperClient) ChangeUserTags

func (c *GRPCEmitEventsHelperClient) ChangeUserTags(userId string, updates []*types.TagUpdate) (*types.User, []bool, error)

func (*GRPCEmitEventsHelperClient) EmitEvents

func (c *GRPCEmitEventsHelperClient) EmitEvents(events []*types.Event) error

func (*GRPCEmitEventsHelperClient) GetRoom

func (c *GRPCEmitEventsHelperClient) GetRoom(roomId string) (*types.Room, error)

func (*GRPCEmitEventsHelperClient) GetUser

func (c *GRPCEmitEventsHelperClient) GetUser(userId string) (*types.User, error)

type GRPCEmitEventsHelperServer

type GRPCEmitEventsHelperServer struct {
	proto.UnimplementedEmitEventsHelperServer

	// This is the real implementation
	Impl EmitEventsHelper
}

func (*GRPCEmitEventsHelperServer) AuthenticateUser

func (*GRPCEmitEventsHelperServer) ChangeRoomTags

func (*GRPCEmitEventsHelperServer) ChangeUserTags

func (*GRPCEmitEventsHelperServer) EmitEvents

func (*GRPCEmitEventsHelperServer) GetRoom

func (*GRPCEmitEventsHelperServer) GetUser

type GRPCServer

type GRPCServer struct {
	proto.UnimplementedEventHandlerServer

	// This is the real implementation
	Impl EventHandler
	// contains filtered or unexported fields
}

Here is the gRPC server that GRPCClient talks to.

func (*GRPCServer) Configure

func (*GRPCServer) Cron

func (*GRPCServer) HandleEvents

func (*GRPCServer) InitEmitEvents

type HelperFunctionsType

type HelperFunctionsType struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*HelperFunctionsType) AuthenticateUser

func (h *HelperFunctionsType) AuthenticateUser(token string, provider string) (*types.User, error)

func (*HelperFunctionsType) ChangeRoomTags

func (h *HelperFunctionsType) ChangeRoomTags(roomId string, updates []*types.TagUpdate) (*types.Room, []bool, error)

func (*HelperFunctionsType) ChangeUserTags

func (h *HelperFunctionsType) ChangeUserTags(userId string, updates []*types.TagUpdate) (*types.User, []bool, error)

func (*HelperFunctionsType) Clear

func (h *HelperFunctionsType) Clear()

func (*HelperFunctionsType) EmitEvents

func (h *HelperFunctionsType) EmitEvents(events []*types.Event) error

func (*HelperFunctionsType) GetRoom

func (h *HelperFunctionsType) GetRoom(roomId string) (*types.Room, error)

func (*HelperFunctionsType) GetUser

func (h *HelperFunctionsType) GetUser(userId string) (*types.User, error)

func (*HelperFunctionsType) Set

type PluginSpec

type PluginSpec struct {
	Name        string
	Plugin      EventHandler
	CronSpec    string
	EventFilter string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL