stream

package
Version: v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Request       = "request"
	Response      = "response"
	StatusSuccess = "success"
	StatusError   = "error"
)
View Source
const (
	ClientTypeServer = ClientType("server")
	ClientTypeMobile = ClientType("mobile")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Stat
	Id      string
	Connect *websocket.Conn
	Ip      string
	Send    chan []byte
	Token   string
	Type    ClientType
	// contains filtered or unexported fields
}

func NewClient added in v0.0.6

func NewClient(ctx *gin.Context, clientId, token string, clientType ClientType) (client *Client, err error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Notify

func (c *Client) Notify(t, b string)

func (*Client) Write

func (c *Client) Write(payload []byte) (err error)

func (*Client) WritePump

func (c *Client) WritePump()

send message to client

type ClientType added in v0.0.6

type ClientType string

type Hub

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

func NewHub

func NewHub(adaptors *adaptors.Adaptors,
	graceful_service *graceful_service.GracefulService) *Hub

func (*Hub) AddClient

func (h *Hub) AddClient(client *Client)

func (*Hub) GetClientServer added in v0.0.6

func (h *Hub) GetClientServer(clientId string) (client *Client, err error)

func (*Hub) GetCommandFromSubscribers added in v0.0.6

func (h *Hub) GetCommandFromSubscribers(cmd string) func(client *Client, msg Message)

func (*Hub) GetServer added in v0.0.6

func (h *Hub) GetServer(cli *Client) (server *Client, err error)

func (*Hub) GetServerClients added in v0.0.6

func (h *Hub) GetServerClients(cli *Client) (clients []*Client, err error)

func (*Hub) Recv

func (h *Hub) Recv(client *Client, b []byte)

client --> server

server --> [client1, client2]

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) Send

func (h *Hub) Send(client *Client, message []byte)

func (*Hub) Shutdown added in v0.0.6

func (h *Hub) Shutdown()

func (*Hub) Subscribe

func (h *Hub) Subscribe(command string, f func(client *Client, msg Message))

func (*Hub) UnSubscribe

func (h *Hub) UnSubscribe(command string)

type Message

type Message struct {
	Id      uuid.UUID              `json:"id"`
	Command string                 `json:"command"`
	Payload map[string]interface{} `json:"payload"`
	Forward string                 `json:"forward"`
	Status  string                 `json:"status"`
	Type    string                 `json:"type"`
}

func NewMessage

func NewMessage(b []byte) (message Message, err error)

func (*Message) Error

func (m *Message) Error(err error) *Message

func (*Message) IsError

func (m *Message) IsError() (err error)

func (*Message) Pack

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

func (*Message) Response

func (m *Message) Response(payload map[string]interface{}) *Message

func (*Message) Success

func (m *Message) Success() *Message

type Stat added in v0.0.6

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

type StreamService

type StreamService struct {
	Hub *Hub
	// contains filtered or unexported fields
}

func NewStreamService

func NewStreamService(hub *Hub,
	adaptors *adaptors.Adaptors) *StreamService

func (*StreamService) GetClientByIdAndType

func (s *StreamService) GetClientByIdAndType(clientId string, clientType ClientType) (client *Client, err error)

func (*StreamService) Subscribe

func (s *StreamService) Subscribe(command string, f func(client *Client, msg Message))

func (*StreamService) UnSubscribe

func (s *StreamService) UnSubscribe(command string)

func (*StreamService) Ws

func (w *StreamService) Ws(ctx *gin.Context)

Jump to

Keyboard shortcuts

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