Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Codester241
GitHub Repository: Codester241/Kahoot-Flood
Path: blob/master/kahoot/handshake.go
463 views
1
package kahoot
2
3
import "errors"
4
5
func (c *Connection) Handshake() error {
6
advice := map[string]int{"timeout": 60000, "interval": 0}
7
content := map[string]interface{}{"version": "1.0", "minimumVersion": "1.0",
8
"supportedConnectionTypes": []string{"websocket"},
9
"advice": advice}
10
pack := c.Packet("/meta/handshake", content)
11
if err := c.WriteAck(pack, true); err != nil {
12
return err
13
}
14
res, err := c.ReadId(pack.Id)
15
if err != nil {
16
return err
17
}
18
19
// Check the 'successful' field
20
success, ok := res.Content["successful"].(bool)
21
if !ok || !success {
22
return errors.New("Negative 'successful' field.")
23
}
24
25
// Read the 'clientId' field
26
c.clientId, ok = res.Content["clientId"].(string)
27
if !ok {
28
return errors.New("No 'clientId' response field")
29
}
30
31
return nil
32
}
33
34