websocket

package
v0.0.0-...-c477d60 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Client  *Client
	Message *Message
}

Action Action data type

type Client

type Client struct {
	Room *Room
	User *datatype.User
	// contains filtered or unexported fields
}

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

func NewClient

func NewClient(conn *websocket.Conn) *Client

NewClient Client factory

func (*Client) Broadcast

func (c *Client) Broadcast(message string, payload *MessagePayload)

Broadcast Broadcasts a mesage to the room of the client

func (*Client) Close

func (c *Client) Close()

Close closes a client

func (*Client) Send

func (c *Client) Send(msg *Message)

Send sends a message to client

func (*Client) SendWithPayload

func (c *Client) SendWithPayload(msg string, p *MessagePayload)

SendWithPayload sends a message to client

type Message

type Message struct {
	//Room    string         `json:"-"`
	Message string         `json:"m"`
	Payload MessagePayload `json:"p"`
}

Message message datatype

func NewMessage

func NewMessage(msg string) *Message

NewMessage message factory

func (*Message) GetBool

func (m *Message) GetBool(key string) (bool, bool)

GetBool try to get a bool from payload

func (*Message) GetFloat64

func (m *Message) GetFloat64(key string) (float64, bool)

GetFloat64 try to get a float64 from payload

func (*Message) GetInt64

func (m *Message) GetInt64(key string) (int64, bool)

GetInt64 try to get an int from payload

func (*Message) GetString

func (m *Message) GetString(key string) (string, bool)

GetString try to get a string from payload

func (*Message) Marshal

func (m *Message) Marshal() []byte

Marshal marshals the message

func (*Message) Set

func (m *Message) Set(key string, val interface{})

Set sets a value in the message's payload

func (*Message) Unmarshal

func (m *Message) Unmarshal(data []byte)

Unmarshal unmarshals the message

type MessagePayload

type MessagePayload map[string]interface{}

MessagePayload Message Payload datatype

type Room

type Room struct {
	Route string

	IsRunning bool
	// contains filtered or unexported fields
}

Room room datatype

func NewRoom

func NewRoom(route string) *Room

NewRoom rom factory

func (*Room) AddHandler

func (r *Room) AddHandler(message string, f RoomHandler)

AddHandler adds a handler for the given msg

func (*Room) Broadcast

func (r *Room) Broadcast(message string, p *MessagePayload)

Broadcast broadcasts the given message to all room clients

func (*Room) BroadcastMsg

func (r *Room) BroadcastMsg(msg *Message)

BroadcastMsg broadcasts the given message to all room clients

func (*Room) ClientsCount

func (r *Room) ClientsCount() int

ClientsCount returns the number of clients connected

func (*Room) Enter

func (r *Room) Enter(c *Client)

Enter enter room

func (*Room) Handle

func (r *Room) Handle(a *Action)

Handle handles an incomming action

func (*Room) Leave

func (r *Room) Leave(c *Client)

Leave leaves room

func (*Room) OnQuit

func (r *Room) OnQuit(f func(r *Room))

OnQuit sets a callback to be called when the room quits

func (*Room) Quit

func (r *Room) Quit()

Quit quits the room

func (*Room) Run

func (r *Room) Run()

Run runs room main loop

func (*Room) SetOnEnter

func (r *Room) SetOnEnter(f RoomCientLifecycleCallback)

SetOnEnter sets room onEnter callback

func (*Room) SetOnLeave

func (r *Room) SetOnLeave(f RoomCientLifecycleCallback)

SetOnLeave sets room OnLeave callback

type RoomCientLifecycleCallback

type RoomCientLifecycleCallback func(c *Client)

RoomCientLifecycleCallback RoomCientLifecycleCallback datatype

type RoomHandler

type RoomHandler func(*Action)

RoomHandler room handler datatype

type RoomManager

type RoomManager struct {
	Rooms map[string]*Room
}

RoomManager room mamaber datatype

func NewRoomManager

func NewRoomManager() *RoomManager

NewRoomManager room manager factory

func (*RoomManager) AddRoom

func (rm *RoomManager) AddRoom(room *Room)

AddRoom adds a room

func (*RoomManager) HandleConnection

func (rm *RoomManager) HandleConnection(c *gin.Context, roomName string)

HandleConnection handles websocket request

func (*RoomManager) OnQuitRoom

func (rm *RoomManager) OnQuitRoom(r *Room)

OnQuitRoom OnQuitRoom gets called when a room quits

Jump to

Keyboard shortcuts

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