Documentation
¶
Overview ¶
Package wire is the gRPC contract between the collector and the browser:
service agentscope.v1.Scope {
rpc Snapshot(Empty) returns (model.Snapshot); // unary
rpc Watch(Empty) returns (stream model.Snapshot); // server-streaming
}
The messages are the JSON form of model.Snapshot, carried by a gRPC codec named "json" that both ends force, so there is no protoc step and the schema is the Go type. The transport in the browser is a WebSocket (github.com/grpc-transports/websocket), whose js/wasm client is the same code as the native one: the wasm UI speaks the same gRPC a terminal client does.
Index ¶
Constants ¶
const MaxMessage = 16 << 20
MaxMessage bounds one message in either direction.
const (
ServiceName = "agentscope.v1.Scope"
)
Service and method names.
Variables ¶
var Codec encoding.CodecV2 = codec{}
Codec is the codec to force on a server or a client of this service.
Functions ¶
func DialOptions ¶
func DialOptions() []grpc.DialOption
DialOptions are the grpc.DialOption a client of this service needs, besides the transport.
func ServerOptions ¶
func ServerOptions() []grpc.ServerOption
ServerOptions are the grpc.ServerOption a server of this service needs.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client side of the service over a WebSocket. It compiles and runs the same natively and under GOOS=js GOARCH=wasm.
func Dial ¶
Dial connects to the service at wsURL (ws:// or wss://). The connection is lazy: the first call opens it.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub polls a Source and fans the snapshots out to every Watch stream. It collects once per interval however many browsers are watching, and sends a stream a snapshot only when something besides the clock changed, plus a keepalive so a quiet network still shows a moving "updated" time.
func NewHub ¶
NewHub returns a Hub that collects every `every` and republishes an unchanged snapshot after `keepalive`.
func (*Hub) Collect ¶
func (h *Hub) Collect()
Collect takes one snapshot and publishes it when it differs, or when the keepalive is due.
func (*Hub) Run ¶
Run collects until ctx ends. The first snapshot is taken before it returns from the first iteration, so a client that connects at once is served.