forked from njones/socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.v3.go
82 lines (61 loc) · 1.73 KB
/
server.v3.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
80
81
82
package socketio
import (
"net/http"
nmem "github.com/njones/socketio/adaptor/transport/memory"
eio "github.com/njones/socketio/engineio"
siop "github.com/njones/socketio/protocol"
siot "github.com/njones/socketio/transport"
)
// https://socket.io/docs/v4/migrating-from-2-x-to-3-0/
// This is the revision 5 of the Socket.IO protocol, included in [email protected].
type ServerV3 struct {
inSocketV3
doBinaryAckPacket func(SocketID, siot.Socket) error
prev *ServerV2
}
func NewServerV3(opts ...Option) *ServerV3 {
v3 := &ServerV3{}
v3.new(opts...)
v2 := v3.prev
v1 := v2.prev
v1.eio = eio.NewServerV4(eio.WithPath(*v1.path)).(eio.EIOServer)
v1.eio.With(opts...)
v3.With(opts...)
return v3
}
func (v3 *ServerV3) new(opts ...Option) Server {
v3.prev = (&ServerV2{}).new(opts...).(*ServerV2)
v3.onConnect = make(map[Namespace]onConnectCallbackVersion3)
v2 := v3.prev
v1 := v2.prev
v1.run = runV3(v3)
v1.transport = nmem.NewInMemoryTransport(siop.NewPacketV5)
v1.setTransporter(v1.transport)
v1.protectedEventName = v3ProtectedEventName
v1.doConnectPacket = doConnectPacketV3(v3)
v3.doBinaryAckPacket = doBinaryAckPacket(v1)
v3.inSocketV3.prev = v2.inSocketV2.clone()
return v3
}
func (v3 *ServerV3) With(opts ...Option) {
v3.prev.With(opts...)
for _, opt := range opts {
opt(v3)
}
}
func (v3 *ServerV3) In(room Room) inToEmit {
rtn := v3.clone()
rtn.setIsServer(true)
return rtn.In(room)
}
func (v3 *ServerV3) Of(ns Namespace) inSocketV3 {
rtn := v3.clone()
rtn.setIsServer(true)
return rtn.Of(ns)
}
func (v3 *ServerV3) To(room Room) inToEmit {
rtn := v3.clone()
rtn.setIsServer(true)
return rtn.To(room)
}
func (v3 *ServerV3) ServeHTTP(w http.ResponseWriter, r *http.Request) { v3.prev.ServeHTTP(w, r) }