"use strict";

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