mirror of
https://github.com/mochi-mqtt/server.git
synced 2025-10-30 03:01:58 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51d6825430 | ||
|
|
514288c53e | ||
|
|
957fc0a049 | ||
|
|
03f94f948a | ||
|
|
1bc752a2b8 | ||
|
|
b9db59ba12 | ||
|
|
c0ef58c363 |
@@ -124,6 +124,8 @@ server.Events.OnMessage = func(cl events.Client, pk events.Packet) (pkx events.P
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The OnMessage hook can also be used to selectively only deliver messages to one or more clients based on their id, using the `AllowClients []string` field on the packet structure.
|
||||||
|
|
||||||
A working example can be found in the `examples/events` folder. Please open an issue if there is a particular event hook you are interested in!
|
A working example can be found in the `examples/events` folder. Please open an issue if there is a particular event hook you are interested in!
|
||||||
|
|
||||||
#### Direct Publishing
|
#### Direct Publishing
|
||||||
|
|||||||
@@ -44,13 +44,10 @@ func (l *MockListener) Serve(establisher EstablishFunc) {
|
|||||||
l.Lock()
|
l.Lock()
|
||||||
l.Serving = true
|
l.Serving = true
|
||||||
l.Unlock()
|
l.Unlock()
|
||||||
for {
|
for range l.done {
|
||||||
select {
|
|
||||||
case <-l.done:
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// SetConfig sets the configuration values of the mock listener.
|
// SetConfig sets the configuration values of the mock listener.
|
||||||
func (l *MockListener) Listen(s *system.Info) error {
|
func (l *MockListener) Listen(s *system.Info) error {
|
||||||
|
|||||||
@@ -63,10 +63,12 @@ func (l *TCP) Listen(s *system.Info) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if l.config.TLS != nil && len(l.config.TLS.Certificate) > 0 && len(l.config.TLS.PrivateKey) > 0 {
|
if l.config.TLS != nil && len(l.config.TLS.Certificate) > 0 && len(l.config.TLS.PrivateKey) > 0 {
|
||||||
cert, err := tls.X509KeyPair(l.config.TLS.Certificate, l.config.TLS.PrivateKey)
|
var cert tls.Certificate
|
||||||
|
cert, err = tls.X509KeyPair(l.config.TLS.Certificate, l.config.TLS.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l.listen, err = tls.Listen(l.protocol, l.address, &tls.Config{
|
l.listen, err = tls.Listen(l.protocol, l.address, &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidMessage = errors.New("Message type not binary")
|
ErrInvalidMessage = errors.New("message type not binary")
|
||||||
|
|
||||||
// wsUpgrader is used to upgrade the incoming http/tcp connection to a
|
// wsUpgrader is used to upgrade the incoming http/tcp connection to a
|
||||||
// websocket compliant connection.
|
// websocket compliant connection.
|
||||||
wsUpgrader = &websocket.Upgrader{
|
wsUpgrader = &websocket.Upgrader{
|
||||||
Subprotocols: []string{"mqtt"},
|
Subprotocols: []string{"mqtt"},
|
||||||
|
CheckOrigin: func(r *http.Request) bool { return true },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user