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"` Channel string `json:"channel,omitempty"`
Version string `json:"version,omitempty"` Version string `json:"version,omitempty"`
SupportedConnectionTypes []string `json:"supportedConnectionTypes,omitempty"` SupportedConnectionTypes []string `json:"supportedConnectionTypes,omitempty"`
ConnectionType string `json:"connectionType,omitempty"`
MinimumVersion string `json:"minimumVersion,omitempty"` MinimumVersion string `json:"minimumVersion,omitempty"`
Successful bool `json:"successful,omitempty"` Successful bool `json:"successful,omitempty"`
Ext interface{} `json:"ext,omitempty"` Ext interface{} `json:"ext,omitempty"`

View File

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

View File

@ -8,6 +8,8 @@ import (
"sync/atomic" "sync/atomic"
) )
const transportName = "websocket"
func init() { func init() {
transport.RegisterTransport(&Websocket{}) transport.RegisterTransport(&Websocket{})
} }
@ -36,7 +38,7 @@ func (w *Websocket) Init(options *transport.Options) error {
return nil return nil
} }
func (w *Websocket) Name() string { func (w *Websocket) Name() string {
return "websocket" return transportName
} }
func (w *Websocket) nextMsgID() string { func (w *Websocket) nextMsgID() string {
return strconv.Itoa(int(atomic.AddUint64(w.msgID, 1))) 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{ if err = w.conn.WriteJSON(append(nil, message.Message{
Channel: string(transport.Handshake), Channel: string(transport.Handshake),
Version: "1.0", //todo const Version: "1.0", //todo const
SupportedConnectionTypes: []string{"websocket"}, SupportedConnectionTypes: []string{transportName},
})); err != nil { })); err != nil {
return err return err
} }
@ -68,7 +70,13 @@ func (w *Websocket) Handshake() (err error) {
} }
func (w *Websocket) Connect() 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 { func (w *Websocket) Subscribe(subscription string, onMessage func(message *message.Message)) error {