events

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderAndSanitize

func RenderAndSanitize(raw string) string

RenderAndSanitize will turn markdown into HTML, sanitize raw user-supplied HTML and standardize the message into something safe and renderable for clients.

func RenderMarkdown

func RenderMarkdown(raw string) string

RenderMarkdown will return HTML rendered from the string body of a chat message.

Types

type ActionEvent

type ActionEvent struct {
	Event
	MessageEvent
}

ActionEvent represents an action that took place, not a chat message.

func (*ActionEvent) GetBroadcastPayload

func (e *ActionEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*ActionEvent) GetMessageType

func (e *ActionEvent) GetMessageType() EventType

GetMessageType will return the type of message.

type Event

type Event struct {
	Type      EventType `json:"type,omitempty"`
	ID        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
}

Event is any kind of event. A type is required to be specified.

func (*Event) SetDefaults

func (e *Event) SetDefaults()

SetDefaults will set default properties of all inbound events.

type EventPayload

type EventPayload map[string]interface{}

EventPayload is a generic key/value map for sending out to chat clients.

type EventType

type EventType = string

EventType is the type of a websocket event.

const (
	// MessageSent is the event sent when a chat event takes place.
	MessageSent EventType = "CHAT"
	// UserJoined is the event sent when a chat user join action takes place.
	UserJoined EventType = "USER_JOINED"
	// UserNameChanged is the event sent when a chat username change takes place.
	UserNameChanged EventType = "NAME_CHANGE"
	// VisibiltyToggled is the event sent when a chat message's visibility changes.
	VisibiltyToggled EventType = "VISIBILITY-UPDATE"
	// PING is a ping message.
	PING EventType = "PING"
	// PONG is a pong message.
	PONG EventType = "PONG"
	// StreamStarted represents a stream started event.
	StreamStarted EventType = "STREAM_STARTED"
	// StreamStopped represents a stream stopped event.
	StreamStopped EventType = "STREAM_STOPPED"
	// SystemMessageSent is the event sent when a system message is sent.
	SystemMessageSent EventType = "SYSTEM"
	// ChatDisabled is when a user is explicitly disabled and blocked from using chat.
	ChatDisabled EventType = "CHAT_DISABLED"
	// ConnectedUserInfo is a private event to a user letting them know their user details.
	ConnectedUserInfo EventType = "CONNECTED_USER_INFO"
	// ChatActionSent is a generic chat action that can be used for anything that doesn't need specific handling or formatting.
	ChatActionSent EventType = "CHAT_ACTION"
	// ErrorNeedsRegistration is an error returned when the client needs to perform registration.
	ErrorNeedsRegistration EventType = "ERROR_NEEDS_REGISTRATION"
	// ErrorMaxConnectionsExceeded is an error returned when the server determined it should not handle more connections.
	ErrorMaxConnectionsExceeded EventType = "ERROR_MAX_CONNECTIONS_EXCEEDED"
	// ErrorUserDisabled is an error returned when the connecting user has been previously banned/disabled.
	ErrorUserDisabled EventType = "ERROR_USER_DISABLED"
)

type MessageEvent

type MessageEvent struct {
	OutboundEvent `json:"-"`
	Body          string `json:"body"`
	RawBody       string `json:"-"`
}

MessageEvent is an event that has a message body.

func (*MessageEvent) Empty

func (m *MessageEvent) Empty() bool

Empty will return if this message's contents is empty.

func (*MessageEvent) RenderAndSanitizeMessageBody

func (m *MessageEvent) RenderAndSanitizeMessageBody()

RenderAndSanitizeMessageBody will turn markdown into HTML, sanitize raw user-supplied HTML and standardize the message into something safe and renderable for clients.

func (*MessageEvent) RenderBody

func (m *MessageEvent) RenderBody()

RenderBody will render markdown to html without any sanitization.

type NameChangeBroadcast

type NameChangeBroadcast struct {
	Event
	UserEvent
	Oldname string `json:"oldName"`
}

NameChangeBroadcast represents a user changing their chat display name.

func (*NameChangeBroadcast) GetBroadcastPayload

func (e *NameChangeBroadcast) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

type NameChangeEvent

type NameChangeEvent struct {
	Event
	UserEvent
	NewName string `json:"newName"`
}

NameChangeEvent is received when a user changes their chat display name.

type OutboundEvent

type OutboundEvent interface {
	GetBroadcastPayload() EventPayload
	GetMessageType() EventType
}

OutboundEvent represents an event that is sent out to all listeners of the chat server.

type SystemActionEvent

type SystemActionEvent struct {
	Event
	MessageEvent
}

SystemActionEvent is an event that represents an action that took place, not a chat message.

type SystemMessageEvent

type SystemMessageEvent struct {
	Event
	MessageEvent
}

SystemMessageEvent is a message displayed in chat on behalf of the server.

func (*SystemMessageEvent) GetBroadcastPayload

func (e *SystemMessageEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*SystemMessageEvent) GetMessageType

func (e *SystemMessageEvent) GetMessageType() EventType

GetMessageType will return the event type for this message.

type UserDisabledEvent

type UserDisabledEvent struct {
	Event
	UserEvent
}

UserDisabledEvent is the event fired when a user is banned/blocked and disconnected from chat.

func (*UserDisabledEvent) GetBroadcastPayload

func (e *UserDisabledEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

type UserEvent

type UserEvent struct {
	User     *user.User `json:"user"`
	ClientID uint       `json:"clientId"`
	HiddenAt *time.Time `json:"hiddenAt,omitempty"`
}

UserEvent is an event with an associated user.

type UserJoinedEvent

type UserJoinedEvent struct {
	Event
	UserEvent
}

UserJoinedEvent is the event fired when a user joins chat.

func (*UserJoinedEvent) GetBroadcastPayload

func (e *UserJoinedEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

type UserMessageEvent

type UserMessageEvent struct {
	Event
	UserEvent
	MessageEvent
}

UserMessageEvent is an inbound message from a user.

func (*UserMessageEvent) GetBroadcastPayload

func (e *UserMessageEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*UserMessageEvent) GetMessageType

func (e *UserMessageEvent) GetMessageType() EventType

GetMessageType will return the event type for this message.

func (*UserMessageEvent) SetDefaults

func (e *UserMessageEvent) SetDefaults()

SetDefaults will set default properties of all inbound events.

Jump to

Keyboard shortcuts

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