canape/backend/events/events.go
Lucas BEE 07823efd74 Fix deadlock in channels
We now close the Channels when its connection is closed so that we never
try to send events into a dead channel
Add a debug handler showing who is subscribed to what
2019-07-17 12:56:31 +00:00

60 lines
1.2 KiB
Go

package events
// ErrorLevel is the level of the ServerError
type ErrorLevel string
// Status is the status of an event
type Status string
// Different ErrorLevels and statuses
const (
// ErrorLevel
WarningError ErrorLevel = "warning"
FatalError ErrorLevel = "fatal"
// Statuses
OK Status = "ok"
Disconnected Status = "disconnected"
Error Status = "error"
)
// Event is the base of a message
type Event struct {
Type string `json:"type"`
Status Status `json:"status"`
}
// ClientMessage represents a message sent by the client
type ClientMessage struct {
Event
Message string `json:"message"`
}
// ServerEvent represents an event sent to the client
type ServerEvent struct {
Event
Data interface{} `json:"message"`
}
// ErrorEvent represents an event error
type ErrorEvent struct {
Level ErrorLevel `json:"level"`
Message string `json:"message"`
}
// ServerError represents an error sent to the client
type ServerError struct {
Event
ErrorEvent `json:"error"`
}
// Eventer define an interface that any eventer must follow
type Eventer interface {
Unsubscribe(chanl *Channel) error
Append(chanl *Channel)
Subscribers() []*Channel
NotifyAll(data interface{})
Launch() error
Finish()
FatalError(error)
}