waveterm/pkg/wps/wpstypes.go
Evan Simkowitz 936d4bfb30
Migrate websocket eventbus messages to wps (#367)
This migrates all remaining eventbus events sent over the websocket to
use the wps interface. WPS is more flexible for registering events and
callbacks and provides support for more reliable unsubscribes and
resubscribes.
2024-09-11 18:03:55 -07:00

46 lines
1.1 KiB
Go

package wps
import "github.com/wavetermdev/waveterm/pkg/util/utilfn"
const (
Event_BlockClose = "blockclose"
Event_ConnChange = "connchange"
Event_SysInfo = "sysinfo"
Event_ControllerStatus = "controllerstatus"
Event_WaveObjUpdate = "waveobj:update"
Event_BlockFile = "blockfile"
Event_Config = "config"
Event_UserInput = "userinput"
)
type WaveEvent struct {
Event string `json:"event"`
Scopes []string `json:"scopes,omitempty"`
Sender string `json:"sender,omitempty"`
Persist int `json:"persist,omitempty"`
Data any `json:"data,omitempty"`
}
func (e WaveEvent) HasScope(scope string) bool {
return utilfn.ContainsStr(e.Scopes, scope)
}
type SubscriptionRequest struct {
Event string `json:"event"`
Scopes []string `json:"scopes,omitempty"`
AllScopes bool `json:"allscopes,omitempty"`
}
const (
FileOp_Append = "append"
FileOp_Truncate = "truncate"
FileOp_Invalidate = "invalidate"
)
type WSFileEventData struct {
ZoneId string `json:"zoneid"`
FileName string `json:"filename"`
FileOp string `json:"fileop"`
Data64 string `json:"data64"`
}