2018-09-04 22:55:52 +00:00
|
|
|
package transport
|
|
|
|
|
|
|
|
import "github.com/thesyncim/faye/message"
|
|
|
|
|
|
|
|
// handshake, connect, disconnect, subscribe, unsubscribe and publish
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Url string
|
|
|
|
InExt message.Extension
|
2018-09-04 23:04:40 +00:00
|
|
|
OutExt message.Extension
|
2018-09-04 22:55:52 +00:00
|
|
|
//todo dial timeout
|
|
|
|
//todo read/write deadline
|
|
|
|
}
|
|
|
|
|
|
|
|
type Transport interface {
|
|
|
|
Name() string
|
|
|
|
Init(options *Options) error
|
|
|
|
Options() *Options
|
|
|
|
Handshake() error
|
|
|
|
Connect() error
|
|
|
|
Subscribe(subscription string, onMessage func(message *message.Message)) error
|
|
|
|
Unsubscribe(subscription string) error
|
|
|
|
Publish(subscription string, message *message.Message) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Event string
|
|
|
|
|
|
|
|
const (
|
|
|
|
Subscribe Event = "/meta/subscribe"
|
2018-09-04 23:22:43 +00:00
|
|
|
Connect Event = "/meta/connect"
|
2018-09-04 22:55:52 +00:00
|
|
|
Unsubscribe Event = "/meta/unsubscribe"
|
|
|
|
Handshake Event = "/meta/handshake"
|
|
|
|
Disconnect Event = "/meta/disconnect"
|
|
|
|
)
|
|
|
|
|
|
|
|
var registeredTransports = map[string]Transport{}
|
|
|
|
|
|
|
|
func RegisterTransport(t Transport) {
|
|
|
|
registeredTransports[t.Name()] = t //todo validate
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetTransport(name string) Transport {
|
|
|
|
return registeredTransports[name]
|
|
|
|
}
|