demo live stream
This commit is contained in:
@@ -154,13 +154,26 @@ func (ingest *Ingest) SubscribeLive(ctx context.Context, streamId string) (<-cha
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to subscribe to live stream %s: %w", streamId, err)
|
||||
}
|
||||
defer active.pipeline.LiveUnsubscribe(id)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, nil
|
||||
case buf := <-stream:
|
||||
ingest.log.Debug("Received live stream chunk", "streamId", streamId, "chunkSize", buf.Len())
|
||||
out := make(chan *bytes.Reader, 16)
|
||||
go func() {
|
||||
defer close(out)
|
||||
defer active.pipeline.LiveUnsubscribe(id)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case buf, ok := <-stream:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case out <- buf:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user