2021-02-09 11:53:33 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-02-01 15:45:30 +00:00
|
|
|
package server
|
2021-01-25 17:31:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
kitlog "github.com/go-kit/kit/log"
|
|
|
|
"go.cryptoscope.co/muxrpc/v2"
|
|
|
|
"go.cryptoscope.co/muxrpc/v2/typemux"
|
|
|
|
|
2021-02-10 14:50:36 +00:00
|
|
|
"github.com/ssb-ngi-pointer/go-ssb-room/roomstate"
|
|
|
|
refs "go.mindeco.de/ssb-refs"
|
2021-01-25 17:31:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/* manifest:
|
|
|
|
{
|
|
|
|
"announce": "sync",
|
|
|
|
"leave": "sync",
|
|
|
|
"connect": "duplex",
|
|
|
|
"endpoints": "source",
|
|
|
|
"isRoom": "async",
|
|
|
|
"ping": "sync",
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
func New(log kitlog.Logger, self refs.FeedRef, m *roomstate.Manager) *Handler {
|
|
|
|
var h = new(Handler)
|
2021-02-10 14:50:36 +00:00
|
|
|
h.self = self
|
|
|
|
h.logger = log
|
|
|
|
h.state = m
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
return h
|
|
|
|
}
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
func (h *Handler) Register(mux typemux.HandlerMux, namespace muxrpc.Method) {
|
|
|
|
mux.RegisterAsync(append(namespace, "isRoom"), typemux.AsyncFunc(h.isRoom))
|
|
|
|
mux.RegisterAsync(append(namespace, "ping"), typemux.AsyncFunc(h.ping))
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterAsync(append(namespace, "announce"), typemux.AsyncFunc(h.announce))
|
|
|
|
mux.RegisterAsync(append(namespace, "leave"), typemux.AsyncFunc(h.leave))
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterSource(append(namespace, "endpoints"), typemux.SourceFunc(h.endpoints))
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterDuplex(append(namespace, "connect"), typemux.DuplexFunc(h.connect))
|
2021-01-25 17:31:09 +00:00
|
|
|
}
|