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 Publish(subscription string, message *message.Message) error
} }
type Event string type Event = string
const ( const (
Subscribe Event = "/meta/subscribe" Subscribe Event = "/meta/subscribe"
@ -33,6 +33,17 @@ const (
Disconnect Event = "/meta/disconnect" 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{} var registeredTransports = map[string]Transport{}
func RegisterTransport(t Transport) { func RegisterTransport(t Transport) {

View File

@ -7,7 +7,6 @@ import (
"github.com/thesyncim/faye/transport" "github.com/thesyncim/faye/transport"
"log" "log"
"strconv" "strconv"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
) )
@ -62,15 +61,21 @@ func (w *Websocket) readWorker() error {
} }
//dispatch //dispatch
msg := payload[0] 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() w.subsMu.Lock()
subscription := w.subs[msg.Channel] subscription := w.subs[msg.Channel]
w.subsMu.Unlock() w.subsMu.Unlock()
subscription <- &msg if subscription != nil {
subscription <- &msg
}
} }
} }