Live video on the AT Protocol
1package iroh
2
3import (
4 "context"
5
6 "stream.place/streamplace/pkg/log"
7
8 irohStreamplace "stream.place/streamplace/pkg/iroh/generated/iroh_streamplace"
9)
10
11// IrohReplicator implements the replication mechanism using iroh
12type IrohReplicator struct {
13 topic string
14 sender *irohStreamplace.Sender
15}
16
17func NewIrohReplicator(ctx context.Context, ep *irohStreamplace.Endpoint, topic string) (*IrohReplicator, error) {
18 sender, err := irohStreamplace.NewSender(ep)
19 if err.AsError() != nil {
20 return nil, err.AsError()
21 }
22
23 return &IrohReplicator{
24 topic: topic,
25 sender: sender,
26 }, nil
27}
28
29func (rep *IrohReplicator) NewSegment(ctx context.Context, bs []byte) {
30 go func(topic string) {
31 err := sendSegment(rep.sender, topic, bs)
32 if err != nil {
33 log.Log(ctx, "error replicating segment", "error", err)
34 }
35 }(rep.topic)
36}
37
38func sendSegment(endpoint *irohStreamplace.Sender, topic string, bs []byte) error {
39 return endpoint.Send(topic, bs).AsError()
40}