gateway

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RoomTitle = []string{"健身", "体育", "电影", "音乐"}
)
View Source
var (
	WsErrConnLoss = errors.New("conn already close")
)

Functions

func ClientIP

func ClientIP(c *http.Request) string

func InitWsServer

func InitWsServer()

func NewPushTask

func NewPushTask(roomLen, workNum, taskNum int)

func NewRoomManage

func NewRoomManage()

Types

type PushJob

type PushJob struct {
	Type     int
	PushType int
	RoomId   int
	Info     string
}

type PushManage

type PushManage interface {
	Push(job *PushJob)
}

func GetPushManage

func GetPushManage() PushManage

type PushTask

type PushTask struct {
	JobChan          []chan *PushJob
	DistributionTask chan *PushJob
}

func (*PushTask) Push

func (p *PushTask) Push(job *PushJob)

type Room

type Room struct {
	RConn sync.Map
	// contains filtered or unexported fields
}

一个房间代表一个订阅推送类型

func (*Room) Count

func (r *Room) Count() int

func (*Room) JoinRoom

func (r *Room) JoinRoom(ws *WsConnection) error

func (*Room) LeaveRoom

func (r *Room) LeaveRoom(wsId string) error

func (*Room) Push

func (r *Room) Push(msg *WSMessage)

type RoomManage

type RoomManage struct {
	AllRoom sync.Map
	AllConn sync.Map
}

func GetRoomManage

func GetRoomManage() *RoomManage

func (*RoomManage) AddConn

func (r *RoomManage) AddConn(ws *WsConnection)

func (*RoomManage) AddRoom

func (r *RoomManage) AddRoom(id int, wsId string) error

func (*RoomManage) DelConn

func (r *RoomManage) DelConn(ws *WsConnection)

func (*RoomManage) LeaveRoom

func (r *RoomManage) LeaveRoom(id int, wsId string) error

func (*RoomManage) NewRoom

func (r *RoomManage) NewRoom(id int, title string) error

func (*RoomManage) PushAll

func (r *RoomManage) PushAll(msg *WSMessage)

func (*RoomManage) PushRoom

func (r *RoomManage) PushRoom(id int, msg *WSMessage) error

type WSMessage

type WSMessage struct {
	Type int    `json:"type"`
	Data string `json:"data"`
}

type WsConnection

type WsConnection struct {
	// contains filtered or unexported fields
}

func NewWsConnection

func NewWsConnection(conn *websocket.Conn) *WsConnection

func (*WsConnection) CloseConn

func (w *WsConnection) CloseConn()

func (*WsConnection) GetIp

func (w *WsConnection) GetIp() string

func (*WsConnection) GetWsId

func (w *WsConnection) GetWsId() string

func (*WsConnection) ReadMsg

func (w *WsConnection) ReadMsg() (message *WSMessage, err error)

func (*WsConnection) SendMsg

func (w *WsConnection) SendMsg(msg *WSMessage) (err error)

func (*WsConnection) SetIp

func (w *WsConnection) SetIp(ip string)

func (*WsConnection) WsHandle

func (w *WsConnection) WsHandle()

Jump to

Keyboard shortcuts

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