implement websocket transport connect
This commit is contained in:
parent
518d141dca
commit
fc09ac255e
@ -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"`
|
||||
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user