websocket

package
v0.0.0-...-9e48597 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CLIENT_TYPE_TEXT   = 1
	CLIENT_TYPE_BINARY = 2
)
View Source
const (
	CLIENT_STATUS_ACTIVE = 1
	CLIENT_STATUS_DEAD   = 2
)
View Source
const BINARY_MESSAGE_TYPE_MOVING = 1
View Source
const BROADCAST_TYPE_ATTACH_COMPONENT = "attachComponent"
View Source
const BROADCAST_TYPE_ENTER = "enter"
View Source
const BROADCAST_TYPE_SUFFIX = "/remote"

for broadcast rewrite

View Source
const DASHBOARD_APP_ID = -1
View Source
const DEFAULT_APP_ID = 0
View Source
const DEFAULT_INSTANCE_ID = "SELF_HOST"
View Source
const DEFAULT_ROOM_SLOT = 0
View Source
const ERROR_AI_AGENT_MAX_TOKEN_OVER_COLLA_BALANCE = 18
View Source
const ERROR_CAN_NOT_MOVE_KVSTATE = 10
View Source
const ERROR_CAN_NOT_MOVE_SETSTATE = 11
View Source
const ERROR_CODE_BROADCAST = 0
View Source
const ERROR_CODE_FAILED = 1
View Source
const ERROR_CODE_LOGGEDIN = 0
View Source
const ERROR_CODE_LOGIN_FAILED = 4
View Source
const ERROR_CODE_NEED_ENTER = 2
View Source
const ERROR_CODE_OK = 0

for feedback

View Source
const ERROR_CODE_PONG = 3
View Source
const ERROR_CONTEXT_LENGTH_EXCEEDED = 16
View Source
const ERROR_CREATE_OR_UPDATE_STATE_FAILED = 9
View Source
const ERROR_CREATE_OR_UPDATE_STATE_OK = 0
View Source
const ERROR_CREATE_SNAPSHOT_MIDIFY_HISTORY_FAILED = 12
View Source
const ERROR_CREATE_STATE_FAILED = 5
View Source
const ERROR_CREATE_STATE_OK = 0
View Source
const ERROR_DELETE_STATE_FAILED = 6
View Source
const ERROR_DELETE_STATE_OK = 0
View Source
const ERROR_FLAG_ONLY_PAID_TEAM_CAN_RUN_SPECIAL_AI_AGENT_MODEL = 19
View Source
const ERROR_FORCE_REFRESH_WINDOW = 14
View Source
const ERROR_INSUFFICIENT_COLLA = 17
View Source
const ERROR_MESSAGE_END = 15
View Source
const ERROR_MOVE_STATE_FAILED = 8
View Source
const ERROR_MOVE_STATE_OK = 0
View Source
const ERROR_PUT_STATE_FAILED = 20
View Source
const ERROR_UPDATE_SNAPSHOT_MIDIFY_HISTORY_FAILED = 13
View Source
const ERROR_UPDATE_STATE_FAILED = 7
View Source
const ERROR_UPDATE_STATE_OK = 0
View Source
const HTTP_SERVER_CLIENT_ID = "a97bce38-703b-4f03-b59b-111a00000001"
View Source
const OPTION_BROADCAST_ROOM = 1 // 00000000000000000000000000000001; // use as signed int32 in typescript

Variables

View Source
var (
	Signal_name = map[int32]string{
		0:  "SIGNAL_PING",
		1:  "SIGNAL_ENTER",
		2:  "SIGNAL_LEAVE",
		3:  "SIGNAL_CREATE_STATE",
		4:  "SIGNAL_DELETE_STATE",
		5:  "SIGNAL_UPDATE_STATE",
		6:  "SIGNAL_MOVE_STATE",
		7:  "SIGNAL_CREATE_OR_UPDATE_STATE",
		8:  "SIGNAL_BROADCAST_ONLY",
		9:  "SIGNAL_PUT_STATE",
		10: "SIGNAL_GLOBAL_BROADCAST_ONLY",
		11: "SIGNAL_COOPERATE_ATTACH",
		12: "SIGNAL_COOPERATE_DISATTACH",
		13: "SIGNAL_MOVE_CURSOR",
	}
	Signal_value = map[string]int32{
		"SIGNAL_PING":                   0,
		"SIGNAL_ENTER":                  1,
		"SIGNAL_LEAVE":                  2,
		"SIGNAL_CREATE_STATE":           3,
		"SIGNAL_DELETE_STATE":           4,
		"SIGNAL_UPDATE_STATE":           5,
		"SIGNAL_MOVE_STATE":             6,
		"SIGNAL_CREATE_OR_UPDATE_STATE": 7,
		"SIGNAL_BROADCAST_ONLY":         8,
		"SIGNAL_PUT_STATE":              9,
		"SIGNAL_GLOBAL_BROADCAST_ONLY":  10,
		"SIGNAL_COOPERATE_ATTACH":       11,
		"SIGNAL_COOPERATE_DISATTACH":    12,
		"SIGNAL_MOVE_CURSOR":            13,
	}
)

Enum value maps for Signal.

View Source
var (
	Target_name = map[int32]string{
		0: "TARGET_NOTHING",
		1: "TARGET_COMPONENTS",
		2: "TARGET_DEPENDENCIES",
		3: "TARGET_DRAG_SHADOW",
		4: "TARGET_DOTTED_LINE_SQUARE",
		5: "TARGET_DISPLAY_NAME",
		6: "TARGET_APPS",
		7: "TARGET_RESOURCE",
		8: "TARGET_ACTION",
		9: "TARGET_CURSOR",
	}
	Target_value = map[string]int32{
		"TARGET_NOTHING":            0,
		"TARGET_COMPONENTS":         1,
		"TARGET_DEPENDENCIES":       2,
		"TARGET_DRAG_SHADOW":        3,
		"TARGET_DOTTED_LINE_SQUARE": 4,
		"TARGET_DISPLAY_NAME":       5,
		"TARGET_APPS":               6,
		"TARGET_RESOURCE":           7,
		"TARGET_ACTION":             8,
		"TARGET_CURSOR":             9,
	}
)

Enum value maps for Target.

View Source
var File_cursor_sync_proto protoreflect.FileDescriptor

Functions

func GetBinaryMessageType

func GetBinaryMessageType(message []byte) (int, error)

func GetMessageClientIDForWebsocketServer

func GetMessageClientIDForWebsocketServer() uuid.UUID

Types

type Broadcast

type Broadcast struct {
	Type    string      `json:"type"`
	Payload interface{} `json:"payload"`
}

type Client

type Client struct {
	ID uuid.UUID

	Status int

	Type int

	MappedUserID int

	MappedUserUID uuid.UUID

	IsLoggedIn bool

	Hub *Hub

	// The websocket connection.
	Conn *websocket.Conn

	// Buffered channel of outbound messages.
	Send chan []byte

	// teamID, 0 by default in SELF_HOST mode
	TeamID int // TeamID

	// appID, 0 by default, -1 for dashboard
	APPID int
}

Client is a middleman between the websocket connection and the hub.

func NewClient

func NewClient(hub *Hub, conn *websocket.Conn, teamID int, appID int, clientType int) *Client

func (*Client) ExportMappedUserIDToString

func (c *Client) ExportMappedUserIDToString() string

func (*Client) Feedback

func (c *Client) Feedback(message *Message, errorCode int, errorMessage error)

func (*Client) FeedbackBinary

func (c *Client) FeedbackBinary(message []byte)

func (*Client) GetAPPID

func (c *Client) GetAPPID() int

func (*Client) GetID

func (c *Client) GetID() uuid.UUID

func (*Client) IsDead

func (c *Client) IsDead() bool

func (*Client) OnBinaryMessage

func (c *Client) OnBinaryMessage(message []byte)

func (*Client) OnTextMessage

func (c *Client) OnTextMessage(message []byte)

func (*Client) ReadPump

func (c *Client) ReadPump()

readPump pumps messages from the websocket connection to the hub.

The application runs readPump in a per-connection goroutine. The application ensures that there is at most one reader on a connection by executing all reads from this goroutine.

func (*Client) SetStatus

func (c *Client) SetStatus(status int)

func (*Client) SetType

func (c *Client) SetType(clientType int)

func (*Client) WritePump

func (c *Client) WritePump()

writePump pumps messages from the hub to the websocket connection.

A goroutine running writePump is started for each connection. The application ensures that there is at most one writer to a connection by executing all writes from this goroutine.

All message types (TextMessage, BinaryMessage, CloseMessage, PingMessage and PongMessage) are supported.

type ComponentAttachedUsers

type ComponentAttachedUsers struct {
	ComponentAttachedUsers map[string][]*UserForCooperateFeedback `json:"componentAttachedUsers"`
}

type Feedback

type Feedback struct {
	ErrorCode    int         `json:"errorCode"`
	ErrorMessage string      `json:"errorMessage"`
	Broadcast    *Broadcast  `json:"broadcast"`
	Data         interface{} `json:"data"`
}

func (*Feedback) Serialization

func (feed *Feedback) Serialization() ([]byte, error)

type Hub

type Hub struct {
	// registered clients map
	Clients       map[uuid.UUID]*Client
	BinaryClients map[uuid.UUID]*Client

	// inbound messages from the clients.
	// try “`hub.Broadcast <- []byte(message)“`
	Broadcast chan []byte

	// on message process
	OnTextMessage chan *Message

	OnBinaryMessage chan []byte

	// register requests from the clients.
	Register       chan *Client
	RegisterBinary chan *Client

	// unregister requests from the clients.
	Unregister chan *Client

	// InRoomUsers
	InRoomUsersMap map[int]*InRoomUsers // map[roomID]*InRoomUsers

	// sotrage
	Storage *storage.Storage

	// attribute group
	AttributeGroup *accesscontrol.AttributeGroup
}

clients hub, maintains active clients and broadcast messags.

func NewHub

func NewHub(s *storage.Storage, attrg *accesscontrol.AttributeGroup) *Hub

func (*Hub) BroadcastBinaryToOtherClients

func (hub *Hub) BroadcastBinaryToOtherClients(message []byte, currentClient *Client)

func (*Hub) BroadcastToGlobal

func (hub *Hub) BroadcastToGlobal(message *Message, currentClient *Client, includeCurrentClient bool)

WARRING: This method will broadcast to server all clients. Use it carefully.

func (*Hub) BroadcastToOtherClients

func (hub *Hub) BroadcastToOtherClients(message *Message, currentClient *Client)

func (*Hub) BroadcastToRoomAllClients

func (hub *Hub) BroadcastToRoomAllClients(message *Message, currentClient *Client)

func (*Hub) BroadcastToTeamAllClients

func (hub *Hub) BroadcastToTeamAllClients(message *Message, currentClient *Client, includeCurrentClient bool)

func (*Hub) CleanRoom

func (hub *Hub) CleanRoom(roomID int)

func (*Hub) GetClientByID

func (hub *Hub) GetClientByID(clientID uuid.UUID) (*Client, error)

func (*Hub) GetInRoomUsersByRoomID

func (hub *Hub) GetInRoomUsersByRoomID(roomID int) *InRoomUsers

func (*Hub) KickClient

func (hub *Hub) KickClient(client *Client)

func (*Hub) RemoveClient

func (hub *Hub) RemoveClient(client *Client)

func (*Hub) SendFeedbackToTargetRoomAllClients

func (hub *Hub) SendFeedbackToTargetRoomAllClients(errorCode int, message *Message, teamID int, appID int)

type InRoomUsers

type InRoomUsers struct {
	RoomID           int
	All              []*UserForCooperateFeedback            // []*UserForCooperateFeedback
	AllUsers         map[string]*UserForCooperateFeedback   // map[user.ID]*UserForCooperateFeedback
	AttachedUserList map[string][]*UserForCooperateFeedback // map[component.DisplayName][]*UserForCooperateFeedback
}

func NewInRoomUsers

func NewInRoomUsers(roomID int) *InRoomUsers

func (*InRoomUsers) AttachComponent

func (iru *InRoomUsers) AttachComponent(userID string, componentDisplayNames []string)

func (*InRoomUsers) Count

func (iru *InRoomUsers) Count() int

func (*InRoomUsers) DisattachComponent

func (iru *InRoomUsers) DisattachComponent(userID string, componentDisplayNames []string)

func (*InRoomUsers) EnterRoom

func (iru *InRoomUsers) EnterRoom(user *model.User)

func (*InRoomUsers) FetchAllAttachedUsers

func (iru *InRoomUsers) FetchAllAttachedUsers() *ComponentAttachedUsers

func (*InRoomUsers) FetchAllInRoomUsers

func (iru *InRoomUsers) FetchAllInRoomUsers() *InRoomUsersFeedback

func (*InRoomUsers) LeaveRoom

func (iru *InRoomUsers) LeaveRoom(userID string)

type InRoomUsersFeedback

type InRoomUsersFeedback struct {
	InRoomUsers []*UserForCooperateFeedback `json:"inRoomUsers"`
}

type Message

type Message struct {
	ClientID      uuid.UUID     `json:"clientID"`
	Signal        int           `json:"signal"`
	APPID         int           `json:"appID"` // also as APP ID
	Option        int           `json:"option"`
	Payload       []interface{} `json:"payload"`
	Target        int           `json:"target"`
	Broadcast     *Broadcast    `json:"broadcast"`
	NeedBroadcast bool
}

func NewEmptyMessage

func NewEmptyMessage(appID int, clientID uuid.UUID, signal int, target int, needBroadcast bool) (*Message, error)

func NewMessage

func NewMessage(clientID uuid.UUID, appID int, rawMessage []byte) (*Message, error)

func (*Message) RewriteBroadcast

func (m *Message) RewriteBroadcast()

func (*Message) SetBroadcastPayload

func (m *Message) SetBroadcastPayload(any interface{})

func (*Message) SetBroadcastType

func (m *Message) SetBroadcastType(t string)

func (*Message) SetSignal

func (m *Message) SetSignal(s int)

type MovingMessageBin

type MovingMessageBin struct {
	Signal            Signal  `protobuf:"varint,1,opt,name=signal,proto3,enum=tutorial.Signal" json:"signal,omitempty"` // see package websocket const define
	Target            Target  `protobuf:"varint,2,opt,name=target,proto3,enum=tutorial.Target" json:"target,omitempty"` //
	ClientID          string  `protobuf:"bytes,3,opt,name=clientID,proto3" json:"clientID,omitempty"`                   // message sender client ID
	NeedBroadcast     bool    `protobuf:"varint,4,opt,name=needBroadcast,proto3" json:"needBroadcast,omitempty"`
	UserID            string  `protobuf:"bytes,5,opt,name=userID,proto3" json:"userID,omitempty"`                       // message sender user ID
	Nickname          string  `protobuf:"bytes,6,opt,name=nickname,proto3" json:"nickname,omitempty"`                   // message sender user ID
	Status            int32   `protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"`                      // set instance to status, 0 for empty status
	ParentDisplayName string  `protobuf:"bytes,8,opt,name=parentDisplayName,proto3" json:"parentDisplayName,omitempty"` // parent component displayname
	DisplayNames      string  `protobuf:"bytes,9,opt,name=displayNames,proto3" json:"displayNames,omitempty"`           // message affected component display names, separate with comma ","
	CursorXInteger    uint32  `protobuf:"varint,10,opt,name=cursorXInteger,proto3" json:"cursorXInteger,omitempty"`     // cursor's position with dot number
	CursorYInteger    uint32  `protobuf:"varint,11,opt,name=cursorYInteger,proto3" json:"cursorYInteger,omitempty"`     // cursor's position with dot number
	CursorXMod        float32 `protobuf:"fixed32,12,opt,name=cursorXMod,proto3" json:"cursorXMod,omitempty"`            // cursor's position with dot number
	CursorYMod        float32 `protobuf:"fixed32,13,opt,name=cursorYMod,proto3" json:"cursorYMod,omitempty"`            // cursor's position with dot number
	WidgetX           uint32  `protobuf:"varint,14,opt,name=widgetX,proto3" json:"widgetX,omitempty"`                   // widget'position with dot number
	WidgetY           uint32  `protobuf:"varint,15,opt,name=widgetY,proto3" json:"widgetY,omitempty"`                   // widget'position with dot number
	WidgetW           uint32  `protobuf:"varint,16,opt,name=widgetW,proto3" json:"widgetW,omitempty"`                   // widget'shape with dot number
	WidgetH           uint32  `protobuf:"varint,17,opt,name=widgetH,proto3" json:"widgetH,omitempty"`                   // widget'shape with dot number
	// contains filtered or unexported fields
}

func (*MovingMessageBin) Descriptor deprecated

func (*MovingMessageBin) Descriptor() ([]byte, []int)

Deprecated: Use MovingMessageBin.ProtoReflect.Descriptor instead.

func (*MovingMessageBin) GetClientID

func (x *MovingMessageBin) GetClientID() string

func (*MovingMessageBin) GetCursorXInteger

func (x *MovingMessageBin) GetCursorXInteger() uint32

func (*MovingMessageBin) GetCursorXMod

func (x *MovingMessageBin) GetCursorXMod() float32

func (*MovingMessageBin) GetCursorYInteger

func (x *MovingMessageBin) GetCursorYInteger() uint32

func (*MovingMessageBin) GetCursorYMod

func (x *MovingMessageBin) GetCursorYMod() float32

func (*MovingMessageBin) GetDisplayNames

func (x *MovingMessageBin) GetDisplayNames() string

func (*MovingMessageBin) GetNeedBroadcast

func (x *MovingMessageBin) GetNeedBroadcast() bool

func (*MovingMessageBin) GetNickname

func (x *MovingMessageBin) GetNickname() string

func (*MovingMessageBin) GetParentDisplayName

func (x *MovingMessageBin) GetParentDisplayName() string

func (*MovingMessageBin) GetSignal

func (x *MovingMessageBin) GetSignal() Signal

func (*MovingMessageBin) GetStatus

func (x *MovingMessageBin) GetStatus() int32

func (*MovingMessageBin) GetTarget

func (x *MovingMessageBin) GetTarget() Target

func (*MovingMessageBin) GetUserID

func (x *MovingMessageBin) GetUserID() string

func (*MovingMessageBin) GetWidgetH

func (x *MovingMessageBin) GetWidgetH() uint32

func (*MovingMessageBin) GetWidgetW

func (x *MovingMessageBin) GetWidgetW() uint32

func (*MovingMessageBin) GetWidgetX

func (x *MovingMessageBin) GetWidgetX() uint32

func (*MovingMessageBin) GetWidgetY

func (x *MovingMessageBin) GetWidgetY() uint32

func (*MovingMessageBin) ProtoMessage

func (*MovingMessageBin) ProtoMessage()

func (*MovingMessageBin) ProtoReflect

func (x *MovingMessageBin) ProtoReflect() protoreflect.Message

func (*MovingMessageBin) Reset

func (x *MovingMessageBin) Reset()

func (*MovingMessageBin) String

func (x *MovingMessageBin) String() string

type Signal

type Signal int32
const (
	Signal_SIGNAL_PING                   Signal = 0
	Signal_SIGNAL_ENTER                  Signal = 1
	Signal_SIGNAL_LEAVE                  Signal = 2
	Signal_SIGNAL_CREATE_STATE           Signal = 3
	Signal_SIGNAL_DELETE_STATE           Signal = 4
	Signal_SIGNAL_UPDATE_STATE           Signal = 5
	Signal_SIGNAL_MOVE_STATE             Signal = 6
	Signal_SIGNAL_CREATE_OR_UPDATE_STATE Signal = 7
	Signal_SIGNAL_BROADCAST_ONLY         Signal = 8
	Signal_SIGNAL_PUT_STATE              Signal = 9
	Signal_SIGNAL_GLOBAL_BROADCAST_ONLY  Signal = 10
	Signal_SIGNAL_COOPERATE_ATTACH       Signal = 11
	Signal_SIGNAL_COOPERATE_DISATTACH    Signal = 12
	Signal_SIGNAL_MOVE_CURSOR            Signal = 13
)

func (Signal) Descriptor

func (Signal) Descriptor() protoreflect.EnumDescriptor

func (Signal) Enum

func (x Signal) Enum() *Signal

func (Signal) EnumDescriptor deprecated

func (Signal) EnumDescriptor() ([]byte, []int)

Deprecated: Use Signal.Descriptor instead.

func (Signal) Number

func (x Signal) Number() protoreflect.EnumNumber

func (Signal) String

func (x Signal) String() string

func (Signal) Type

func (Signal) Type() protoreflect.EnumType

type Target

type Target int32
const (
	Target_TARGET_NOTHING            Target = 0 // placeholder for nothing
	Target_TARGET_COMPONENTS         Target = 1 // ComponentsState
	Target_TARGET_DEPENDENCIES       Target = 2 // DependenciesState
	Target_TARGET_DRAG_SHADOW        Target = 3 // DragShadowState
	Target_TARGET_DOTTED_LINE_SQUARE Target = 4 // DottedLineSquareState
	Target_TARGET_DISPLAY_NAME       Target = 5 // DisplayNameState
	Target_TARGET_APPS               Target = 6 // only for broadcast
	Target_TARGET_RESOURCE           Target = 7 // only for broadcast
	Target_TARGET_ACTION             Target = 8 // only for broadcast
	Target_TARGET_CURSOR             Target = 9 // only for broadcast
)

func (Target) Descriptor

func (Target) Descriptor() protoreflect.EnumDescriptor

func (Target) Enum

func (x Target) Enum() *Target

func (Target) EnumDescriptor deprecated

func (Target) EnumDescriptor() ([]byte, []int)

Deprecated: Use Target.Descriptor instead.

func (Target) Number

func (x Target) Number() protoreflect.EnumNumber

func (Target) String

func (x Target) String() string

func (Target) Type

func (Target) Type() protoreflect.EnumType

type UserForCooperateFeedback

type UserForCooperateFeedback struct {
	ID                 string            `json:"id"`
	Nickname           string            `json:"nickname"`
	Avatar             string            `json:"avatar"`
	AttachedComponents map[string]string `json:"-"`
}

func NewUserForCooperateFeedbackByUser

func NewUserForCooperateFeedbackByUser(user *model.User) *UserForCooperateFeedback

func (*UserForCooperateFeedback) ExportAttachedComponentDisplayName

func (fuser *UserForCooperateFeedback) ExportAttachedComponentDisplayName() []string

Jump to

Keyboard shortcuts

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