- Add socket handler and server implementations for real-time communication - Add Mattermost integration (auth service, push client, plugin client) - Add Mattermost push host integration tests - Update Flutter client app with new app structure and bootstrap - Update Android build configurations and add Google Services config - Add asset keep file for Flutter client - Update agent-roadmap with api-centered-proto-socket-rail milestone - Update agent-task with planning and code review documents for all groups - Update domain rules for api, client, worker and project rules
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package socket
|
|
|
|
import (
|
|
protoSocket "git.toki-labs.com/toki/proto-socket/go"
|
|
|
|
altv1 "git.toki-labs.com/toki/alt/packages/contracts/gen/go/alt/v1"
|
|
)
|
|
|
|
// sessionHandler is one request-response unit attached to a freshly connected
|
|
// client communicator. Splitting registration into independent units keeps the
|
|
// api hub control-plane surface thin: later command/query handlers attach
|
|
// through the same registry instead of growing a single registration function.
|
|
type sessionHandler struct {
|
|
// requestType is the ALT protobuf request type name the handler answers.
|
|
// It lets the registry detect duplicate or missing handler coverage without
|
|
// a live socket connection.
|
|
requestType string
|
|
// register attaches the handler onto the client communicator.
|
|
register func(*protoSocket.WsClient)
|
|
}
|
|
|
|
// sessionHandlers returns the ordered set of handlers registered on every API
|
|
// client session. Hello is registered through this registry so its behaviour
|
|
// stays identical while gaining the shared registration path.
|
|
func sessionHandlers() []sessionHandler {
|
|
return []sessionHandler{
|
|
helloHandler(),
|
|
}
|
|
}
|
|
|
|
// registerSessionHandlers wires every session handler onto a newly connected
|
|
// client. nil registrars are skipped so a malformed registry entry cannot
|
|
// panic the connection setup path.
|
|
func registerSessionHandlers(client *protoSocket.WsClient) {
|
|
for _, handler := range sessionHandlers() {
|
|
if handler.register == nil {
|
|
continue
|
|
}
|
|
handler.register(client)
|
|
}
|
|
}
|
|
|
|
func helloHandler() sessionHandler {
|
|
return sessionHandler{
|
|
requestType: protoSocket.TypeNameOf(&altv1.HelloRequest{}),
|
|
register: func(client *protoSocket.WsClient) {
|
|
protoSocket.AddRequestListenerTyped[*altv1.HelloRequest, *altv1.HelloResponse](&client.Communicator, handleHello)
|
|
},
|
|
}
|
|
}
|
|
|
|
func handleHello(req *altv1.HelloRequest) (*altv1.HelloResponse, error) {
|
|
protocolVersion := req.GetAltProtocolVersion()
|
|
if protocolVersion == "" {
|
|
protocolVersion = defaultAltProtocolVersion
|
|
}
|
|
return &altv1.HelloResponse{
|
|
ServerName: serverName,
|
|
ServerVersion: serverVersion,
|
|
AltProtocolVersion: protocolVersion,
|
|
Capabilities: []string{
|
|
"hello",
|
|
"request-response",
|
|
},
|
|
}, nil
|
|
}
|