2018-08-14 03:05:30 +03:00
|
|
|
package endpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-10-30 20:17:59 +03:00
|
|
|
const localExpiresAfter = time.Second * 30
|
2018-08-14 03:05:30 +03:00
|
|
|
|
|
|
|
// LocalPublisher is used to publish local notifcations
|
|
|
|
type LocalPublisher interface {
|
|
|
|
Publish(channel string, message ...string) int
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocalConn is an endpoint connection
|
|
|
|
type LocalConn struct {
|
|
|
|
ep Endpoint
|
|
|
|
publisher LocalPublisher
|
|
|
|
}
|
|
|
|
|
|
|
|
func newLocalConn(ep Endpoint, publisher LocalPublisher) *LocalConn {
|
|
|
|
return &LocalConn{
|
|
|
|
ep: ep,
|
|
|
|
publisher: publisher,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expired returns true if the connection has expired
|
|
|
|
func (conn *LocalConn) Expired() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send sends a message
|
|
|
|
func (conn *LocalConn) Send(msg string) error {
|
|
|
|
conn.publisher.Publish(conn.ep.Local.Channel, msg)
|
|
|
|
return nil
|
|
|
|
}
|