-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsocket.go
52 lines (40 loc) · 1.34 KB
/
socket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sio
import (
"time"
"github.com/karagenc/socket.io-go/adapter"
)
type (
SocketID = adapter.SocketID
Room = adapter.Room
)
type Socket interface {
// Socket ID. For client socket, this may return an empty string if the client hasn't connected yet.
ID() SocketID
// Is the socket (currently) connected?
Connected() bool
// Whether the connection state was recovered after a
// temporary disconnection. In that case, any missed packets
// will be transmitted, the data attribute
// and the rooms will be restored.
Recovered() bool
// Emit a message.
// If you want to emit a binary data, use sio.Binary instead of []byte.
Emit(eventName string, v ...any)
// Return an emitter with timeout set.
Timeout(timeout time.Duration) Emitter
// Register an event handler.
OnEvent(eventName string, handler any)
// Register a one-time event handler.
// The handler will run once and will be removed afterwards.
OnceEvent(eventName string, handler any)
// Remove an event handler.
//
// If you want to remove all handlers of a particular event,
// provide the eventName and leave the handler nil.
//
// Otherwise, provide both the eventName and handler arguments.
OffEvent(eventName string, handler ...any)
// Remove all event handlers.
// Including special event handlers (connect, disconnect, disconnecting, etc.).
OffAll()
}