annotate client.js @ 63:ee1df80a1715 default tip

Nicer-looking input form
author mathieui
date Sun, 24 May 2020 14:19:29 +0200
parents 6d861d881b96
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
1 // SPDX-License-Identifier: AGPL-3.0-only
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
2 /*
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
3 * Copyright © 2018-2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
4 * Copyright © 2020 Mathieu Pasquet <mathieui@mathieui.net>
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
5 *
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
6 * Released under GNU AGPL v3 only, read the file 'LICENSE' for more information.
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
7 */
6d861d881b96 Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 57
diff changeset
8
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 'use strict';
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 document.addEventListener('DOMContentLoaded', function () {
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
12 let connection = null;
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 const jid_element = document.getElementById('jid');
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 const pass_element = document.getElementById('pass');
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 const connect_button = document.getElementById('connect');
10
e47b9bd55192 Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
17 const spinner_img = document.getElementById('connect-spinner');
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 const connected_div = document.getElementById('connected');
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 const avatar_img = document.getElementById('avatar');
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
23
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
23 const tabs = ['profile', 'mam', 'pep', 'account'];
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
24 function onHashChange() {
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
25 const hash = location.hash.substr(1);
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
26 if (!tabs.includes(hash))
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
27 return;
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
28 for (let tab of tabs) {
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
29 const tab_name = 'tab-' + tab;
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
30 const tab_element = document.getElementById(tab_name);
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
31 if (tab == hash) {
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
32 tab_element.classList.add('active')
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
33 const content_elements = document.getElementsByClassName(tab_name);
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
34 for (let element of content_elements)
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
35 element.hidden = false;
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
36 } else {
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
37 tab_element.classList.remove('active')
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
38 const content_elements = document.getElementsByClassName(tab_name);
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
39 for (let element of content_elements)
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
40 element.hidden = true;
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
41 }
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
42 }
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
43 }
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
44
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
45 onHashChange();
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
46 window.addEventListener('hashchange', onHashChange);
e99984564b17 Implement a tab system, thanks Zash!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
47
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
48 function rawInput(data)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
49 {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
50 console.log('RECV', data);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
51 }
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
52
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
53 function rawOutput(data)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
54 {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
55 console.log('SENT', data);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
56 }
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
57
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 connect_button.addEventListener('click', function (evt) {
13
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
59 if (!connect_button.classList.contains('disconnect')) {
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
60 const jid = jid_element.value;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
61 getBOSHService(jid).then((bosh_service) => {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
62 connection = new Strophe.Connection(bosh_service);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
63 connection.rawInput = rawInput;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
64 connection.rawOutput = rawOutput;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
65 connection.connect(jid,
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
66 pass_element.value,
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
67 onConnect);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
68 });
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
69 } else if (connection != null) {
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 connection.disconnect();
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 }
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 evt.preventDefault();
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 });
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
75 function getBOSHService(jid)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
76 {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
77 return new Promise((resolve, reject) => {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
78 const [nodepart, domainpart] = jid.split('@', 2);
14
962f64b156dd Stop hardcoding XEP-0156 file to the current domain.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
79 const url = 'https://' + domainpart + '/.well-known/host-meta';
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
80 const xhr = new XMLHttpRequest();
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
81 xhr.onload = function (evt) {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
82 const xml = evt.target.responseXML;
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
83 const links = parseXPath(xml, './xrd:XRD/xrd:Link', XPathResult.ORDERED_NODE_ITERATOR_TYPE);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
84 let bosh_service = null;
45
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
85 let ws_service = null;
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
86 while (true) {
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
87 const link = links.iterateNext();
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
88 if (!link)
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
89 break;
45
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
90 const rel = link.getAttributeNS(null, 'rel');
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
91 if (rel == 'urn:xmpp:alt-connections:xbosh')
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
92 bosh_service = link.getAttributeNS(null, 'href');
45
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
93 else if (rel == 'urn:xmpp:alt-connections:websocket')
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
94 ws_service = link.getAttributeNS(null, 'href');
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
95 }
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
96 console.log('bosh_service', bosh_service);
45
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
97 console.log('ws_service', ws_service);
8b69b3a1ef8e Add support for WebSocket.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 42
diff changeset
98 resolve(ws_service || bosh_service);
1
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
99 };
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
100 xhr.open('GET', url);
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
101 xhr.send();
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
102 });
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
103 }
d6df73b466f6 Implement XEP-0156 to discover the right BOSH endpoint.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
104
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 function onConnect(status)
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 {
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 if (status == Strophe.Status.CONNECTING) {
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 console.log('Strophe is connecting.');
57
427807059ca8 Use `` in JS for templating, and add two forgotten strings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
109 connect_button.value = `{% trans 'Log out' %}`;
13
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
110 connect_button.classList.add('disconnect');
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 jid_element.disabled = true;
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 pass_element.disabled = true;
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 14
diff changeset
113 displaySpinner(spinner_img);
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 } else if (status == Strophe.Status.CONNFAIL) {
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 console.log('Strophe failed to connect.');
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
116 onDisconnected();
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 } else if (status == Strophe.Status.DISCONNECTING) {
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 console.log('Strophe is disconnecting.');
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 14
diff changeset
119 displaySpinner(spinner_img);
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 } else if (status == Strophe.Status.DISCONNECTED) {
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 console.log('Strophe is disconnected.');
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
122 onDisconnected();
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 } else if (status == Strophe.Status.CONNECTED) {
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 console.log('Strophe is connected.');
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 onConnected();
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 }
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 }
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 function onConnected()
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 {
63
ee1df80a1715 Nicer-looking input form
mathieui
parents: 60
diff changeset
131 const connection_form = document.getElementById('connection');
ee1df80a1715 Nicer-looking input form
mathieui
parents: 60
diff changeset
132 connection_form.classList.remove('initial-login');
42
fe59565063af mathieui: Add our current JID in the top bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 40
diff changeset
133 const new_node = document.createElementNS('http://www.w3.org/1999/xhtml', 'span');
fe59565063af mathieui: Add our current JID in the top bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 40
diff changeset
134 const parent_node = connect.parentNode;
57
427807059ca8 Use `` in JS for templating, and add two forgotten strings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
135 const text = document.createTextNode(`{% trans 'Logged in as ${connection.authzid} ' %}`);
42
fe59565063af mathieui: Add our current JID in the top bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 40
diff changeset
136 new_node.appendChild(text);
fe59565063af mathieui: Add our current JID in the top bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 40
diff changeset
137 parent_node.insertBefore(new_node, connect);
fe59565063af mathieui: Add our current JID in the top bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 40
diff changeset
138
13
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
139 jid_element.hidden = true;
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
140 pass_element.hidden = true;
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 connected_div.hidden = false;
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 14
diff changeset
142 hideSpinner(spinner_img);
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
143 initRoster(connection);
3
5aa1bf7154b0 Add a simple PEP node viewer and editor.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
144 initPEP(connection);
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 initNickname(connection);
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 initAvatar(connection);
25
d9da5c3e305d Add support for setting some vCard4 fields.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 23
diff changeset
147 initVCard(connection);
17
07543f7f5e89 Retrieve and change the default MAM prefs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 15
diff changeset
148 initMAM(connection);
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 }
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
150
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
151 function onDisconnected()
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
152 {
57
427807059ca8 Use `` in JS for templating, and add two forgotten strings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
153 connect_button.value = `{% trans 'Log in' %}`;
13
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
154 connect_button.classList.remove('disconnect');
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
155 jid_element.hidden = false;
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
156 jid_element.disabled = false;
13
8724e28ccbd7 Improve styling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
157 pass_element.hidden = false;
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
158 pass_element.disabled = false;
15
3eed9fe0bd7c End spinners with either a green ✔ or a red ✘.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 14
diff changeset
159 hideSpinner(spinner_img);
12
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
160 connected_div.hidden = true;
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
161 let table = document.getElementById('roster-table');
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
162 while (table.hasChildNodes()) {
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
163 table.removeChild(table.lastChild);
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
164 }
12
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
165 table = document.getElementById('pep-table');
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
166 while (table.hasChildNodes()) {
139b223dafb0 Actually remove all of the extra data on disconnect.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
167 table.removeChild(table.lastChild);
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
168 }
40
bd343ef0942f mathieui: Reload the page on logout.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 25
diff changeset
169 location.reload();
4
5e97e1808a35 Add support for the roster.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
170 }
0
2a8d4e8600d0 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 });