"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createRoom = createRoom;
var _jsSha = require("js-sha256");
var _createRoomPresence = require("./createRoomPresence.xmpp");
var _setMeAsOwner = require("./setMeAsOwner.xmpp");
var _roomConfig = require("./roomConfig.xmpp");
var _PLATFORM_CONSTANTS = require("../../helpers/constants/PLATFORM_CONSTANTS");
var _pushSubscriptionService = require("../../services/pushSubscriptionService");
async function createRoom(title, description, client) {
  const randomNumber = Math.round(Math.random() * 100_000);
  const chatNameWithSalt = title + Date.now() + randomNumber;
  const roomHash = (0, _jsSha.sha256)(chatNameWithSalt);
  const roomId = `${roomHash}${_PLATFORM_CONSTANTS.CONFERENCE_DOMAIN}`;
  try {
    await (0, _createRoomPresence.createRoomPresence)(roomId, client);
    await (0, _setMeAsOwner.setMeAsOwner)(roomId, client);
    await (0, _roomConfig.roomConfig)(roomId, title, description, client);
    const userNick = client.jid?.getLocal();
    await _pushSubscriptionService.pushSubscriptionService.subscribeToRoom(client, roomId, userNick).catch(error => {
      console.error('Failed to subscribe to new room for push:', error);
    });
  } catch (error) {
    console.log(error);
  }
  return roomId;
}
//# sourceMappingURL=createRoom.xmpp.js.map