فهرست منبع

Don't make `bosh_service_url` and `websocket_url` mandatory

Instead, show an input to the user to manually add a service URL if none
can be found.
JC Brand 4 ماه پیش
والد
کامیت
120a646720

+ 0 - 3
docs/source/configuration.rst

@@ -795,9 +795,6 @@ Use `XEP-0156 <https://xmpp.org/extensions/xep-0156.html>`_ to discover whether
 the XMPP host for the current user advertises any Websocket or BOSH connection
 URLs that can be used.
 
-If this is set to ``false``, then a `websocket_url`_ or `bosh_service_url`_ need to be
-set.
-
 Currently only the XML encoded host-meta resource is supported as shown in
 `Example 2 under section 3.3 <https://xmpp.org/extensions/xep-0156.html#httpexamples>`_.
 

+ 1 - 1
local.html

@@ -38,7 +38,7 @@
             message_archiving: 'always',
             // muc_domain: 'conference.chat.example.org',
             view_mode: 'fullscreen',
-            websocket_url: 'ws://chat.example.org:5380/xmpp-websocket',
+            // websocket_url: 'ws://chat.example.org:5380/xmpp-websocket',
             // websocket_url: 'wss://chat.example.org:5381/xmpp-websocket',
             // websocket_url: 'wss://conversejs.org/xmpp-websocket',
             // bosh_service_url: 'http://chat.example.org:5280/http-bind',

+ 6 - 4
src/headless/shared/connection/index.js

@@ -56,14 +56,14 @@ export class Connection extends Strophe.Connection {
         const text = await response.text();
         const xrd = (new 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");
+            return log.info("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')).filter(uri => uri.startsWith('https:'));
         const ws_methods = ws_links.map(el => el.getAttribute('href')).filter(uri => uri.startsWith('wss:'));
         if (bosh_methods.length === 0 && ws_methods.length === 0) {
-            log.warn("Neither BOSH nor WebSocket connection methods have been specified with XEP-0156.");
+            log.info("Neither BOSH nor WebSocket connection methods have been specified with XEP-0156.");
         } else {
             // TODO: support multiple endpoints
             api.settings.set("websocket_url", ws_methods.pop());
@@ -101,7 +101,7 @@ export class Connection extends Strophe.Connection {
         if (response.status >= 200 && response.status < 400) {
             await this.onDomainDiscovered(response);
         } else {
-            log.warn("Could not discover XEP-0156 connection methods");
+            log.info("Could not discover XEP-0156 connection methods");
         }
     }
 
@@ -121,7 +121,9 @@ export class Connection extends Strophe.Connection {
             await this.discoverConnectionMethods(domain);
         }
         if (!api.settings.get('bosh_service_url') && !api.settings.get("websocket_url")) {
-            throw new Error("You must supply a value for either the bosh_service_url or websocket_url or both.");
+            // If we don't have a connection URL, we show an input for the user
+            // to manually provide it.
+            api.settings.set('show_connection_url_input', true);
         }
         super.connect(jid, password, callback || this.onConnectStatusChanged, BOSH_WAIT);
     }

+ 2 - 0
src/plugins/controlbox/loginform.js

@@ -13,6 +13,8 @@ const { ANONYMOUS } = constants;
 class LoginForm extends CustomElement {
 
     initialize () {
+        const settings = api.settings.get();
+        this.listenTo(settings, 'change:show_connection_url_input', () => this.requestUpdate());
         this.listenTo(_converse.state.connfeedback, 'change', () => this.requestUpdate());
         this.handler = () => this.requestUpdate()
     }

+ 1 - 1
src/plugins/controlbox/styles/loginform.scss

@@ -82,7 +82,7 @@
                         @include make-col(6);
                     }
                     .title, .instructions {
-                        margin: 1em 0;
+                        margin: 0.5em 0;
                     }
                     input[type=submit],
                     input[type=button] {

+ 19 - 17
src/plugins/controlbox/templates/loginform.js

@@ -16,7 +16,7 @@ const trust_checkbox = (checked) => {
     );
     const i18n_trusted = __('This is a trusted device');
     return html`
-        <div class="form-group form-check login-trusted">
+        <div class="form-check login-trusted">
             <input
                 id="converse-login-trusted"
                 type="checkbox"
@@ -40,7 +40,7 @@ const connection_url_input = () => {
     const i18n_form_help = __('HTTP or websocket URL that is used to connect to your XMPP server');
     const i18n_placeholder = __('e.g. wss://example.org/xmpp-websocket');
     return html`
-        <div class="form-group fade-in">
+        <div class="mb-3 fade-in">
             <label for="converse-conn-url" class="form-label">${i18n_connection_url}</label>
             <p class="form-help instructions">${i18n_form_help}</p>
             <input
@@ -57,7 +57,7 @@ const connection_url_input = () => {
 const password_input = () => {
     const i18n_password = __('Password');
     return html`
-        <div>
+        <div class="mb-3">
             <label for="converse-login-password" class="form-label">${i18n_password}</label>
             <input
                 id="converse-login-password"
@@ -104,22 +104,24 @@ const auth_fields = (el) => {
 
     return html`
         <fieldset class="form-group">
+            <div class="mb-3">
             <label for="converse-login-jid" class="form-label">${i18n_xmpp_address}:</label>
-            <input
-                id="converse-login-jid"
-                ?autofocus=${api.settings.get('auto_focus') ? true : false}
-                @changed=${el.validate}
-                value="${api.settings.get('jid') ?? ''}"
-                required
-                class="form-control"
-                type="text"
-                name="jid"
-                placeholder="${placeholder_username}"
-            />
+                <input
+                    id="converse-login-jid"
+                    ?autofocus=${api.settings.get('auto_focus') ? true : false}
+                    @changed=${el.validate}
+                    value="${api.settings.get('jid') ?? ''}"
+                    required
+                    class="form-control"
+                    type="text"
+                    name="jid"
+                    placeholder="${placeholder_username}"
+                />
+            </div>
+            ${authentication !== EXTERNAL ? password_input() : ''}
+            ${api.settings.get('show_connection_url_input') ? connection_url_input() : ''}
+            ${show_trust_checkbox ? trust_checkbox(show_trust_checkbox === 'off' ? false : true) : ''}
         </fieldset>
-        ${authentication !== EXTERNAL ? password_input() : ''}
-        ${api.settings.get('show_connection_url_input') ? connection_url_input() : ''}
-        ${show_trust_checkbox ? trust_checkbox(show_trust_checkbox === 'off' ? false : true) : ''}
         <fieldset class="form-group buttons">
             <input class="btn btn-primary" type="submit" value="${i18n_login}" />
         </fieldset>