ws

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

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_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_CREATE_OR_UPDATE_STATE_FAILED = 9
View Source
const ERROR_CREATE_OR_UPDATE_STATE_OK = 0
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_MOVE_STATE_FAILED = 8
View Source
const ERROR_MOVE_STATE_OK = 0
View Source
const ERROR_UPDATE_STATE_FAILED = 7
View Source
const ERROR_UPDATE_STATE_OK = 0
View Source
const OPTION_BROADCAST_ROOM = 1 // 00000000000000000000000000000001; // use as signed int32 in typescript
View Source
const SIGNAL_BROADCAST_ONLY = 8
View Source
const SIGNAL_COOPERATE_ATTACH = 11
View Source
const SIGNAL_COOPERATE_DISATTACH = 12
View Source
const SIGNAL_CREATE_OR_UPDATE_STATE = 7
View Source
const SIGNAL_CREATE_STATE = 3
View Source
const SIGNAL_DELETE_STATE = 4
View Source
const SIGNAL_ENTER = 1
View Source
const SIGNAL_GLOBAL_BROADCAST_ONLY = 10
View Source
const SIGNAL_LEAVE = 2
View Source
const SIGNAL_MOVE_STATE = 6
View Source
const SIGNAL_PING = 0

for message

View Source
const SIGNAL_PUT_STATE = 9
View Source
const SIGNAL_UPDATE_STATE = 5
View Source
const TARGET_ACTION = 8 // only for broadcast
View Source
const TARGET_APPS = 6 // only for broadcast
View Source
const TARGET_COMPONENTS = 1 // ComponentsState
View Source
const TARGET_DEPENDENCIES = 2 // DependenciesState
View Source
const TARGET_DISPLAY_NAME = 5 // DisplayNameState
View Source
const TARGET_DOTTED_LINE_SQUARE = 4 // DottedLineSquareState
View Source
const TARGET_DRAG_SHADOW = 3 // DragShadowState
View Source
const TARGET_NOTNING = 0 // placeholder for nothing
View Source
const TARGET_RESOURCE = 7 // only for broadcast

Variables

This section is empty.

Functions

func KickClient

func KickClient(hub *Hub, client *Client)

Types

type Broadcast

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

type Client

type Client struct {
	ID uuid.UUID

	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) *Client

func (*Client) ExportMappedUserIDToString added in v1.9.0

func (c *Client) ExportMappedUserIDToString() string

func (*Client) Feedback

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

func (*Client) GetAPPID

func (c *Client) GetAPPID() int

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) 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.

type ComponentAttachedUsers added in v1.7.1

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

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

	// on message process
	OnMessage chan *Message

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

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

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

	// impl
	TreeStateServiceImpl *state.TreeStateServiceImpl
	KVStateServiceImpl   *state.KVStateServiceImpl
	SetStateServiceImpl  *state.SetStateServiceImpl
	AppServiceImpl       *app.AppServiceImpl
	ResourceServiceImpl  *resource.ResourceServiceImpl
}

clients hub, maintains active clients and broadcast messags.

func NewHub

func NewHub() *Hub

func (*Hub) BroadcastToGlobal

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

func (*Hub) BroadcastToOtherClients

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

func (*Hub) BroadcastToRoomAllClients added in v1.7.1

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

func (*Hub) CleanRoom added in v1.7.2

func (hub *Hub) CleanRoom(roomID int)

func (*Hub) GetInRoomUsersByRoomID added in v1.7.1

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

func (*Hub) SetAppServiceImpl

func (hub *Hub) SetAppServiceImpl(asi *app.AppServiceImpl)

func (*Hub) SetKVStateServiceImpl

func (hub *Hub) SetKVStateServiceImpl(kvssi *state.KVStateServiceImpl)

func (*Hub) SetResourceServiceImpl

func (hub *Hub) SetResourceServiceImpl(rsi *resource.ResourceServiceImpl)

func (*Hub) SetSetStateServiceImpl

func (hub *Hub) SetSetStateServiceImpl(sssi *state.SetStateServiceImpl)

func (*Hub) SetTreeStateServiceImpl

func (hub *Hub) SetTreeStateServiceImpl(tssi *state.TreeStateServiceImpl)

type InRoomUsers added in v1.7.1

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 added in v1.7.1

func NewInRoomUsers(roomID int) *InRoomUsers

func (*InRoomUsers) AttachComponent added in v1.7.1

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

func (*InRoomUsers) Count added in v1.7.2

func (iru *InRoomUsers) Count() int

func (*InRoomUsers) DisattachComponent added in v1.7.1

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

func (*InRoomUsers) EnterRoom added in v1.7.1

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

func (*InRoomUsers) FetchAllAttachedUsers added in v1.7.1

func (iru *InRoomUsers) FetchAllAttachedUsers() *ComponentAttachedUsers

func (*InRoomUsers) FetchAllInRoomUsers added in v1.7.1

func (iru *InRoomUsers) FetchAllInRoomUsers() *InRoomUsersFeedback

func (*InRoomUsers) LeaveRoom added in v1.7.1

func (iru *InRoomUsers) LeaveRoom(userID string)

type InRoomUsersFeedback added in v1.7.1

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 NewMessage

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

func (*Message) RewriteBroadcast

func (m *Message) RewriteBroadcast()

func (*Message) SetBroadcastPayload added in v1.7.1

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

func (*Message) SetBroadcastType added in v1.7.1

func (m *Message) SetBroadcastType(t string)

func (*Message) SetSignal added in v1.7.1

func (m *Message) SetSignal(s int)

type UserForCooperateFeedback added in v1.7.1

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

func NewUserForCooperateFeedbackByUser added in v1.7.1

func NewUserForCooperateFeedbackByUser(user *repository.User) *UserForCooperateFeedback

func (*UserForCooperateFeedback) ExportAttachedComponentDisplayName added in v1.7.1

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

Jump to

Keyboard shortcuts

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