Documentation
¶
Index ¶
- func EncodePacket(p *Packet) ([]byte, error)
- type ClientSocket
- type EventHandler
- type Packet
- type PacketType
- type RoomBroadcaster
- type Server
- type ServerRoomBroadcaster
- type Socket
- func (s *Socket) BroadcastTo(room string) *RoomBroadcaster
- func (s *Socket) Close() error
- func (s *Socket) Conn() *zsocket.Conn
- func (s *Socket) Emit(event string, data any) error
- func (s *Socket) EmitWithAck(ctx context.Context, event string, data any) ([]byte, error)
- func (s *Socket) ID() string
- func (s *Socket) Join(room string)
- func (s *Socket) Leave(room string)
- func (s *Socket) On(eventName string, handler EventHandler)
- func (s *Socket) To(room string) *RoomBroadcaster
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodePacket ¶
EncodePacket serializes a packet to JSON bytes.
Types ¶
type ClientSocket ¶
type ClientSocket struct {
*Socket
}
ClientSocket represents a client-side Socket.IO event connection.
func DialSocket ¶
func DialSocket(urlStr string, requestHeader http.Header) (*ClientSocket, error)
DialSocket connects to a Socket.IO WebSocket server.
type EventHandler ¶
EventHandler handles an incoming event. It may return a response payload or error for ACKs.
type Packet ¶
type Packet struct {
Type PacketType `json:"type"`
Event string `json:"event,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
AckID uint64 `json:"ack_id,omitempty"`
Error string `json:"error,omitempty"`
}
Packet represents a Socket.IO event or ACK payload.
func DecodePacket ¶
DecodePacket deserializes JSON bytes into a packet.
type PacketType ¶
type PacketType byte
PacketType defines the type of Socket.IO packet.
const ( PacketEvent PacketType = 1 PacketAck PacketType = 2 )
type RoomBroadcaster ¶
type RoomBroadcaster struct {
// contains filtered or unexported fields
}
RoomBroadcaster handles room emissions.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server manages Socket.IO event-driven connections.
func (*Server) OnConnection ¶
OnConnection registers a callback for new client connections.
func (*Server) ServeHTTP ¶
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles incoming HTTP websocket upgrade requests.
func (*Server) To ¶
func (srv *Server) To(room string) *ServerRoomBroadcaster
To returns a ServerRoomBroadcaster for global room broadcasts.
type ServerRoomBroadcaster ¶
type ServerRoomBroadcaster struct {
// contains filtered or unexported fields
}
ServerRoomBroadcaster broadcasts events to rooms from the server instance.
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
Socket represents an event-driven WebSocket client connection.
func (*Socket) BroadcastTo ¶
func (s *Socket) BroadcastTo(room string) *RoomBroadcaster
BroadcastTo returns a RoomBroadcaster for sending to a room, excluding this socket.
func (*Socket) EmitWithAck ¶
EmitWithAck sends an event and waits for the peer to acknowledge/reply.
func (*Socket) On ¶
func (s *Socket) On(eventName string, handler EventHandler)
On registers an event listener for eventName.
func (*Socket) To ¶
func (s *Socket) To(room string) *RoomBroadcaster
To returns a RoomBroadcaster for sending messages to a room.