-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsocket_server.go
79 lines (58 loc) · 2.22 KB
/
socket_server.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package sio
import mapset "github.com/deckarep/golang-set/v2"
type (
ServerSocket interface {
Socket
ServerSocketEvents
// Retrieves the underlying Server.
Server() *Server
// Retrieves the Namespace this socket is connected to.
Namespace() *Namespace
// Join room(s)
Join(room ...Room)
// Leave a room
Leave(room Room)
// Get a set of all rooms socket was joined to.
Rooms() mapset.Set[Room]
// Register a middleware for events.
//
// Function signature must be same as with On and Once:
// func(eventName string, v ...any) error
Use(f any)
// Sets a modifier for a subsequent event emission that the event
// will only be broadcast to clients that have joined the given room.
//
// To emit to multiple rooms, you can call To several times.
To(room ...Room) *BroadcastOperator
// Alias of To(...)
In(room ...Room) *BroadcastOperator
// Sets a modifier for a subsequent event emission that the event
// will only be broadcast to clients that have not joined the given rooms.
Except(room ...Room) *BroadcastOperator
// Sets a modifier for a subsequent event emission that
// the event data will only be broadcast to the current node.
Local() *BroadcastOperator
// Sets a modifier for a subsequent event emission that
// the event data will only be broadcast to every sockets but the sender.
Broadcast() *BroadcastOperator
// Disconnect from namespace.
//
// If `close` is true, all namespaces are going to be disconnected (a DISCONNECT packet will be sent),
// and the underlying Engine.IO connection will be terminated.
//
// If `close` is false, only the current namespace will be disconnected (a DISCONNECT packet will be sent),
// and the underlying Engine.IO connection will be kept open.
Disconnect(close bool)
}
ServerSocketEvents interface {
OnError(f ServerSocketErrorFunc)
OnceError(f ServerSocketErrorFunc)
OffError(f ...ServerSocketErrorFunc)
OnDisconnecting(f ServerSocketDisconnectingFunc)
OnceDisconnecting(f ServerSocketDisconnectingFunc)
OffDisconnecting(f ...ServerSocketDisconnectingFunc)
OnDisconnect(f ServerSocketDisconnectFunc)
OnceDisconnect(f ServerSocketDisconnectFunc)
OffDisconnect(f ...ServerSocketDisconnectFunc)
}
)