identify control messages

This commit is contained in:
Marcelo Pires 2018-09-05 15:17:11 +02:00
parent 3586f4d799
commit ffa426bf69
2 changed files with 21 additions and 5 deletions

View File

@ -23,7 +23,7 @@ type Transport interface {
Publish(subscription string, message *message.Message) error
}
type Event string
type Event = string
const (
Subscribe Event = "/meta/subscribe"
@ -33,6 +33,17 @@ const (
Disconnect Event = "/meta/disconnect"
)
var ControlEvents = []Event{Subscribe, Connect, Unsubscribe, Handshake, Disconnect}
func IsControlMsg(channel string) bool {
for i := range ControlEvents {
if channel == ControlEvents[i] {
return true
}
}
return false
}
var registeredTransports = map[string]Transport{}
func RegisterTransport(t Transport) {

View File

@ -7,7 +7,6 @@ import (
"github.com/thesyncim/faye/transport"
"log"
"strconv"
"strings"
"sync"
"sync/atomic"
)
@ -62,16 +61,22 @@ func (w *Websocket) readWorker() error {
}
//dispatch
msg := payload[0]
if strings.HasPrefix(msg.Channel, "/meta") {
continue //todo update introspect message and update state
if transport.IsControlMsg(msg.Channel) {
//handle it
log.Println("recv control message", debugJson(msg))
continue
}
w.subsMu.Lock()
subscription := w.subs[msg.Channel]
w.subsMu.Unlock()
if subscription != nil {
subscription <- &msg
}
}
}