BareRTC/pkg/messages.go

79 lines
2.8 KiB
Go
Raw Normal View History

2023-01-11 06:38:48 +00:00
package barertc
2023-03-22 04:29:24 +00:00
/*
Message is the basic carrier of WebSocket chat protocol actions.
Every message (client or server) has an Action and the rest of the
fields may vary depending on the action. Many messages target (or carry)
a Username, chat Channel and carry an arbitrary Message.
*/
2023-01-11 06:38:48 +00:00
type Message struct {
2023-02-11 06:46:39 +00:00
Action string `json:"action,omitempty"`
Channel string `json:"channel,omitempty"`
Username string `json:"username,omitempty"`
Message string `json:"message,omitempty"`
// JWT token for `login` actions.
JWTToken string `json:"jwt,omitempty"`
// WhoList for `who` actions
WhoList []WhoList `json:"whoList,omitempty"`
// Sent on `me` actions along with Username
2023-03-28 04:13:04 +00:00
VideoActive bool `json:"videoActive,omitempty"` // user tells us their cam status
ChatStatus string `json:"status,omitempty"` // online vs. away
NSFW bool `json:"nsfw,omitempty"` // user tags their video NSFW
// Sent on `open` actions along with the (other) Username.
OpenSecret string `json:"openSecret,omitempty"`
2023-03-22 04:29:24 +00:00
// Send on `file` actions, passing e.g. image data.
Bytes []byte `json:"bytes,omitempty"`
// WebRTC negotiation messages: proxy their signaling messages
// between the two users to negotiate peer connection.
Candidate string `json:"candidate,omitempty"` // candidate
Description string `json:"description,omitempty"` // sdp
2023-01-11 06:38:48 +00:00
}
const (
// Actions sent by the client side only
ActionLogin = "login" // post the username to backend
ActionBoot = "boot" // boot a user off your video feed
ActionMute = "mute" // mute a user's chat messages
ActionUnmute = "unmute"
// Actions sent by server or client
2023-01-11 06:38:48 +00:00
ActionMessage = "message" // post a message to the room
ActionMe = "me" // user self-info sent by FE or BE
ActionOpen = "open" // user wants to view a webcam (open WebRTC)
ActionRing = "ring" // receiver of a WebRTC open request
ActionWatch = "watch" // user has received video and is watching you
ActionUnwatch = "unwatch" // user has closed your video
2023-03-22 04:29:24 +00:00
ActionFile = "file" // image sharing in chat
// Actions sent by server only
ActionPing = "ping"
2023-02-11 06:46:39 +00:00
ActionWhoList = "who" // server pushes the Who List
ActionPresence = "presence" // a user joined or left the room
ActionError = "error" // ChatServer errors
ActionKick = "disconnect" // client should disconnect (e.g. have been kicked).
// WebRTC signaling messages.
ActionCandidate = "candidate"
ActionSDP = "sdp"
2023-01-11 06:38:48 +00:00
)
// WhoList is a member entry in the chat room.
type WhoList struct {
Username string `json:"username"`
2023-02-11 06:46:39 +00:00
VideoActive bool `json:"videoActive,omitempty"`
NSFW bool `json:"nsfw,omitempty"`
2023-03-28 04:13:04 +00:00
Status string `json:"status"`
// JWT auth extra settings.
Operator bool `json:"op"`
2023-02-11 06:46:39 +00:00
Avatar string `json:"avatar,omitempty"`
ProfileURL string `json:"profileURL,omitempty"`
}