Documentation ¶
Overview ¶
Defines interfaces for creating communciation channels between server and clients
Index ¶
- Constants
- func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I
- type Bus
- type Channel
- type CleanableUpdateItem
- type ModelUpdate
- type ModelUpdateChannel
- type ModelUpdateItem
- type ModelUpdatePacketType
- type PtyDataUpdate
- type PtyDataUpdatePacketType
- type RpcBus
- type RpcChannel
- type RpcPacket
- type RpcResponse
- type UpdateBus
- type UpdateChannel
- type UpdatePacket
Constants ¶
const ChSize = 100
The default channel size
const ModelUpdateStr = "model"
const PtyDataUpdateStr = "pty"
Variables ¶
This section is empty.
Functions ¶
func GetUpdateItems ¶
func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I
Returns the items in the update that are of type I
Types ¶
type Bus ¶
A concurrent bus for registering and managing channels
func (*Bus[I]) RegisterChannel ¶
Opens new channel and registers it with the bus. If a channel exists, it is closed and replaced.
func (*Bus[I]) UnregisterChannel ¶
Closes the channel matching the provided key and removes it from the bus
type Channel ¶
type Channel[I packet.PacketType] interface { GetChannel() chan I SetChannel(chan I) Match(string) bool }
type CleanableUpdateItem ¶
type CleanableUpdateItem interface {
Clean()
}
An interface for model updates that can be cleaned
type ModelUpdate ¶
type ModelUpdate []ModelUpdateItem
An inner data type for the ModelUpdatePacketType. Stores a collection of model updates to be sent to the client.
func (*ModelUpdate) IsEmpty ¶
func (mu *ModelUpdate) IsEmpty() bool
func (*ModelUpdate) MarshalJSON ¶
func (mu *ModelUpdate) MarshalJSON() ([]byte, error)
type ModelUpdateChannel ¶
type ModelUpdateChannel[J any] struct { ScreenId string ClientId string // contains filtered or unexported fields }
A channel for sending model updates to the client
func (*ModelUpdateChannel[J]) GetChannel ¶
func (uch *ModelUpdateChannel[J]) GetChannel() chan J
func (*ModelUpdateChannel[J]) Match ¶
func (sch *ModelUpdateChannel[J]) Match(screenId string) bool
Match the screenId to the channel
func (*ModelUpdateChannel[J]) SetChannel ¶
func (uch *ModelUpdateChannel[J]) SetChannel(ch chan J)
type ModelUpdateItem ¶
type ModelUpdateItem interface { // The key to use when marshalling to JSON and interpreting in the client GetType() string }
An interface for all model updates
type ModelUpdatePacketType ¶
type ModelUpdatePacketType struct { Type string `json:"type"` Data *ModelUpdate `json:"data"` }
An UpdatePacket for sending model updates to the client
func MakeUpdatePacket ¶
func MakeUpdatePacket() *ModelUpdatePacketType
Create a new model update packet
func (*ModelUpdatePacketType) AddUpdate ¶
func (upk *ModelUpdatePacketType) AddUpdate(items ...ModelUpdateItem)
Add a collection of model updates to the update
func (*ModelUpdatePacketType) Clean ¶
func (upk *ModelUpdatePacketType) Clean()
Clean the ClientData in an update, if present
func (*ModelUpdatePacketType) GetType ¶
func (*ModelUpdatePacketType) GetType() string
func (*ModelUpdatePacketType) IsEmpty ¶
func (upk *ModelUpdatePacketType) IsEmpty() bool
func (*ModelUpdatePacketType) Merge ¶
func (upk *ModelUpdatePacketType) Merge(p2Arg UpdatePacket) error
adds the items from p2 to the update (p2 must be ModelUpdatePacketType)
type PtyDataUpdate ¶
type PtyDataUpdate struct { ScreenId string `json:"screenid,omitempty"` LineId string `json:"lineid,omitempty"` RemoteId string `json:"remoteid,omitempty"` PtyPos int64 `json:"ptypos"` PtyData64 string `json:"ptydata64"` PtyDataLen int64 `json:"ptydatalen"` }
The inner data type for the PtyDataUpdatePacketType. Stores the pty data to be sent to the client.
type PtyDataUpdatePacketType ¶
type PtyDataUpdatePacketType struct { Type string `json:"type"` Data *PtyDataUpdate `json:"data"` }
An UpdatePacket for sending pty data to the client
func MakePtyDataUpdate ¶
func MakePtyDataUpdate(update *PtyDataUpdate) *PtyDataUpdatePacketType
Create a new PtyDataUpdatePacketType
func (*PtyDataUpdatePacketType) Clean ¶
func (pdu *PtyDataUpdatePacketType) Clean()
func (*PtyDataUpdatePacketType) GetType ¶
func (*PtyDataUpdatePacketType) GetType() string
func (*PtyDataUpdatePacketType) IsEmpty ¶
func (pdu *PtyDataUpdatePacketType) IsEmpty() bool
type RpcBus ¶
type RpcBus struct { Bus[RpcResponse] }
A collection of channels that can receive rpc responses
var MainRpcBus *RpcBus = MakeRpcBus()
func (*RpcBus) GetRpcChannel ¶
func (bus *RpcBus) GetRpcChannel(id string) (chan RpcResponse, bool)
Get the user input channel for the given request id
type RpcChannel ¶
type RpcChannel struct {
// contains filtered or unexported fields
}
Implements the Channel interface to allow receiving rpc responses
func (*RpcChannel) GetChannel ¶
func (ch *RpcChannel) GetChannel() chan RpcResponse
func (*RpcChannel) Match ¶
func (ch *RpcChannel) Match(string) bool
This is a no-op, only used to satisfy the Channel interface
func (*RpcChannel) SetChannel ¶
func (ch *RpcChannel) SetChannel(newCh chan RpcResponse)
type RpcPacket ¶
An interface for rpc requests This is separate from the RpcPacketType defined in the waveshell/pkg/packet package, as that one is intended for use communicating between wavesrv and waveshell. It is has a different set of required methods.
type RpcResponse ¶
An interface for rpc responses This is separate from the RpcResponsePacketType defined in the waveshell/pkg/packet package, as that one is intended for use communicating between wavesrv and waveshell. It is has a different set of required methods.
type UpdateBus ¶
type UpdateBus struct { Bus[UpdatePacket] }
A collection of channels that can transmit updates
var MainUpdateBus *UpdateBus = MakeUpdateBus()
func (*UpdateBus) DoScreenUpdate ¶
func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket)
Send a model update to only clients that are subscribed to the given screenId
func (*UpdateBus) DoUpdate ¶
func (bus *UpdateBus) DoUpdate(update UpdatePacket)
Send an update to all channels in the collection
type UpdateChannel ¶
type UpdateChannel struct { ScreenId string // contains filtered or unexported fields }
A channel for sending model updates to the client
func (*UpdateChannel) GetChannel ¶
func (uch *UpdateChannel) GetChannel() chan UpdatePacket
func (*UpdateChannel) Match ¶
func (sch *UpdateChannel) Match(screenId string) bool
Match the screenId to the channel
func (*UpdateChannel) SetChannel ¶
func (uch *UpdateChannel) SetChannel(ch chan UpdatePacket)
type UpdatePacket ¶
type UpdatePacket interface { // The key to use when marshalling to JSON and interpreting in the client GetType() string Clean() IsEmpty() bool }
An interface for updates to be sent over an UpdateChannel