mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 11:06:27 +01:00
This commit is contained in:
parent
40c8c18792
commit
f841bd4157
|
@ -111,7 +111,8 @@ func runAndWatch(flags cli.Flags) error {
|
||||||
if !isWindows {
|
if !isWindows {
|
||||||
fname = " " // we don't want to print the ".gooutput..." so dont print anything as a name
|
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(×), fname)
|
|
||||||
|
printer.Infof("\n[OP: %d] File %s changed, reloading...", atomic.LoadUint32(×), fname)
|
||||||
|
|
||||||
//kill the prev run
|
//kill the prev run
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ type (
|
||||||
MessageFunc interface{}
|
MessageFunc interface{}
|
||||||
// Connection is the client
|
// Connection is the client
|
||||||
Connection interface {
|
Connection interface {
|
||||||
// Emmiter implements EmitMessage & Emit
|
// Emitter implements EmitMessage & Emit
|
||||||
Emmiter
|
Emitter
|
||||||
// ID returns the connection's identifier
|
// ID returns the connection's identifier
|
||||||
ID() string
|
ID() string
|
||||||
// OnDisconnect registers a callback which fires when this connection is closed by an error or manual
|
// OnDisconnect registers a callback which fires when this connection is closed by an error or manual
|
||||||
|
@ -37,7 +37,7 @@ type (
|
||||||
EmitError(errorMessage string)
|
EmitError(errorMessage string)
|
||||||
// To defines where server should send a message
|
// To defines where server should send a message
|
||||||
// returns an emmiter to send messages
|
// returns an emmiter to send messages
|
||||||
To(string) Emmiter
|
To(string) Emitter
|
||||||
// OnMessage registers a callback which fires when native websocket message received
|
// OnMessage registers a callback which fires when native websocket message received
|
||||||
OnMessage(NativeMessageFunc)
|
OnMessage(NativeMessageFunc)
|
||||||
// On registers a callback to a particular event which fires when a message to this event received
|
// On registers a callback to a particular event which fires when a message to this event received
|
||||||
|
@ -57,9 +57,9 @@ type (
|
||||||
onNativeMessageListeners []NativeMessageFunc
|
onNativeMessageListeners []NativeMessageFunc
|
||||||
onEventListeners map[string][]MessageFunc
|
onEventListeners map[string][]MessageFunc
|
||||||
// these were maden for performance only
|
// these were maden for performance only
|
||||||
self Emmiter // pre-defined emmiter than sends message to its self client
|
self Emitter // pre-defined emmiter than sends message to its self client
|
||||||
broadcast Emmiter // pre-defined emmiter that sends message to all except this
|
broadcast Emitter // pre-defined emmiter that sends message to all except this
|
||||||
all Emmiter // pre-defined emmiter which sends message to all clients
|
all Emitter // pre-defined emmiter which sends message to all clients
|
||||||
|
|
||||||
server *server
|
server *server
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,9 @@ func newConnection(websocketConn *websocket.Conn, s *server) *connection {
|
||||||
server: s,
|
server: s,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.self = newEmmiter(c, c.id)
|
c.self = newEmitter(c, c.id)
|
||||||
c.broadcast = newEmmiter(c, NotMe)
|
c.broadcast = newEmitter(c, NotMe)
|
||||||
c.all = newEmmiter(c, All)
|
c.all = newEmitter(c, All)
|
||||||
|
|
||||||
return c
|
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
|
if to == NotMe { // if send to all except me, then return the pre-defined emmiter, and so on
|
||||||
return c.broadcast
|
return c.broadcast
|
||||||
} else if to == All {
|
} else if to == All {
|
||||||
|
@ -260,7 +260,7 @@ func (c *connection) To(to string) Emmiter {
|
||||||
return c.self
|
return c.self
|
||||||
}
|
}
|
||||||
// is an emmiter to another client/connection
|
// is an emmiter to another client/connection
|
||||||
return newEmmiter(c, to)
|
return newEmitter(c, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *connection) EmitMessage(nativeMessage []byte) error {
|
func (c *connection) EmitMessage(nativeMessage []byte) error {
|
||||||
|
|
|
@ -1,44 +1,44 @@
|
||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
const (
|
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 = ""
|
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;"
|
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
|
Broadcast = NotMe
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Emmiter is the message/or/event manager
|
// Emitter is the message/or/event manager
|
||||||
Emmiter interface {
|
Emitter interface {
|
||||||
// EmitMessage sends a native websocket message
|
// EmitMessage sends a native websocket message
|
||||||
EmitMessage([]byte) error
|
EmitMessage([]byte) error
|
||||||
// Emit sends a message on a particular event
|
// Emit sends a message on a particular event
|
||||||
Emit(string, interface{}) error
|
Emit(string, interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
emmiter struct {
|
emitter struct {
|
||||||
conn *connection
|
conn *connection
|
||||||
to string
|
to string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Emmiter = &emmiter{}
|
var _ Emitter = &emitter{}
|
||||||
|
|
||||||
// emmiter implementation
|
// emitter implementation
|
||||||
|
|
||||||
func newEmmiter(c *connection, to string) *emmiter {
|
func newEmitter(c *connection, to string) *emitter {
|
||||||
return &emmiter{conn: c, to: to}
|
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}
|
mp := messagePayload{e.conn.id, e.to, nativeMessage}
|
||||||
e.conn.server.messages <- mp
|
e.conn.server.messages <- mp
|
||||||
return nil
|
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)
|
message, err := serialize(event, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
Loading…
Reference in New Issue
Block a user