"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.roomConfig = roomConfig;
var _client = require("@xmpp/client");
var _createTimeoutPromise = require("./createTimeoutPromise.xmpp");
function roomConfig(roomId, roomTitle, roomDescription, client) {
  const id = `room-config:${Date.now().toString()}`;
  let stanzaHdlrPointer;
  const unsubscribe = () => {
    client.off('stanza', stanzaHdlrPointer);
  };
  const responsePromise = new Promise(resolve => {
    stanzaHdlrPointer = stanza => {
      if (stanza.attrs.id === id && stanza.attrs.type === 'result') {
        unsubscribe();
        resolve(true);
      }
    };
    client.on('stanza', stanzaHdlrPointer);
    const message = (0, _client.xml)('iq', {
      id: id,
      to: roomId,
      type: 'set'
    }, (0, _client.xml)('query', {
      xmlns: 'http://jabber.org/protocol/muc#owner'
    }, (0, _client.xml)('x', {
      xmlns: 'jabber:x:data',
      type: 'submit'
    }, (0, _client.xml)('field', {
      var: 'FORM_TYPE'
    }, (0, _client.xml)('value', {}, 'http://jabber.org/protocol/muc#roomconfig')), (0, _client.xml)('field', {
      var: 'muc#roomconfig_roomname'
    }, (0, _client.xml)('value', {}, roomTitle)), (0, _client.xml)('field', {
      var: 'muc#roomconfig_roomdesc'
    }, (0, _client.xml)('value', {}, roomDescription)))));
    client.send(message);
  });
  const timeoutPromise = (0, _createTimeoutPromise.createTimeoutPromise)(2000, unsubscribe);
  return Promise.race([responsePromise, timeoutPromise]);
}
//# sourceMappingURL=roomConfig.xmpp.js.map