<commit_before>/*!
 * Copyright (C) 2000-2017 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of
 * the GPL, you may redistribute this Program in connection with Writer Free/Libre
 * Open Source Software ("FLOSS") applications as described in Silverpeas's
 * FLOSS exception.  You should have recieved a copy of the text describing
 * the FLOSS exception, and it is also available here:
 * "http://www.silverpeas.org/legal/licensing"
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The chat client for Silverpeas.
 * It is based upon JSXC (https://www.jsxc.org/)
 */

var SilverChat = null;

(function($) {
  "use strict";

  if (top.window.SilverChat) {
    if (!window.SilverChat) {
      window.SilverChat = top.window.SilverChat;
    }
    return;
  }

  if (typeof jsxc === 'undefined' || typeof Strophe === 'undefined') {
    throw new Error('SilverChat dependencies not defined: jsxc and Strophe');
  }

  if (window.webContext === null) {
    window.webContext = '.';
  }
  var chatPath = window.webContext + '/chat';

  /**
   * The chat client of Silverpeas.
   * @type {object}
   */
  SilverChat = {

    /**
     * The settings of the chat client. They define the parameters to communicate with the chat
     * server and to parameterize the UI. The settings can be overridden when initializing the chat
     * client.
     */
    settings : {
      /**
       * The URL of the XMPP's BOSH service with which SilverChat communicates.
       * @type {string}
       */
      url : 'http://im.silverpeas.net:5280/http-bind/',

      /**
       * The definition of an ICE service to enable the video chat capability. It is defined by the
       * following object:
       * {
       *   server: {string}    the hostname or IP address of a ICE server with its port number.
       *                       (for example ice.silverpeas.net:80)
       *   auth: {boolean}     is an authentication must be performed to access the STUN service?
       *   user: {string}      the user identifier used to authenticate the client to the STUN
       *                       service. If missing and auth is true, then the current user
       *                       identifier is used. Optional.
       *   password: {string}  the password associated with the user identifier to authenticate the
       *                       the client to the STUN service. If user is set, this attribute is
       *                       mandatory. Optional.
       * }
       * If no such service is defined, then the video chat capability is disabled.
       */
      ice : null,

      /**
       * The user login to open a connection with the XMPP server.
       * @type {string}
       */
      id : '',

      /**
       * The user password to open a connection with the XMPP server.
       * @type {string}
       */
      password : '',

      /**
       * The XMPP domain (or Jabber domain) in which the user is.
       * @type {string}
       */
      domain : 'im.silverpeas.net',

      /**
       * The ISO 639-1 code of the language to use in the GUI localization. By default, in English.
       * @type {string}
       */
      language : '',

      /**
       * The path of the installation directory of SilverChat. By default, in the chat directory
       * relative to the web context (the web context is assumed to be defined in the webContext
       * variable).
       * @type {string}
       */
      path : chatPath,

      /**
       * The path of the directory containing the avatars of the user and of its buddies.
       * The path can be provided by a function that has to accept as argument the JID (Jabber
       * IDentifier) of the user for which the avatar is asked.
       * @type {string|function}
       */
      avatar : null,

      /**
       * A function to provide a custom and an external way to select a user with whom the current
       * user wish to chat. The selected user will be then added into the current user's roster
       * but no presence subscription will be performed.
       *
       * The function must accept as argument a callback to call with as parameters the JID of the
       * selected user and optionally the name (or alias) of the selected user.
       * If no function is set, then the user selection menu item is removed.
       * @type {function}
       */
      selectUser: null,

      /**
       * Switches SilverChat logs in the debug level for displaying debugging messages in the
       * Javascript console of the web browser. By default, false.
       * @type {boolean}
       */
      debug: false
    },

    /**
     * Initializes the silverpeas chat client. It bootstraps JSXC and its own customization of
     * JSXC.
     * @param options the options to override the default settings.
     * @return {SilverChat}
     */
    init : function(options) {
      this.settings = $.extend(true, this.settings, options);
      this.settings.path += '/jsxc';

      window.top.addEventListener("beforeunload", function() {
        jsxc.gui.changePresence('offline', true);
        setTimeout(function() {
          jsxc.xmpp.logout(true);

          // here we call directly this method to be sure it have time to execute
          jsxc.xmpp.disconnected();

          jsxc.error("Disconnected before leaving page");
        }, 0);

      }, false);

      jsxc.storage.setItem("debug", this.settings.debug);
<commit_msg>Automatic disconnection when the browser window is closed is now performed only if this window is the master (that is to say from which the chat client was initialized)<commit_after>/*!
 * Copyright (C) 2000-2017 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of
 * the GPL, you may redistribute this Program in connection with Writer Free/Libre
 * Open Source Software ("FLOSS") applications as described in Silverpeas's
 * FLOSS exception.  You should have recieved a copy of the text describing
 * the FLOSS exception, and it is also available here:
 * "http://www.silverpeas.org/legal/licensing"
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The chat client for Silverpeas.
 * It is based upon JSXC (https://www.jsxc.org/)
 */

var SilverChat = null;

(function($) {
  "use strict";

  if (top.window.SilverChat) {
    if (!window.SilverChat) {
      window.SilverChat = top.window.SilverChat;
    }
    return;
  }

  if (typeof jsxc === 'undefined' || typeof Strophe === 'undefined') {
    throw new Error('SilverChat dependencies not defined: jsxc and Strophe');
  }

  if (window.webContext === null) {
    window.webContext = '.';
  }
  var chatPath = window.webContext + '/chat';

  /**
   * The chat client of Silverpeas.
   * @type {object}
   */
  SilverChat = {

    /**
     * The settings of the chat client. They define the parameters to communicate with the chat
     * server and to parameterize the UI. The settings can be overridden when initializing the chat
     * client.
     */
    settings : {
      /**
       * The URL of the XMPP's BOSH service with which SilverChat communicates.
       * @type {string}
       */
      url : 'http://im.silverpeas.net:5280/http-bind/',

      /**
       * The definition of an ICE service to enable the video chat capability. It is defined by the
       * following object:
       * {
       *   server: {string}    the hostname or IP address of a ICE server with its port number.
       *                       (for example ice.silverpeas.net:80)
       *   auth: {boolean}     is an authentication must be performed to access the STUN service?
       *   user: {string}      the user identifier used to authenticate the client to the STUN
       *                       service. If missing and auth is true, then the current user
       *                       identifier is used. Optional.
       *   password: {string}  the password associated with the user identifier to authenticate the
       *                       the client to the STUN service. If user is set, this attribute is
       *                       mandatory. Optional.
       * }
       * If no such service is defined, then the video chat capability is disabled.
       */
      ice : null,

      /**
       * The user login to open a connection with the XMPP server.
       * @type {string}
       */
      id : '',

      /**
       * The user password to open a connection with the XMPP server.
       * @type {string}
       */
      password : '',

      /**
       * The XMPP domain (or Jabber domain) in which the user is.
       * @type {string}
       */
      domain : 'im.silverpeas.net',

      /**
       * The ISO 639-1 code of the language to use in the GUI localization. By default, in English.
       * @type {string}
       */
      language : '',

      /**
       * The path of the installation directory of SilverChat. By default, in the chat directory
       * relative to the web context (the web context is assumed to be defined in the webContext
       * variable).
       * @type {string}
       */
      path : chatPath,

      /**
       * The path of the directory containing the avatars of the user and of its buddies.
       * The path can be provided by a function that has to accept as argument the JID (Jabber
       * IDentifier) of the user for which the avatar is asked.
       * @type {string|function}
       */
      avatar : null,

      /**
       * A function to provide a custom and an external way to select a user with whom the current
       * user wish to chat. The selected user will be then added into the current user's roster
       * but no presence subscription will be performed.
       *
       * The function must accept as argument a callback to call with as parameters the JID of the
       * selected user and optionally the name (or alias) of the selected user.
       * If no function is set, then the user selection menu item is removed.
       * @type {function}
       */
      selectUser: null,

      /**
       * Switches SilverChat logs in the debug level for displaying debugging messages in the
       * Javascript console of the web browser. By default, false.
       * @type {boolean}
       */
      debug: false
    },

    /**
     * Initializes the silverpeas chat client. It bootstraps JSXC and its own customization of
     * JSXC.
     * @param options the options to override the default settings.
     * @return {SilverChat}
     */
    init : function(options) {
      this.settings = $.extend(true, this.settings, options);
      this.settings.path += '/jsxc';

      window.top.addEventListener("beforeunload", function() {
        if (jsxc.master) {
          jsxc.gui.changePresence('offline', true);
          setTimeout(function() {
            jsxc.xmpp.logout(true);

            // here we call directly this method to be sure it have time to execute
            jsxc.xmpp.disconnected();

            jsxc.error("Disconnected before leaving page");
          }, 0);
        }
      }, false);

      jsxc.storage.setItem("debug", this.settings.debug);

{'fraction_non_alphanumeric': 0.08343488504346414, 'fraction_numerical': 0.0035746201966041107, 'mean_word_length': 2.2267365661861076, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2591562', 'n_tokens_mistral': 3333, 'n_tokens_neox': 3198, 'n_words': 1440}