export class StudioSseHub {
    subscribers = new Set();
    subscribe(subscriber) {
        this.subscribers.add(subscriber);
        return () => {
            this.subscribers.delete(subscriber);
        };
    }
    broadcastToUser(userId, event, data) {
        for (const subscriber of this.subscribers) {
            if (subscriber.userId === userId)
                subscriber.send(event, data);
        }
    }
    broadcastToAdmins(event, data, options) {
        for (const subscriber of this.subscribers) {
            if (options?.excludeUserId && subscriber.userId === options.excludeUserId)
                continue;
            if (subscriber.isAdmin)
                subscriber.send(event, data);
        }
    }
    broadcastPublic(event, data) {
        for (const subscriber of this.subscribers) {
            subscriber.send(event, data);
        }
    }
    broadcastForJob(job, event, data) {
        this.broadcastToUser(job.userId, event, data);
        this.broadcastToAdmins(event, data, { excludeUserId: job.userId });
    }
}
//# sourceMappingURL=sse.js.map