forked from getblank/wango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
52 lines (45 loc) · 1.34 KB
/
client.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 wango
import (
"strconv"
"github.com/pkg/errors"
"golang.org/x/net/websocket"
)
func (c *Conn) receiveWelcome() error {
var data []byte
err := websocket.Message.Receive(c.connection, &data)
if err != nil {
return errors.Wrap(err, "Can't receive welcome message")
}
msgType, msg, err := parseMessage(data)
if err != nil {
return errors.Wrap(err, "Parsing welcome message")
}
if msgType != msgWelcome {
if typeString, ok := msgIntTypes[msgType]; ok {
return errors.New("First message received must be welcome. Received: " + typeString)
}
return errors.New("First message received must be welcome. Received unknown type " + strconv.Itoa(msgType))
}
if len(msg) < 3 {
return errors.New("Invalid welcome message")
}
// sessionID, ok := msg[1].(string)
// if !ok {
// return errors.New("Invalid welcome message. SessionID is not a string")
// }
// c.sessionID = sessionID
// protocolVersion, ok := msg[1].(float64)
// if !ok {
// return errors.New("Invalid welcome message. ProtocolVersion is not a number")
// }
// c.protocolVersion = int(protocolVersion)
// serverIdent, ok := msg[1].(string)
// if !ok {
// return errors.New("Invalid welcome message. ServerIdent is not a string")
// }
// c.serverIdent = serverIdent
// if c.sessionOpenCallback != nil {
// c.sessionOpenCallback(c.sessionID)
// }
return nil
}