websocket

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package websocket to handling connection and session by messages and there subject

Index

Constants

View Source
const SessionMessageInit = "session_init"

SessionMessageInit subject in messages

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client of Websocket Server Connection

func NewClient

func NewClient(s *Server, ws *websocket.Conn) *Client

NewClient by websocket

func (*Client) Close

func (c *Client) Close()

Close Client

func (*Client) GetID

func (c *Client) GetID() string

GetID of Client ( UUID or Address to Client)

func (*Client) Listen

func (c *Client) Listen()

Listen write and read request via channel

func (*Client) Write

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

Write Message to Client

type Message

type Message struct {
	ID      uuid.UUID   `json:"id,omitempty"`
	Session uuid.UUID   `json:"-"`
	From    *Client     `json:"-"`
	Subject string      `json:"subject,omitempty"`
	Body    interface{} `json:"body,omitempty"`
	// contains filtered or unexported fields
}

Message which send over websocket

func (*Message) Answer

func (msg *Message) Answer(subject string, body interface{}) error

Answer to replay at a request

func (*Message) AnswerEverybody

func (msg *Message) AnswerEverybody(subject string, body interface{}) error

AnswerEverybody to replay all connection on Server

func (*Message) AnswerSession

func (msg *Message) AnswerSession(subject string, body interface{}) error

AnswerSession to replay all of current Session

func (*Message) Replay

func (msg *Message) Replay(body interface{}) error

Replay to request

func (*Message) ReplayEverybody

func (msg *Message) ReplayEverybody(body interface{}) error

ReplayEverybody to replay all connection on Server

func (*Message) ReplaySession

func (msg *Message) ReplaySession(body interface{}) error

ReplaySession to replay all of current Session

func (*Message) Validate

func (msg *Message) Validate() (bool, error)

Validate is it valid message to forward

type MessageHandleFunc

type MessageHandleFunc func(msg *Message)

MessageHandleFunc for handling messages

type Server

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

Server of websocket

func NewServer

func NewServer(msgChanIn chan *Message, sessionManager *SessionManager) *Server

NewServer to get a new Server for websockets

func (*Server) Handler

func (s *Server) Handler(w http.ResponseWriter, r *http.Request)

Handler of websocket Server for binding on webserver

func (*Server) SendAll

func (s *Server) SendAll(msg *Message)

SendAll to Send a message on every Client

type SessionManager

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

SessionManager to handle reconnected websocket

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager to get a new SessionManager

func (*SessionManager) HandleMessage

func (s *SessionManager) HandleMessage(msg *Message) bool

HandleMessage of client for Session

func (*SessionManager) Init

func (s *SessionManager) Init(c *Client)

Init Session for given Client

func (*SessionManager) Remove

func (s *SessionManager) Remove(c *Client) (client bool, session bool)

Remove clients from SessionManagerer - 1. result: clients removed from session manager - 2. result: session closed and all clients removed

func (*SessionManager) Send

func (s *SessionManager) Send(id uuid.UUID, msg *Message)

Send a message to a specific Session (and all his Websocket clients)

type WebsocketHandlerService

type WebsocketHandlerService struct {
	FallbackHandler MessageHandleFunc
	// contains filtered or unexported fields
}

WebsocketHandlerService to handle every Message on there Subject by Handlers

func NewWebsocketHandlerService

func NewWebsocketHandlerService() *WebsocketHandlerService

NewWebsocketHandlerService with Websocket Server

func (*WebsocketHandlerService) Close

func (ws *WebsocketHandlerService) Close()

Close webserver

func (*WebsocketHandlerService) Listen

func (ws *WebsocketHandlerService) Listen(path string)

Listen on net/http server at `path` and start running handling

func (*WebsocketHandlerService) SendAll

func (ws *WebsocketHandlerService) SendAll(msg *Message)

SendAll see Server.SendAll

func (*WebsocketHandlerService) SendSession

func (ws *WebsocketHandlerService) SendSession(id uuid.UUID, msg *Message)

SendSession see message to all connection of one session

func (*WebsocketHandlerService) SetHandler

func (ws *WebsocketHandlerService) SetHandler(subject string, f MessageHandleFunc)

SetHandler for a message type by subject

Jump to

Keyboard shortcuts

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