package main

import (
	"bufio"
	"fmt"
	"io"

	socketio "github.com/googollee/go-socket.io"
)

// streamOutput reads io.Reader line by line and broadcasts
func streamOutput(r io.Reader, server *socketio.Server, room string) {
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		line := scanner.Text()
		server.BroadcastToRoom("/", room, "buildlogs", line)
	}
	if err := scanner.Err(); err != nil {
		server.BroadcastToRoom("/", room, "buildlogs", fmt.Sprintf("❌ Log stream error: %v", err))
	}
}
