Mercurial > xmpp-account-manager
comparison client.js @ 0:2a8d4e8600d0
Initial commit.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 21 Dec 2018 21:34:17 +0100 |
parents | |
children | d6df73b466f6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2a8d4e8600d0 |
---|---|
1 'use strict'; | |
2 | |
3 const BOSH_SERVICE = 'https://bosh.linkmauve.fr/'; | |
4 | |
5 function rawInput(data) | |
6 { | |
7 console.log('RECV', data); | |
8 } | |
9 | |
10 function rawOutput(data) | |
11 { | |
12 console.log('SENT', data); | |
13 } | |
14 | |
15 document.addEventListener('DOMContentLoaded', function () { | |
16 const connection = new Strophe.Connection(BOSH_SERVICE); | |
17 connection.rawInput = rawInput; | |
18 connection.rawOutput = rawOutput; | |
19 | |
20 const jid_element = document.getElementById('jid'); | |
21 const pass_element = document.getElementById('pass'); | |
22 const connect_button = document.getElementById('connect'); | |
23 | |
24 const connected_div = document.getElementById('connected'); | |
25 | |
26 const avatar_img = document.getElementById('avatar'); | |
27 | |
28 connect_button.addEventListener('click', function (evt) { | |
29 if (connect_button.value == 'connect') { | |
30 connection.connect(jid_element.value, | |
31 pass_element.value, | |
32 onConnect); | |
33 } else { | |
34 connection.disconnect(); | |
35 } | |
36 evt.preventDefault(); | |
37 }); | |
38 | |
39 function onConnect(status) | |
40 { | |
41 if (status == Strophe.Status.CONNECTING) { | |
42 console.log('Strophe is connecting.'); | |
43 connect_button.value = 'disconnect'; | |
44 jid_element.disabled = true; | |
45 pass_element.disabled = true; | |
46 } else if (status == Strophe.Status.CONNFAIL) { | |
47 console.log('Strophe failed to connect.'); | |
48 connect_button.value = 'connect'; | |
49 jid_element.disabled = false; | |
50 pass_element.disabled = false; | |
51 } else if (status == Strophe.Status.DISCONNECTING) { | |
52 console.log('Strophe is disconnecting.'); | |
53 } else if (status == Strophe.Status.DISCONNECTED) { | |
54 console.log('Strophe is disconnected.'); | |
55 connect_button.value = 'connect'; | |
56 jid_element.disabled = false; | |
57 pass_element.disabled = false; | |
58 } else if (status == Strophe.Status.CONNECTED) { | |
59 console.log('Strophe is connected.'); | |
60 onConnected(); | |
61 } | |
62 } | |
63 | |
64 function onConnected() | |
65 { | |
66 connected_div.hidden = false; | |
67 initNickname(connection); | |
68 initAvatar(connection); | |
69 } | |
70 }); |