Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3298 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3298 Rev 3719
Línea 1... Línea 1...
1
import React, { useLayoutEffect } from 'react'
1
import React, { useLayoutEffect } from 'react';
2
import { useMatch } from 'react-router-dom'
2
import { useMatch } from 'react-router-dom';
3
import { useSelector } from 'react-redux'
3
import { useSelector } from 'react-redux';
4
 
4
 
5
import 'converse.js'
5
import 'converse.js';
6
import './converse.css'
6
import './converse.css';
7
import './chat.css'
7
import './chat.css';
8
 
8
 
9
export default function Chat() {
9
export default function Chat() {
10
  const match = useMatch('/habits/*')
10
  const match = useMatch('/habits/*');
11
 
11
 
12
  const {
12
  const {
13
    xmpp_hostname,
13
    xmpp_hostname,
14
    xmpp_username,
14
    xmpp_username,
15
    xmpp_password,
15
    xmpp_password,
16
    xmpp_domain
16
    xmpp_domain
17
    // xmpp_port
17
    // xmpp_port
18
  } = useSelector((state) => state.auth)
18
  } = useSelector((state) => state.auth);
19
 
19
 
20
  useLayoutEffect(() => {
20
  useLayoutEffect(() => {
21
    const converse = window.converse
21
    const converse = window.converse;
22
 
22
 
23
    if (
-
 
24
      !xmpp_hostname ||
-
 
25
      !xmpp_username ||
-
 
26
      !xmpp_password ||
23
    if (!xmpp_hostname || !xmpp_username || !xmpp_password || !xmpp_domain || match) {
27
      !xmpp_domain ||
-
 
28
      match
-
 
29
    ) {
-
 
30
      return
24
      return;
31
    }
25
    }
32
 
26
 
33
    if (match && converse.connection) {
27
    if (match && converse.connection) {
34
      converse.connection?.disconnect()
28
      converse.connection?.disconnect();
35
      return
29
      return;
36
    }
30
    }
37
 
31
 
38
    converse.initialize({
32
    converse.initialize({
39
      bosh_service_url: `https://${xmpp_hostname}:${17443}/http-bind/`,
33
      bosh_service_url: `https://${xmpp_hostname}:${17443}/http-bind/`,
40
      authentication: 'login',
34
      authentication: 'login',
41
      jid: `${xmpp_username}@${xmpp_domain}.com`,
35
      jid: `${xmpp_username}@${xmpp_domain}.com`,
42
      password: xmpp_password,
36
      password: xmpp_password,
43
      discover_connection_methods: false,
37
      discover_connection_methods: false,
44
      allow_adhoc_commands: false,
38
      allow_adhoc_commands: false,
45
      allow_registration: false,
39
      allow_registration: false,
46
      allow_logout: false,
40
      allow_logout: false,
47
      auto_login: true,
41
      auto_login: true,
48
      auto_reconnect: true,
42
      auto_reconnect: true,
49
      debug: true,
43
      debug: true,
50
      view_mode: 'overlayed',
44
      view_mode: 'overlayed',
51
      i18n: 'es',
45
      i18n: 'es',
52
      emojis: true,
46
      emojis: true,
53
      clear_cache_on_logout: true,
47
      clear_cache_on_logout: true,
54
      persistent_store: 'localStorage',
48
      persistent_store: 'localStorage',
55
      assets_path: '/public/'
49
      assets_path: '/'
56
    })
50
    });
57
 
51
 
58
    return () => {
52
    return () => {
59
      converse.connection?.disconnect()
53
      converse.connection?.disconnect();
60
    }
54
    };
61
  }, [xmpp_hostname, xmpp_password, xmpp_username, xmpp_domain, match])
55
  }, [xmpp_hostname, xmpp_password, xmpp_username, xmpp_domain, match]);
62
 
56
 
63
  return <div id='converse-container'></div>
57
  return <div id='converse-container'></div>;
64
}
58
}