implement websocket transport connect

This commit is contained in:
Marcelo Pires 2018-09-05 01:22:43 +02:00
parent 518d141dca
commit fc09ac255e
3 changed files with 13 additions and 3 deletions

View File

@ -8,6 +8,7 @@ type Message struct {
Channel string `json:"channel,omitempty"`
Version string `json:"version,omitempty"`
SupportedConnectionTypes []string `json:"supportedConnectionTypes,omitempty"`
ConnectionType string `json:"connectionType,omitempty"`
MinimumVersion string `json:"minimumVersion,omitempty"`
Successful bool `json:"successful,omitempty"`
Ext interface{} `json:"ext,omitempty"`

View File

@ -27,6 +27,7 @@ type Event string
const (
Subscribe Event = "/meta/subscribe"
Connect Event = "/meta/connect"
Unsubscribe Event = "/meta/unsubscribe"
Handshake Event = "/meta/handshake"
Disconnect Event = "/meta/disconnect"

View File

@ -8,6 +8,8 @@ import (
"sync/atomic"
)
const transportName = "websocket"
func init() {
transport.RegisterTransport(&Websocket{})
}
@ -36,7 +38,7 @@ func (w *Websocket) Init(options *transport.Options) error {
return nil
}
func (w *Websocket) Name() string {
return "websocket"
return transportName
}
func (w *Websocket) nextMsgID() string {
return strconv.Itoa(int(atomic.AddUint64(w.msgID, 1)))
@ -49,7 +51,7 @@ func (w *Websocket) Handshake() (err error) {
if err = w.conn.WriteJSON(append(nil, message.Message{
Channel: string(transport.Handshake),
Version: "1.0", //todo const
SupportedConnectionTypes: []string{"websocket"},
SupportedConnectionTypes: []string{transportName},
})); err != nil {
return err
}
@ -68,7 +70,13 @@ func (w *Websocket) Handshake() (err error) {
}
func (w *Websocket) Connect() error {
panic("not implemented")
//todo verify if extensions are applied on connect,verify if hs is complete
return w.conn.WriteJSON(append(nil, message.Message{
Channel: string(transport.Connect),
ClientId: w.clientID,
ConnectionType: transportName,
Id: w.nextMsgID(),
}))
}
func (w *Websocket) Subscribe(subscription string, onMessage func(message *message.Message)) error {