1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: jsxc.lib.xmpp.chatState.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: jsxc.lib.xmpp.chatState.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Implements XEP-0085: Chat State Notifications.
*
* @namespace jsxc.xmpp.chatState
* @see {@link http://xmpp.org/extensions/xep-0085.html}
*/
jsxc.xmpp.chatState = {
conn: null,
/** Delay between two notification on the message composing */
toComposingNotificationDelay: 900,
};
jsxc.xmpp.chatState.init = function() {
var self = jsxc.xmpp.chatState;
if (!jsxc.xmpp.conn || !jsxc.xmpp.connected) {
$(document).on('attached.jsxc', self.init);
return;
}
// prevent double execution after reconnect
$(document).off('composing.chatstates', jsxc.xmpp.chatState.onComposing);
$(document).off('paused.chatstates', jsxc.xmpp.chatState.onPaused);
$(document).off('active.chatstates', jsxc.xmpp.chatState.onActive);
if (self.isDisabled()) {
jsxc.debug('chat state notification disabled');
return;
}
self.conn = jsxc.xmpp.conn;
$(document).on('composing.chatstates', jsxc.xmpp.chatState.onComposing);
$(document).on('paused.chatstates', jsxc.xmpp.chatState.onPaused);
$(document).on('active.chatstates', jsxc.xmpp.chatState.onActive);
};
/**
* Composing event received. Display message.
*
* @memberOf jsxc.xmpp.chatState
* @param {Event} ev
* @param {String} jid
*/
jsxc.xmpp.chatState.onComposing = function(ev, jid) {
var self = jsxc.xmpp.chatState;
var bid = jsxc.jidToBid(jid);
var data = jsxc.storage.getUserItem('buddy', bid) || null;
if (!data || jsxc.xmpp.chatState.isDisabled()) {
return;
}
// ignore own notifications in groupchat
if (data.type === 'groupchat' &&
Strophe.getResourceFromJid(jid) === Strophe.getNodeFromJid(self.conn.jid)) {
return;
}
var user = data.type === 'groupchat' ? Strophe.getResourceFromJid(jid) : data.name;
var win = jsxc.gui.window.get(bid);
if (win.length === 0) {
return;
}
// add user in array if necessary
var usersComposing = win.data('composing') || [];
if (usersComposing.indexOf(user) === -1) {
usersComposing.push(user);
win.data('composing', usersComposing);
}
var msg = self._genComposingMsg(data.type, usersComposing);
jsxc.xmpp.chatState.setStatus(win, msg);
};
/**
* Pause event receive. Remove or update composing message.
*
* @memberOf jsxc.xmpp.chatState
* @param {Event} ev
* @param {String} jid
*/
jsxc.xmpp.chatState.onPaused = function(ev, jid) {
var self = jsxc.xmpp.chatState;
var bid = jsxc.jidToBid(jid);
var data = jsxc.storage.getUserItem('buddy', bid) || null;
if (!data || jsxc.xmpp.chatState.isDisabled()) {
return;
}
var user = data.type === 'groupchat' ? Strophe.getResourceFromJid(jid) : data.name;
var win = jsxc.gui.window.get(bid);
if (win.length === 0) {
return;
}
var usersComposing = win.data('composing') || [];
if (usersComposing.indexOf(user) >= 0) {
// remove user from list
usersComposing.splice(usersComposing.indexOf(user), 1);
win.data('composing', usersComposing);
}
var composingMsg;
if (usersComposing.length !== 0) {
composingMsg = self._genComposingMsg(data.type, usersComposing);
}
jsxc.xmpp.chatState.setStatus(win, composingMsg);
};
/**
* Active event received.
*
* @memberOf jsxc.xmpp.chatState
* @param {Event} ev
* @param {String} jid
*/
jsxc.xmpp.chatState.onActive = function(ev, jid) {
jsxc.xmpp.chatState.onPaused(ev, jid);
};
/**
* Send composing event.
*
* @memberOf jsxc.xmpp.chatState
* @param {String} bid
*/
jsxc.xmpp.chatState.startComposing = function(bid) {
var self = jsxc.xmpp.chatState;
if (!jsxc.xmpp.conn || !jsxc.xmpp.conn.chatstates || jsxc.xmpp.chatState.isDisabled()) {
return;
}
var win = jsxc.gui.window.get(bid);
var timeout = win.data('composing-timeout');
var type = win.hasClass('jsxc_groupchat') ? 'groupchat' : 'chat';
if (timeout) {
// @REVIEW page reload?
clearTimeout(timeout);
} else {
jsxc.xmpp.conn.chatstates.sendComposing(bid, type);
}
timeout = setTimeout(function() {
self.pauseComposing(bid, type);
win.data('composing-timeout', null);
}, self.toComposingNotificationDelay);
win.data('composing-timeout', timeout);
};
/**
* Send pause event.
*
* @memberOf jsxc.xmpp.chatState
* @param {String} bid
*/
jsxc.xmpp.chatState.pauseComposing = function(bid, type) {
if (jsxc.xmpp.chatState.isDisabled()) {
return;
}
jsxc.xmpp.conn.chatstates.sendPaused(bid, type);
};
/**
* End composing without sending a pause event.
*
* @memberOf jsxc.xmpp.chatState
* @param {String} bid
*/
jsxc.xmpp.chatState.endComposing = function(bid) {
var win = jsxc.gui.window.get(bid);
if (win.data('composing-timeout')) {
clearTimeout(win.data('composing-timeout'));
}
};
/**
* Generate composing message.
*
* @memberOf jsxc.xmpp.chatState
* @param {String} the type of the chat ('groupchat' or 'chat')
* @param {Array} usersComposing List of users which are currently composing a message
*/
jsxc.xmpp.chatState._genComposingMsg = function(chatType, usersComposing) {
if (!usersComposing || usersComposing.length === 0) {
jsxc.debug('usersComposing array is empty?');
return '';
} else {
if (chatType === 'groupchat') {
return usersComposing.length > 1 ? usersComposing.join(', ') + $.t('_are_composing') :
usersComposing[0] + $.t('_is_composing');
}
return $.t('_is_composing');
}
};
jsxc.xmpp.chatState.setStatus = function(win, msg) {
var statusMsgElement = win.find('.jsxc_status-msg');
statusMsgElement.text(msg || '');
statusMsgElement.attr('title', msg || '');
if (msg) {
statusMsgElement.addClass('jsxc_composing');
win.addClass('jsxc_status-msg-show');
} else {
statusMsgElement.removeClass('jsxc_composing');
win.removeClass('jsxc_status-msg-show');
}
};
jsxc.xmpp.chatState.isDisabled = function() {
var options = jsxc.options.get('chatState') || {};
return !options.enable;
};
$(document).on('attached.jsxc', jsxc.xmpp.chatState.init);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="jsxc.Message.html">Message</a></li></ul><h3>Namespaces</h3><ul><li><a href="jsxc.html">jsxc</a></li><li><a href="jsxc.fileTransfer.html">fileTransfer</a></li><li><a href="jsxc.gui.html">gui</a></li><li><a href="jsxc.gui.dialog.html">dialog</a></li><li><a href="jsxc.gui.queryActions.html">queryActions</a></li><li><a href="jsxc.gui.roster.html">roster</a></li><li><a href="jsxc.gui.window.html">window</a></li><li><a href="jsxc.muc.html">muc</a></li><li><a href="jsxc.notification.html">notification</a></li><li><a href="jsxc.options.html">options</a></li><li><a href="jsxc.otr.html">otr</a></li><li><a href="jsxc.storage.html">storage</a></li><li><a href="jsxc.tab.html">tab</a></li><li><a href="jsxc.webrtc.html">webrtc</a></li><li><a href="jsxc.xmpp.html">xmpp</a></li><li><a href="jsxc.xmpp.bookmarks.html">bookmarks</a></li><li><a href="jsxc.xmpp.carbons.html">carbons</a></li><li><a href="jsxc.xmpp.chatState.html">chatState</a></li><li><a href="jsxc.xmpp.httpUpload.html">httpUpload</a></li><li><a href="jsxc.xmpp.mam.html">mam</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri May 10 2019 12:36:11 GMT+0200 (Central European Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
|