Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3298 | | Comparar con el anterior | Ultima modificación | Ver Log |

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