2023-01-11 06:38:48 +00:00
|
|
|
package barertc
|
|
|
|
|
2023-06-24 20:08:15 +00:00
|
|
|
// Auto incrementing Message ID for anything pushed out by the server.
|
|
|
|
var MessageID int
|
|
|
|
|
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"`
|
2023-01-27 04:34:58 +00:00
|
|
|
|
2023-02-06 01:42:09 +00:00
|
|
|
// JWT token for `login` actions.
|
|
|
|
JWTToken string `json:"jwt,omitempty"`
|
|
|
|
|
2023-01-27 04:34:58 +00:00
|
|
|
// WhoList for `who` actions
|
2023-01-27 06:54:02 +00:00
|
|
|
WhoList []WhoList `json:"whoList,omitempty"`
|
2023-01-27 04:34:58 +00:00
|
|
|
|
|
|
|
// Sent on `me` actions along with Username
|
2023-07-01 01:41:06 +00:00
|
|
|
VideoStatus int `json:"video,omitempty"` // user video flags
|
|
|
|
ChatStatus string `json:"status,omitempty"` // online vs. away
|
2023-01-27 06:54:02 +00:00
|
|
|
|
2023-06-24 20:08:15 +00:00
|
|
|
// Message ID to support takebacks/local deletions
|
|
|
|
MessageID int `json:"msgID,omitempty"`
|
|
|
|
|
2023-01-27 06:54:02 +00:00
|
|
|
// 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"`
|
|
|
|
|
2023-07-30 17:32:08 +00:00
|
|
|
// Send on `blocklist` actions, for doing a `mute` on a list of users
|
|
|
|
Usernames []string `json:"usernames,omitempty"`
|
|
|
|
|
2023-08-13 04:35:41 +00:00
|
|
|
// Sent on `report` actions.
|
|
|
|
Timestamp string `json:"timestamp,omitempty"`
|
|
|
|
Reason string `json:"reason,omitempty"`
|
|
|
|
Comment string `json:"comment,omitempty"`
|
|
|
|
|
2023-03-22 04:29:24 +00:00
|
|
|
// WebRTC negotiation messages: proxy their signaling messages
|
|
|
|
// between the two users to negotiate peer connection.
|
2023-02-25 01:42:38 +00:00
|
|
|
Candidate string `json:"candidate,omitempty"` // candidate
|
|
|
|
Description string `json:"description,omitempty"` // sdp
|
2023-01-11 06:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2023-01-27 04:34:58 +00:00
|
|
|
// Actions sent by the client side only
|
2023-07-30 17:32:08 +00:00
|
|
|
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"
|
|
|
|
ActionBlocklist = "blocklist" // mute in bulk for usernames
|
2023-08-13 04:35:41 +00:00
|
|
|
ActionReport = "report" // user reports a message
|
2023-01-27 04:34:58 +00:00
|
|
|
|
|
|
|
// Actions sent by server or client
|
2023-06-24 20:08:15 +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
|
|
|
|
ActionFile = "file" // image sharing in chat
|
|
|
|
ActionTakeback = "takeback" // user takes back (deletes) their message for everybody
|
2023-07-01 03:00:21 +00:00
|
|
|
ActionReact = "react" // emoji reaction to a chat message
|
2023-01-27 04:34:58 +00:00
|
|
|
|
|
|
|
// Actions sent by server only
|
2023-02-05 05:00:01 +00:00
|
|
|
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).
|
2023-01-27 06:54:02 +00:00
|
|
|
|
|
|
|
// WebRTC signaling messages.
|
|
|
|
ActionCandidate = "candidate"
|
|
|
|
ActionSDP = "sdp"
|
2023-01-11 06:38:48 +00:00
|
|
|
)
|
2023-01-27 04:34:58 +00:00
|
|
|
|
|
|
|
// WhoList is a member entry in the chat room.
|
|
|
|
type WhoList struct {
|
2023-07-01 01:41:06 +00:00
|
|
|
Username string `json:"username"`
|
|
|
|
Nickname string `json:"nickname,omitempty"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Video int `json:"video"`
|
2023-08-07 04:06:27 +00:00
|
|
|
LoginAt int64 `json:"loginAt"`
|
2023-02-06 01:42:09 +00:00
|
|
|
|
|
|
|
// 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"`
|
2023-08-06 02:38:04 +00:00
|
|
|
Emoji string `json:"emoji,omitempty"`
|
|
|
|
Gender string `json:"gender,omitempty"`
|
2023-01-27 04:34:58 +00:00
|
|
|
}
|
2023-07-01 01:41:06 +00:00
|
|
|
|
|
|
|
// VideoFlags to convey the state and setting of users' cameras concisely.
|
|
|
|
// Also see the VideoFlag object in BareRTC.js for front-end sync.
|
|
|
|
const (
|
|
|
|
VideoFlagActive int = 1 << iota // user's camera is enabled/broadcasting
|
|
|
|
VideoFlagNSFW // viewer's camera is marked as NSFW
|
|
|
|
VideoFlagMuted // user source microphone is muted
|
|
|
|
VideoFlagIsTalking // broadcaster seems to be talking
|
|
|
|
VideoFlagMutualRequired // video wants viewers to share their camera too
|
|
|
|
VideoFlagMutualOpen // viewer wants to auto-open viewers' cameras
|
|
|
|
)
|