Documentation ¶
Index ¶
Constants ¶
const ( TriedToWriteToAClosedSession = "tried to write to a closed session" SessionMessageBufferIsFull = "session message buffer is full" )
Variables ¶
Functions ¶
Types ¶
type Config ¶
type Config struct { WriteWait time.Duration PongWait time.Duration PingPeriod time.Duration MaxMessageSize int MessageBufferSize int }
Config configuration struct
type Handler ¶
type Handler interface { OnError(Session, error) OnConnect(Session) OnDisconnect(Session) OnMessageText(Session, protocol.Payload) Close() error }
Handler is an interface which defines a handler, methods are called upon when an event occurs.
type Hub ¶
type Hub interface { BroadcastPayload(protocol.Payload) error BroadcastRaw([]byte) error Close() Registered(session Session) bool Register(session Session) Unregister(session Session) }
Hub defines the methods for the hub. The hub is responsible for broadcasting messages amongst registered sessions.
type Session ¶
type Session interface { // RemoteAddr is the *http.Request's Real Remote Address (parses X-Forwarded-For or X-Real-IP) RemoteAddr() netip.AddrPort // Text() returns an io.Writer, writing text messages to the session. Text() io.Writer Write(messageType int, msg []byte) // WriteError writes an error in the custom protocol form. Any error occured during the // write is JSON related. WriteError(writeError error) (err error) WriteJSON(payload any) (err error) Close(closeError error) Context() context.Context Latency() float64 }
type WebSocket ¶
type WebSocket struct {
// contains filtered or unexported fields
}
WebSocket defines a WebSocket server that's designed with the `anime-pack`'s protocol in mind.
func NewWebSocket ¶
NewWebSocket returns an initialized WebSocket instance with the default config.
func NewWithConfig ¶
NewWithConfig returns an initialized WebSocket with the specified config.
func (*WebSocket) Close ¶
func (w *WebSocket) Close()
Close will forcefully close out all the other connections.
func (*WebSocket) Hub ¶
Hub returns the WebSocket's hub where it allows the user to be able to broadcast all sorts of messages to connected sessions.
func (*WebSocket) Request ¶
func (w *WebSocket) Request(rw http.ResponseWriter, r *http.Request)
Request provides a `net.http`.Handler to establish a websocket connection
func (*WebSocket) SetupHandler ¶
SetupHandler set's up the provided handler to the websocket in-order to start receiving events.