import { Awareness } from "y-protocols/awareness";
import { DocAdapter } from "./doc-adapter.js";
export class Room {
    constructor(roomName, doc, options, peerFactory) {
        var _a;
        this.roomName = roomName;
        this.doc = doc;
        this.options = options;
        this.peerFactory = peerFactory;
        this.users = new Map();
        this.docAdapter = new DocAdapter(this.doc, (_a = this.options.awareness) !== null && _a !== void 0 ? _a : new Awareness(this.doc));
    }
    getRegistrationInfo() {
        return {
            room: this.roomName,
            token: this.options.token
        };
    }
    async connect() {
    }
    async disconnect() {
    }
    async addUsers(users) {
        for (let user of users) {
            this.users.set(user.user, user);
            if (user.user > this.options.user)
                this.setConnection(user);
        }
    }
    async setConnection(user) {
        const connection = await this.peerFactory.getConnection(user, this.roomName, this.options.user);
        this.docAdapter.connect(connection);
        return connection;
    }
    addConnection(connection) {
        this.docAdapter.connect(connection);
        return connection;
    }
}
//# sourceMappingURL=room.js.map