Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function onDomainDiscovered (response) {
const text = await response.text();
const xrd = (new window.DOMParser()).parseFromString(text, "text/xml").firstElementChild;
if (xrd.nodeName != "XRD" || xrd.namespaceURI != "http://docs.oasis-open.org/ns/xri/xrd-1.0") {
return log.warn("Could not discover XEP-0156 connection methods");
}
const bosh_links = sizzle(`Link[rel="urn:xmpp:alt-connections:xbosh"]`, xrd);
const ws_links = sizzle(`Link[rel="urn:xmpp:alt-connections:websocket"]`, xrd);
const bosh_methods = bosh_links.map(el => el.getAttribute('href'));
const ws_methods = ws_links.map(el => el.getAttribute('href'));
// TODO: support multiple endpoints
_converse.websocket_url = ws_methods.pop();
_converse.bosh_service_url = bosh_methods.pop();
if (bosh_methods.length === 0 && ws_methods.length === 0) {
log.warn(
"onDomainDiscovered: neither BOSH nor WebSocket connection methods have been specified with XEP-0156."
);
}
}
xform.querySelectorAll('field').forEach(field => {
const _var = field.getAttribute('var');
if (_var) {
this.fields[_var.toLowerCase()] = _.get(field.querySelector('value'), 'textContent', '');
} else {
// TODO: other option seems to be type="fixed"
log.warn("Found field we couldn't parse");
}
});
this.form_type = 'xform';
async function onDomainDiscovered (response) {
const text = await response.text();
const xrd = (new window.DOMParser()).parseFromString(text, "text/xml").firstElementChild;
if (xrd.nodeName != "XRD" || xrd.namespaceURI != "http://docs.oasis-open.org/ns/xri/xrd-1.0") {
return log.warn("Could not discover XEP-0156 connection methods");
}
const bosh_links = sizzle(`Link[rel="urn:xmpp:alt-connections:xbosh"]`, xrd);
const ws_links = sizzle(`Link[rel="urn:xmpp:alt-connections:websocket"]`, xrd);
const bosh_methods = bosh_links.map(el => el.getAttribute('href'));
const ws_methods = ws_links.map(el => el.getAttribute('href'));
// TODO: support multiple endpoints
_converse.websocket_url = ws_methods.pop();
_converse.bosh_service_url = bosh_methods.pop();
if (bosh_methods.length === 0 && ws_methods.length === 0) {
log.warn(
"onDomainDiscovered: neither BOSH nor WebSocket connection methods have been specified with XEP-0156."
);
}
}
// since we don't have a way to distinguish between wether we're
// restoring a previous session (``keepalive``) or whether we're
// automatically setting up a new session (``auto_login``).
// So we can't do the check (!automatic || _converse.auto_login) here.
if (credentials) {
connect(credentials);
} else if (_converse.credentials_url) {
// We give credentials_url preference, because
// _converse.connection.pass might be an expired token.
connect(await getLoginCredentials());
} else if (_converse.jid && (_converse.password || _converse.connection.pass)) {
connect();
} else if (!_converse.isTestEnv() && window.PasswordCredential) {
connect(await getLoginCredentialsFromBrowser());
} else {
log.warn("attemptNonPreboundSession: Could not find any credentials to log in with");
}
} else if ([_converse.ANONYMOUS, _converse.EXTERNAL].includes(_converse.authentication) && (!automatic || _converse.auto_login)) {
connect();
}
}
async function enablePushAppServer (domain, push_app_server) {
if (!push_app_server.jid || !push_app_server.node) {
return;
}
const identity = await _converse.api.disco.getIdentity('pubsub', 'push', push_app_server.jid);
if (!identity) {
return log.warn(
`Not enabling push the service "${push_app_server.jid}", it doesn't have the right disco identtiy.`
);
}
const result = await Promise.all([
_converse.api.disco.supports(Strophe.NS.PUSH, push_app_server.jid),
_converse.api.disco.supports(Strophe.NS.PUSH, domain)
]);
if (!result[0] && !result[1]) {
log.warn(`Not enabling push app server "${push_app_server.jid}", no disco support from your server.`);
return;
}
const stanza = $iq({'type': 'set'});
if (domain !== _converse.bare_jid) {
stanza.attrs({'to': domain});
}
stanza.c('enable', {
'xmlns': Strophe.NS.PUSH,
'jid': push_app_server.jid,
'node': push_app_server.node
});
if (push_app_server.secret) {
stanza.c('x', {'xmlns': Strophe.NS.XFORM, 'type': 'submit'})
.c('field', {'var': 'FORM_TYPE'})
.c('value').t(`${Strophe.NS.PUBSUB}#publish-options`).up().up()
.c('field', {'var': 'secret'})
send (stanza) {
if (!_converse.api.connection.connected()) {
log.warn("Not sending stanza because we're not connected!");
log.warn(Strophe.serialize(stanza));
return;
}
if (_.isString(stanza)) {
stanza = u.toStanza(stanza);
}
if (stanza.tagName === 'iq') {
return _converse.api.sendIQ(stanza);
} else {
_converse.connection.send(stanza);
_converse.api.trigger('send', stanza);
}
},
getModerationAttributes (stanza, original_stanza, room) {
const fastening = sizzle(`apply-to[xmlns="${Strophe.NS.FASTEN}"]`, stanza).pop();
if (fastening) {
const applies_to_id = fastening.getAttribute('id');
const moderated = sizzle(`moderated[xmlns="${Strophe.NS.MODERATE}"]`, fastening).pop();
if (moderated) {
const retracted = sizzle(`retract[xmlns="${Strophe.NS.RETRACT}"]`, moderated).pop();
if (retracted) {
const from = stanza.getAttribute('from');
if (from !== room.get('jid')) {
log.warn("getModerationAttributes: ignore moderation stanza that's not from the MUC!");
log.error(original_stanza);
return {};
}
return {
'edtiable': false,
'moderated': 'retracted',
'moderated_by': moderated.getAttribute('by'),
'moderated_id': applies_to_id,
'moderation_reason': get(moderated.querySelector('reason'), 'textContent')
}
}
}
} else {
const tombstone = sizzle(`> moderated[xmlns="${Strophe.NS.MODERATE}"]`, stanza).pop();
if (tombstone) {
const retracted = sizzle(`retracted[xmlns="${Strophe.NS.RETRACT}"]`, tombstone).pop();