Makis Maropoulos 2016-06-21 14:18:22 +03:00
parent 40c8c18792
commit f841bd4157
3 changed files with 25 additions and 24 deletions

View File

@ -111,7 +111,8 @@ func runAndWatch(flags cli.Flags) error {
if !isWindows {
fname = " " // we don't want to print the ".gooutput..." so dont print anything as a name
}
printer.Infof("\n[OP: %d] File '%s' changed, reloading...", atomic.LoadUint32(&times), fname)
printer.Infof("\n[OP: %d] File %s changed, reloading...", atomic.LoadUint32(&times), fname)
//kill the prev run

View File

@ -23,8 +23,8 @@ type (
MessageFunc interface{}
// Connection is the client
Connection interface {
// Emmiter implements EmitMessage & Emit
Emmiter
// Emitter implements EmitMessage & Emit
Emitter
// ID returns the connection's identifier
ID() string
// OnDisconnect registers a callback which fires when this connection is closed by an error or manual
@ -37,7 +37,7 @@ type (
EmitError(errorMessage string)
// To defines where server should send a message
// returns an emmiter to send messages
To(string) Emmiter
To(string) Emitter
// OnMessage registers a callback which fires when native websocket message received
OnMessage(NativeMessageFunc)
// On registers a callback to a particular event which fires when a message to this event received
@ -57,9 +57,9 @@ type (
onNativeMessageListeners []NativeMessageFunc
onEventListeners map[string][]MessageFunc
// these were maden for performance only
self Emmiter // pre-defined emmiter than sends message to its self client
broadcast Emmiter // pre-defined emmiter that sends message to all except this
all Emmiter // pre-defined emmiter which sends message to all clients
self Emitter // pre-defined emmiter than sends message to its self client
broadcast Emitter // pre-defined emmiter that sends message to all except this
all Emitter // pre-defined emmiter which sends message to all clients
server *server
}
@ -81,9 +81,9 @@ func newConnection(websocketConn *websocket.Conn, s *server) *connection {
server: s,
}
c.self = newEmmiter(c, c.id)
c.broadcast = newEmmiter(c, NotMe)
c.all = newEmmiter(c, All)
c.self = newEmitter(c, c.id)
c.broadcast = newEmitter(c, NotMe)
c.all = newEmitter(c, All)
return c
}
@ -251,7 +251,7 @@ func (c *connection) EmitError(errorMessage string) {
}
}
func (c *connection) To(to string) Emmiter {
func (c *connection) To(to string) Emitter {
if to == NotMe { // if send to all except me, then return the pre-defined emmiter, and so on
return c.broadcast
} else if to == All {
@ -260,7 +260,7 @@ func (c *connection) To(to string) Emmiter {
return c.self
}
// is an emmiter to another client/connection
return newEmmiter(c, to)
return newEmitter(c, to)
}
func (c *connection) EmitMessage(nativeMessage []byte) error {

View File

@ -1,44 +1,44 @@
package websocket
const (
// All is the string which the Emmiter use to send a message to all
// All is the string which the Emitter use to send a message to all
All = ""
// NotMe is the string which the Emmiter use to send a message to all except this connection
// NotMe is the string which the Emitter use to send a message to all except this connection
NotMe = ";iris;to;all;except;me;"
// Broadcast is the string which the Emmiter use to send a message to all except this connection, same as 'NotMe'
// Broadcast is the string which the Emitter use to send a message to all except this connection, same as 'NotMe'
Broadcast = NotMe
)
type (
// Emmiter is the message/or/event manager
Emmiter interface {
// Emitter is the message/or/event manager
Emitter interface {
// EmitMessage sends a native websocket message
EmitMessage([]byte) error
// Emit sends a message on a particular event
Emit(string, interface{}) error
}
emmiter struct {
emitter struct {
conn *connection
to string
}
)
var _ Emmiter = &emmiter{}
var _ Emitter = &emitter{}
// emmiter implementation
// emitter implementation
func newEmmiter(c *connection, to string) *emmiter {
return &emmiter{conn: c, to: to}
func newEmitter(c *connection, to string) *emitter {
return &emitter{conn: c, to: to}
}
func (e *emmiter) EmitMessage(nativeMessage []byte) error {
func (e *emitter) EmitMessage(nativeMessage []byte) error {
mp := messagePayload{e.conn.id, e.to, nativeMessage}
e.conn.server.messages <- mp
return nil
}
func (e *emmiter) Emit(event string, data interface{}) error {
func (e *emitter) Emit(event string, data interface{}) error {
message, err := serialize(event, data)
if err != nil {
return err