Documentation ¶
Index ¶
- Constants
- type Config
- type Melody
- func (m *Melody) Connect(addr string, keys ...map[string]interface{}) (*Session, error)
- func (m *Melody) ConnectWithHeader(addr string, header http.Header, keys ...map[string]interface{}) (*Session, error)
- func (m *Melody) HandleClose(fn func(*Session, int, string) error)
- func (m *Melody) HandleConnect(fn func(*Session))
- func (m *Melody) HandleDisconnect(fn func(*Session))
- func (m *Melody) HandleError(fn func(*Session, error))
- func (m *Melody) HandleMessage(fn func(*Session, []byte))
- func (m *Melody) HandleMessageBinary(fn func(*Session, []byte))
- func (m *Melody) HandlePing(fn func(*Session))
- func (m *Melody) HandleSentMessage(fn func(*Session, []byte))
- func (m *Melody) HandleSentMessageBinary(fn func(*Session, []byte))
- type Session
- func (s *Session) Close() error
- func (s *Session) CloseWithMsg(msg []byte) error
- func (s *Session) Get(key string) (value interface{}, exists bool)
- func (s *Session) IsClosed() bool
- func (s *Session) MustGet(key string) interface{}
- func (s *Session) Send(bytes []byte)
- func (s *Session) Set(key string, value interface{})
- func (s *Session) Write(msg []byte) error
- func (s *Session) WriteBinary(msg []byte) error
Constants ¶
const ( CloseNormalClosure = 1000 CloseGoingAway = 1001 CloseProtocolError = 1002 CloseUnsupportedData = 1003 CloseNoStatusReceived = 1005 CloseAbnormalClosure = 1006 CloseInvalidFramePayloadData = 1007 ClosePolicyViolation = 1008 CloseMessageTooBig = 1009 CloseMandatoryExtension = 1010 CloseInternalServerErr = 1011 CloseServiceRestart = 1012 CloseTryAgainLater = 1013 CloseTLSHandshake = 1015 )
Close codes defined in RFC 6455, section 11.7. Duplicate of codes from gorilla/websocket for convenience.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { WriteWait time.Duration // Milliseconds until write times out. PongWait time.Duration // Timeout for waiting on pong. PingPeriod time.Duration // Milliseconds between pings. MaxMessageSize int64 // Maximum size in bytes of a message. MessageBufferSize int // The max amount of messages that can be in a sessions buffer before it starts dropping them. }
Config melody configuration struct.
type Melody ¶
type Melody struct { Config *Config // contains filtered or unexported fields }
Melody implements a websocket manager.
func (*Melody) Connect ¶
HandleRequest upgrades http requests to websocket connections and dispatches them to be handled by the melody instance.
func (*Melody) ConnectWithHeader ¶
func (m *Melody) ConnectWithHeader(addr string, header http.Header, keys ...map[string]interface{}) (*Session, error)
HandleRequestWithKeys does the same as HandleRequest but populates session.Keys with keys.
func (*Melody) HandleClose ¶
HandleClose sets the handler for close messages received from the session. The code argument to h is the received close code or CloseNoStatusReceived if the close message is empty. The default close handler sends a close frame back to the session.
The application must read the connection to process close messages as described in the section on Control Frames above.
The connection read methods return a CloseError when a close frame is received. Most applications should handle close messages as part of their normal error handling. Applications should only set a close handler when the application must perform some action before sending a close frame back to the session.
func (*Melody) HandleConnect ¶
HandleConnect fires fn when a session connects.
func (*Melody) HandleDisconnect ¶
HandleDisconnect fires fn when a session disconnects.
func (*Melody) HandleError ¶
HandleError fires fn when a session has an error.
func (*Melody) HandleMessage ¶
HandleMessage fires fn when a text message comes in.
func (*Melody) HandleMessageBinary ¶
HandleMessageBinary fires fn when a binary message comes in.
func (*Melody) HandlePing ¶
HandlePing fires fn when a pong is received from a session.
func (*Melody) HandleSentMessage ¶
HandleSentMessage fires fn when a text message is successfully sent.
func (*Melody) HandleSentMessageBinary ¶
HandleSentMessageBinary fires fn when a binary message is successfully sent.
type Session ¶
type Session struct { Response *http.Response Keys map[string]interface{} // contains filtered or unexported fields }
Session wrapper around websocket connections.
func (*Session) CloseWithMsg ¶
CloseWithMsg closes the session with the provided payload. Use the FormatCloseMessage function to format a proper close message payload.
func (*Session) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Session) MustGet ¶
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*Session) Set ¶
Set is used to store a new key/value pair exclusivelly for this session. It also lazy initializes s.Keys if it was not used previously.
func (*Session) WriteBinary ¶
WriteBinary writes a binary message to session.