"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BroadbandSubscriber = void 0;
/**
 * A class that subscribes to all partitions of a Streamr stream.
 */
class BroadbandSubscriber {
    constructor(client, stream) {
        this.client = client;
        this.stream = stream;
        this.subscriptions = [];
        this.partitions = this.stream.getMetadata().partitions;
    }
    async subscribe(onMessage) {
        const promises = [];
        for (let partition = 0; partition < this.partitions; partition++) {
            promises.push(this.client.subscribe({ id: this.stream.id, partition }, onMessage));
        }
        this.subscriptions.push(...(await Promise.all(promises)));
    }
    async unsubscribe() {
        await Promise.all(this.subscriptions.map((subscription) => subscription.unsubscribe()));
        this.subscriptions.splice(0);
    }
}
exports.BroadbandSubscriber = BroadbandSubscriber;
//# sourceMappingURL=BroadbandSubscriber.js.map