@@ -19,15 +19,15 @@ func main() {
19
19
return
20
20
}
21
21
22
- ws.On (handler. WebsocketConnect , func (ctx *websockets.Ctx ) {
22
+ ws.On (websockets. EventType_Connect , func (ctx *websockets.Ctx ) {
23
23
// handle connections
24
24
})
25
25
26
- ws.On (handler. WebsocketDisconnect , func (ctx *websockets.Ctx ) {
26
+ ws.On (websockets. EventType_Disconnect , func (ctx *websockets.Ctx ) {
27
27
// handle disconnections
28
28
})
29
29
30
- ws.On (handler. WebsocketMessage , func (ctx *websockets.Ctx ) {
30
+ ws.On (websockets. EventType_Message , func (ctx *websockets.Ctx ) {
31
31
// handle messages
32
32
})
33
33
@@ -41,8 +41,8 @@ func main() {
41
41
42
42
<Properties >
43
43
<Property name = " eventType" required type = " WebsocketEventType" >
44
- The type of websocket event to listen for. Can be ` WebsocketConnect ` ,
45
- ` WebsocketDisconnect ` , or ` WebsocketMessage ` .
44
+ The type of websocket event to listen for. Can be ` EventType_Connect ` ,
45
+ ` EventType_Disconnect ` , or ` EventType_Message ` .
46
46
</Property >
47
47
<Property name = " middleware" required type = " ...interface{}" >
48
48
The middleware function to use as the handler for Websocket events. If you
@@ -55,7 +55,7 @@ func main() {
55
55
### Register a handler for message events
56
56
57
57
``` go
58
- ws.On (handler. WebsocketMessage , func (ctx *websockets.Ctx ) {
58
+ ws.On (websockets. EventType_Message , func (ctx *websockets.Ctx ) {
59
59
fmt.Printf (" New Message from %s : %s \n " , ctx.Request .ConnectionID (), ctx.Request .Message ())
60
60
})
61
61
```
@@ -85,19 +85,19 @@ func main() {
85
85
}
86
86
87
87
// Register a new connection on connect
88
- ws.On (handler. WebsocketConnect , func (ctx *websockets.Ctx ) error {
88
+ ws.On (websockets. EventType_Connect , func (ctx *websockets.Ctx ) error {
89
89
return := connections.Set (context.TODO (), ctx.Request .ConnectionID (), map [string ]interface {}{
90
90
" connectionId" : ctx.Request .ConnectionID (),
91
91
})
92
92
})
93
93
94
94
// Remove a registered connection on disconnect
95
- ws.On (handler. WebsocketDisconnect , func (ctx *websockets.Ctx ) error {
95
+ ws.On (websockets. EventType_Disconnect , func (ctx *websockets.Ctx ) error {
96
96
return connections.Delete (context.TODO (), ctx.Request .ConnectionID ())
97
97
})
98
98
99
99
// Broadcast message to all the registered websocket connections
100
- ws.On (handler. WebsocketMessage , func (ctx *websockets.Ctx ) error {
100
+ ws.On (websockets. EventType_Message , func (ctx *websockets.Ctx ) error {
101
101
connectionStream , err := connections.Keys (context.TODO ())
102
102
if err != nil {
103
103
return ctx, err
@@ -151,7 +151,7 @@ func main() {
151
151
return
152
152
}
153
153
154
- ws.On (handler. WebsocketMessage , validateMessage, handleMessage)
154
+ ws.On (websockets. EventType_Message , validateMessage, handleMessage)
155
155
156
156
if err := nitric.Run (); err != nil {
157
157
fmt.Println (err)
0 commit comments