stream

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Id      string
	Connect *websocket.Conn
	Ip      string
	Send    chan []byte
	Token   string
	Type    string
}

func (*Client) Close

func (c *Client) Close()

func (*Client) Notify

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

func (*Client) Write

func (c *Client) Write(opCode int, payload []byte) error

func (*Client) WritePump

func (c *Client) WritePump()

send message to client

type Hub

type Hub struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewHub

func NewHub() *Hub

func (*Hub) AddClient

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

func (*Hub) Broadcast

func (h *Hub) Broadcast(message []byte)

func (*Hub) Clients

func (h *Hub) Clients() (clients []*Client)

func (*Hub) GetClientByIdAndType

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

func (*Hub) Recv

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

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) Send

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

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"`
}

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 StreamService

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

func NewStreamService

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

func (*StreamService) Broadcast

func (s *StreamService) Broadcast(message []byte)

func (*StreamService) GetClientByIdAndType

func (s *StreamService) GetClientByIdAndType(clientId,
	clientType string) (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