You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChatRoom.js 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. /* global $, __filename */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import { $iq, $msg, $pres, Strophe } from 'strophe.js';
  4. import GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
  5. import * as JitsiTranscriptionStatus from '../../JitsiTranscriptionStatus';
  6. import Listenable from '../util/Listenable';
  7. import * as MediaType from '../../service/RTC/MediaType';
  8. import XMPPEvents from '../../service/xmpp/XMPPEvents';
  9. import Moderator from './moderator';
  10. const logger = getLogger(__filename);
  11. export const parser = {
  12. packet2JSON(xmlElement, nodes) {
  13. for (const child of Array.from(xmlElement.children)) {
  14. const node = {
  15. attributes: {},
  16. children: [],
  17. tagName: child.tagName
  18. };
  19. for (const attr of Array.from(child.attributes)) {
  20. node.attributes[attr.name] = attr.value;
  21. }
  22. const text = Strophe.getText(child);
  23. if (text) {
  24. // Using Strophe.getText will do work for traversing all direct
  25. // child text nodes but returns an escaped value, which is not
  26. // desirable at this point.
  27. node.value = Strophe.xmlunescape(text);
  28. }
  29. nodes.push(node);
  30. this.packet2JSON(child, node.children);
  31. }
  32. },
  33. json2packet(nodes, packet) {
  34. for (let i = 0; i < nodes.length; i++) {
  35. const node = nodes[i];
  36. if (node) {
  37. packet.c(node.tagName, node.attributes);
  38. if (node.value) {
  39. packet.t(node.value);
  40. }
  41. if (node.children) {
  42. this.json2packet(node.children, packet);
  43. }
  44. packet.up();
  45. }
  46. }
  47. // packet.up();
  48. }
  49. };
  50. /**
  51. * Returns array of JS objects from the presence JSON associated with the passed
  52. / nodeName
  53. * @param pres the presence JSON
  54. * @param nodeName the name of the node (videomuted, audiomuted, etc)
  55. */
  56. function filterNodeFromPresenceJSON(pres, nodeName) {
  57. const res = [];
  58. for (let i = 0; i < pres.length; i++) {
  59. if (pres[i].tagName === nodeName) {
  60. res.push(pres[i]);
  61. }
  62. }
  63. return res;
  64. }
  65. // XXX As ChatRoom constructs XMPP stanzas and Strophe is build around the idea
  66. // of chaining function calls, allow long function call chains.
  67. /* eslint-disable newline-per-chained-call */
  68. /**
  69. *
  70. */
  71. export default class ChatRoom extends Listenable {
  72. /* eslint-disable max-params */
  73. /**
  74. *
  75. * @param connection
  76. * @param jid
  77. * @param password
  78. * @param XMPP
  79. * @param options
  80. * @param {boolean} options.disableFocus - when set to {@code false} will
  81. * not invite Jicofo into the room. This is intended to be used only by
  82. * jitsi-meet-spot.
  83. */
  84. constructor(connection, jid, password, XMPP, options) {
  85. super();
  86. this.xmpp = XMPP;
  87. this.connection = connection;
  88. this.roomjid = Strophe.getBareJidFromJid(jid);
  89. this.myroomjid = jid;
  90. this.password = password;
  91. logger.info(`Joined MUC as ${this.myroomjid}`);
  92. this.members = {};
  93. this.presMap = {};
  94. this.presHandlers = {};
  95. this.joined = false;
  96. this.role = null;
  97. this.focusMucJid = null;
  98. this.noBridgeAvailable = false;
  99. this.options = options || {};
  100. this.moderator
  101. = new Moderator(this.roomjid, this.xmpp, this.eventEmitter, {
  102. connection: this.xmpp.options,
  103. conference: this.options
  104. });
  105. this.initPresenceMap(options);
  106. this.lastPresences = {};
  107. this.phoneNumber = null;
  108. this.phonePin = null;
  109. this.connectionTimes = {};
  110. this.participantPropertyListener = null;
  111. this.locked = false;
  112. this.transcriptionStatus = JitsiTranscriptionStatus.OFF;
  113. this.meetingId = null;
  114. }
  115. /* eslint-enable max-params */
  116. /**
  117. *
  118. */
  119. initPresenceMap(options = {}) {
  120. this.presMap.to = this.myroomjid;
  121. this.presMap.xns = 'http://jabber.org/protocol/muc';
  122. this.presMap.nodes = [];
  123. if (options.statsId) {
  124. this.presMap.nodes.push({
  125. 'tagName': 'stats-id',
  126. 'value': options.statsId
  127. });
  128. }
  129. // We need to broadcast 'videomuted' status from the beginning, cause
  130. // Jicofo makes decisions based on that. Initialize it with 'false'
  131. // here.
  132. this.addVideoInfoToPresence(false);
  133. if (options.deploymentInfo && options.deploymentInfo.userRegion) {
  134. this.presMap.nodes.push({
  135. 'tagName': 'region',
  136. 'attributes': {
  137. id: options.deploymentInfo.userRegion,
  138. xmlns: 'http://jitsi.org/jitsi-meet'
  139. }
  140. });
  141. }
  142. }
  143. /**
  144. * Joins the chat room.
  145. * @param password
  146. * @returns {Promise} - resolved when join completes. At the time of this
  147. * writing it's never rejected.
  148. */
  149. join(password) {
  150. this.password = password;
  151. return new Promise(resolve => {
  152. this.options.disableFocus
  153. && logger.info('Conference focus disabled');
  154. const preJoin
  155. = this.options.disableFocus
  156. ? Promise.resolve()
  157. : this.moderator.allocateConferenceFocus();
  158. preJoin.then(() => {
  159. this.sendPresence(true);
  160. resolve();
  161. });
  162. });
  163. }
  164. /**
  165. *
  166. * @param fromJoin
  167. */
  168. sendPresence(fromJoin) {
  169. const to = this.presMap.to;
  170. if (!to || (!this.joined && !fromJoin)) {
  171. // Too early to send presence - not initialized
  172. return;
  173. }
  174. const pres = $pres({ to });
  175. // xep-0045 defines: "including in the initial presence stanza an empty
  176. // <x/> element qualified by the 'http://jabber.org/protocol/muc'
  177. // namespace" and subsequent presences should not include that or it can
  178. // be considered as joining, and server can send us the message history
  179. // for the room on every presence
  180. if (fromJoin) {
  181. pres.c('x', { xmlns: this.presMap.xns });
  182. if (this.password) {
  183. pres.c('password').t(this.password).up();
  184. }
  185. pres.up();
  186. }
  187. parser.json2packet(this.presMap.nodes, pres);
  188. this.connection.send(pres);
  189. if (fromJoin) {
  190. // XXX We're pressed for time here because we're beginning a complex
  191. // and/or lengthy conference-establishment process which supposedly
  192. // involves multiple RTTs. We don't have the time to wait for
  193. // Strophe to decide to send our IQ.
  194. this.connection.flush();
  195. }
  196. }
  197. /**
  198. * Sends the presence unavailable, signaling the server
  199. * we want to leave the room.
  200. */
  201. doLeave() {
  202. logger.log('do leave', this.myroomjid);
  203. const pres = $pres({ to: this.myroomjid,
  204. type: 'unavailable' });
  205. this.presMap.length = 0;
  206. // XXX Strophe is asynchronously sending by default. Unfortunately, that
  207. // means that there may not be enough time to send the unavailable
  208. // presence. Switching Strophe to synchronous sending is not much of an
  209. // option because it may lead to a noticeable delay in navigating away
  210. // from the current location. As a compromise, we will try to increase
  211. // the chances of sending the unavailable presence within the short time
  212. // span that we have upon unloading by invoking flush() on the
  213. // connection. We flush() once before sending/queuing the unavailable
  214. // presence in order to attemtp to have the unavailable presence at the
  215. // top of the send queue. We flush() once more after sending/queuing the
  216. // unavailable presence in order to attempt to have it sent as soon as
  217. // possible.
  218. this.connection.flush();
  219. this.connection.send(pres);
  220. this.connection.flush();
  221. }
  222. /**
  223. *
  224. */
  225. discoRoomInfo() {
  226. // https://xmpp.org/extensions/xep-0045.html#disco-roominfo
  227. const getInfo
  228. = $iq({
  229. type: 'get',
  230. to: this.roomjid
  231. })
  232. .c('query', { xmlns: Strophe.NS.DISCO_INFO });
  233. this.connection.sendIQ(getInfo, result => {
  234. const locked
  235. = $(result).find('>query>feature[var="muc_passwordprotected"]')
  236. .length
  237. === 1;
  238. if (locked !== this.locked) {
  239. this.eventEmitter.emit(XMPPEvents.MUC_LOCK_CHANGED, locked);
  240. this.locked = locked;
  241. }
  242. const meetingIdValEl
  243. = $(result).find('>query>x[type="result"]>field[var="muc#roominfo_meetingId"]>value');
  244. if (meetingIdValEl.length) {
  245. const meetingId = meetingIdValEl.text();
  246. if (this.meetingId !== meetingId) {
  247. if (this.meetingId) {
  248. logger.warn(`Meeting Id changed from:${this.meetingId} to:${meetingId}`);
  249. }
  250. this.meetingId = meetingId;
  251. }
  252. } else {
  253. logger.trace('No meeting id from backend');
  254. }
  255. }, error => {
  256. GlobalOnErrorHandler.callErrorHandler(error);
  257. logger.error('Error getting room info: ', error);
  258. });
  259. }
  260. /**
  261. *
  262. */
  263. createNonAnonymousRoom() {
  264. // http://xmpp.org/extensions/xep-0045.html#createroom-reserved
  265. const getForm = $iq({ type: 'get',
  266. to: this.roomjid })
  267. .c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' })
  268. .c('x', { xmlns: 'jabber:x:data',
  269. type: 'submit' });
  270. const self = this;
  271. this.connection.sendIQ(getForm, form => {
  272. if (!$(form).find(
  273. '>query>x[xmlns="jabber:x:data"]'
  274. + '>field[var="muc#roomconfig_whois"]').length) {
  275. const errmsg = 'non-anonymous rooms not supported';
  276. GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
  277. logger.error(errmsg);
  278. return;
  279. }
  280. const formSubmit = $iq({ to: self.roomjid,
  281. type: 'set' })
  282. .c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' });
  283. formSubmit.c('x', { xmlns: 'jabber:x:data',
  284. type: 'submit' });
  285. formSubmit.c('field', { 'var': 'FORM_TYPE' })
  286. .c('value')
  287. .t('http://jabber.org/protocol/muc#roomconfig').up().up();
  288. formSubmit.c('field', { 'var': 'muc#roomconfig_whois' })
  289. .c('value').t('anyone').up().up();
  290. self.connection.sendIQ(formSubmit);
  291. }, error => {
  292. GlobalOnErrorHandler.callErrorHandler(error);
  293. logger.error('Error getting room configuration form: ', error);
  294. });
  295. }
  296. /**
  297. *
  298. * @param pres
  299. */
  300. onPresence(pres) {
  301. const from = pres.getAttribute('from');
  302. const member = {};
  303. const statusEl = pres.getElementsByTagName('status')[0];
  304. if (statusEl) {
  305. member.status = statusEl.textContent || '';
  306. }
  307. let hasStatusUpdate = false;
  308. let hasVersionUpdate = false;
  309. const xElement
  310. = pres.getElementsByTagNameNS(
  311. 'http://jabber.org/protocol/muc#user', 'x')[0];
  312. const mucUserItem
  313. = xElement && xElement.getElementsByTagName('item')[0];
  314. member.affiliation
  315. = mucUserItem && mucUserItem.getAttribute('affiliation');
  316. member.role = mucUserItem && mucUserItem.getAttribute('role');
  317. // Focus recognition
  318. const jid = mucUserItem && mucUserItem.getAttribute('jid');
  319. member.jid = jid;
  320. member.isFocus
  321. = jid && jid.indexOf(`${this.moderator.getFocusUserJid()}/`) === 0;
  322. member.isHiddenDomain
  323. = jid && jid.indexOf('@') > 0
  324. && this.options.hiddenDomain
  325. === jid.substring(jid.indexOf('@') + 1, jid.indexOf('/'));
  326. this.eventEmitter.emit(XMPPEvents.PRESENCE_RECEIVED, {
  327. fromHiddenDomain: member.isHiddenDomain,
  328. presence: pres
  329. });
  330. const xEl = pres.querySelector('x');
  331. if (xEl) {
  332. xEl.remove();
  333. }
  334. const nodes = [];
  335. parser.packet2JSON(pres, nodes);
  336. this.lastPresences[from] = nodes;
  337. // process nodes to extract data needed for MUC_JOINED and
  338. // MUC_MEMBER_JOINED events
  339. const extractIdentityInformation = node => {
  340. const identity = {};
  341. const userInfo = node.children.find(c => c.tagName === 'user');
  342. if (userInfo) {
  343. identity.user = {};
  344. for (const tag of [ 'id', 'name', 'avatar' ]) {
  345. const child
  346. = userInfo.children.find(c => c.tagName === tag);
  347. if (child) {
  348. identity.user[tag] = child.value;
  349. }
  350. }
  351. }
  352. const groupInfo = node.children.find(c => c.tagName === 'group');
  353. if (groupInfo) {
  354. identity.group = groupInfo.value;
  355. }
  356. return identity;
  357. };
  358. for (let i = 0; i < nodes.length; i++) {
  359. const node = nodes[i];
  360. switch (node.tagName) {
  361. case 'bot': {
  362. const { attributes } = node;
  363. if (!attributes) {
  364. break;
  365. }
  366. const { type } = attributes;
  367. member.botType = type;
  368. break;
  369. }
  370. case 'nick':
  371. member.nick = node.value;
  372. break;
  373. case 'userId':
  374. member.id = node.value;
  375. break;
  376. case 'stats-id':
  377. member.statsID = node.value;
  378. break;
  379. case 'identity':
  380. member.identity = extractIdentityInformation(node);
  381. break;
  382. case 'stat': {
  383. const { attributes } = node;
  384. if (!attributes) {
  385. break;
  386. }
  387. const { name } = attributes;
  388. if (name === 'version') {
  389. member.version = attributes.value;
  390. }
  391. break;
  392. }
  393. }
  394. }
  395. if (from === this.myroomjid) {
  396. const newRole
  397. = member.affiliation === 'owner' ? member.role : 'none';
  398. if (this.role !== newRole) {
  399. this.role = newRole;
  400. this.eventEmitter.emit(
  401. XMPPEvents.LOCAL_ROLE_CHANGED,
  402. this.role);
  403. }
  404. if (!this.joined) {
  405. this.joined = true;
  406. const now = this.connectionTimes['muc.joined']
  407. = window.performance.now();
  408. logger.log('(TIME) MUC joined:\t', now);
  409. // set correct initial state of locked
  410. if (this.password) {
  411. this.locked = true;
  412. }
  413. // Re-send presence in case any presence updates were added,
  414. // but blocked from sending, during the join process.
  415. this.sendPresence();
  416. this.eventEmitter.emit(XMPPEvents.MUC_JOINED);
  417. // Now let's check the disco-info to retrieve the
  418. // meeting Id if any
  419. this.discoRoomInfo();
  420. }
  421. } else if (jid === undefined) {
  422. logger.info('Ignoring member with undefined JID');
  423. } else if (this.members[from] === undefined) {
  424. // new participant
  425. this.members[from] = member;
  426. logger.log('entered', from, member);
  427. hasStatusUpdate = member.status !== undefined;
  428. hasVersionUpdate = member.version !== undefined;
  429. if (member.isFocus) {
  430. this._initFocus(from, jid);
  431. } else {
  432. // identity is being added to member joined, so external
  433. // services can be notified for that (currently identity is
  434. // not used inside library)
  435. this.eventEmitter.emit(
  436. XMPPEvents.MUC_MEMBER_JOINED,
  437. from,
  438. member.nick,
  439. member.role,
  440. member.isHiddenDomain,
  441. member.statsID,
  442. member.status,
  443. member.identity,
  444. member.botType);
  445. // we are reporting the status with the join
  446. // so we do not want a second event about status update
  447. hasStatusUpdate = false;
  448. }
  449. } else {
  450. // Presence update for existing participant
  451. // Watch role change:
  452. const memberOfThis = this.members[from];
  453. if (memberOfThis.role !== member.role) {
  454. memberOfThis.role = member.role;
  455. this.eventEmitter.emit(
  456. XMPPEvents.MUC_ROLE_CHANGED, from, member.role);
  457. }
  458. // fire event that botType had changed
  459. if (memberOfThis.botType !== member.botType) {
  460. memberOfThis.botType = member.botType;
  461. this.eventEmitter.emit(
  462. XMPPEvents.MUC_MEMBER_BOT_TYPE_CHANGED,
  463. from,
  464. member.botType);
  465. }
  466. if (member.isFocus) {
  467. // From time to time first few presences of the focus are not
  468. // containing it's jid. That way we can mark later the focus
  469. // member instead of not marking it at all and not starting the
  470. // conference.
  471. // FIXME: Maybe there is a better way to handle this issue. It
  472. // seems there is some period of time in prosody that the
  473. // configuration form is received but not applied. And if any
  474. // participant joins during that period of time the first
  475. // presence from the focus won't contain
  476. // <item jid="focus..." />.
  477. memberOfThis.isFocus = true;
  478. this._initFocus(from, jid);
  479. }
  480. // store the new display name
  481. if (member.displayName) {
  482. memberOfThis.displayName = member.displayName;
  483. }
  484. // update stored status message to be able to detect changes
  485. if (memberOfThis.status !== member.status) {
  486. hasStatusUpdate = true;
  487. memberOfThis.status = member.status;
  488. }
  489. if (memberOfThis.version !== member.version) {
  490. hasVersionUpdate = true;
  491. memberOfThis.version = member.version;
  492. }
  493. }
  494. // after we had fired member or room joined events, lets fire events
  495. // for the rest info we got in presence
  496. for (let i = 0; i < nodes.length; i++) {
  497. const node = nodes[i];
  498. switch (node.tagName) {
  499. case 'nick':
  500. if (!member.isFocus) {
  501. const displayName
  502. = this.xmpp.options.displayJids
  503. ? Strophe.getResourceFromJid(from)
  504. : member.nick;
  505. this.eventEmitter.emit(
  506. XMPPEvents.DISPLAY_NAME_CHANGED,
  507. from,
  508. displayName);
  509. }
  510. break;
  511. case 'bridgeNotAvailable':
  512. if (member.isFocus && !this.noBridgeAvailable) {
  513. this.noBridgeAvailable = true;
  514. this.eventEmitter.emit(XMPPEvents.BRIDGE_DOWN);
  515. }
  516. break;
  517. case 'conference-properties':
  518. if (member.isFocus) {
  519. const properties = {};
  520. for (let j = 0; j < node.children.length; j++) {
  521. const { attributes } = node.children[j];
  522. if (attributes && attributes.key) {
  523. properties[attributes.key] = attributes.value;
  524. }
  525. }
  526. this.eventEmitter.emit(
  527. XMPPEvents.CONFERENCE_PROPERTIES_CHANGED, properties);
  528. }
  529. break;
  530. case 'transcription-status': {
  531. const { attributes } = node;
  532. if (!attributes) {
  533. break;
  534. }
  535. const { status } = attributes;
  536. if (status && status !== this.transcriptionStatus) {
  537. this.transcriptionStatus = status;
  538. this.eventEmitter.emit(
  539. XMPPEvents.TRANSCRIPTION_STATUS_CHANGED,
  540. status
  541. );
  542. }
  543. break;
  544. }
  545. case 'call-control': {
  546. const att = node.attributes;
  547. if (!att) {
  548. break;
  549. }
  550. this.phoneNumber = att.phone || null;
  551. this.phonePin = att.pin || null;
  552. this.eventEmitter.emit(XMPPEvents.PHONE_NUMBER_CHANGED);
  553. break;
  554. }
  555. default:
  556. this.processNode(node, from);
  557. }
  558. }
  559. // Trigger status message update if necessary
  560. if (hasStatusUpdate) {
  561. this.eventEmitter.emit(
  562. XMPPEvents.PRESENCE_STATUS,
  563. from,
  564. member.status);
  565. }
  566. if (hasVersionUpdate) {
  567. logger.info(`Received version for ${jid}: ${member.version}`);
  568. }
  569. }
  570. /**
  571. * Initialize some properties when the focus participant is verified.
  572. * @param from jid of the focus
  573. * @param mucJid the jid of the focus in the muc
  574. */
  575. _initFocus(from, mucJid) {
  576. this.focusMucJid = from;
  577. logger.info(`Ignore focus: ${from}, real JID: ${mucJid}`);
  578. }
  579. /**
  580. * Sets the special listener to be used for "command"s whose name starts
  581. * with "jitsi_participant_".
  582. */
  583. setParticipantPropertyListener(listener) {
  584. this.participantPropertyListener = listener;
  585. }
  586. /**
  587. *
  588. * @param node
  589. * @param from
  590. */
  591. processNode(node, from) {
  592. // make sure we catch all errors coming from any handler
  593. // otherwise we can remove the presence handler from strophe
  594. try {
  595. let tagHandlers = this.presHandlers[node.tagName];
  596. if (node.tagName.startsWith('jitsi_participant_')) {
  597. tagHandlers = [ this.participantPropertyListener ];
  598. }
  599. if (tagHandlers) {
  600. tagHandlers.forEach(handler => {
  601. handler(node, Strophe.getResourceFromJid(from), from);
  602. });
  603. }
  604. } catch (e) {
  605. GlobalOnErrorHandler.callErrorHandler(e);
  606. logger.error(`Error processing:${node.tagName} node.`, e);
  607. }
  608. }
  609. /**
  610. * Send text message to the other participants in the conference
  611. * @param message
  612. * @param elementName
  613. * @param nickname
  614. */
  615. sendMessage(message, elementName, nickname) {
  616. const msg = $msg({ to: this.roomjid,
  617. type: 'groupchat' });
  618. // We are adding the message in a packet extension. If this element
  619. // is different from 'body', we add a custom namespace.
  620. // e.g. for 'json-message' extension of message stanza.
  621. if (elementName === 'body') {
  622. msg.c(elementName, message).up();
  623. } else {
  624. msg.c(elementName, { xmlns: 'http://jitsi.org/jitmeet' }, message)
  625. .up();
  626. }
  627. if (nickname) {
  628. msg.c('nick', { xmlns: 'http://jabber.org/protocol/nick' })
  629. .t(nickname)
  630. .up()
  631. .up();
  632. }
  633. this.connection.send(msg);
  634. this.eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, message);
  635. }
  636. /* eslint-disable max-params */
  637. /**
  638. * Send private text message to another participant of the conference
  639. * @param id id/muc resource of the receiver
  640. * @param message
  641. * @param elementName
  642. * @param nickname
  643. */
  644. sendPrivateMessage(id, message, elementName, nickname) {
  645. const msg = $msg({ to: `${this.roomjid}/${id}`,
  646. type: 'chat' });
  647. // We are adding the message in packet. If this element is different
  648. // from 'body', we add our custom namespace for the same.
  649. // e.g. for 'json-message' message extension.
  650. if (elementName === 'body') {
  651. msg.c(elementName, message).up();
  652. } else {
  653. msg.c(elementName, { xmlns: 'http://jitsi.org/jitmeet' }, message)
  654. .up();
  655. }
  656. if (nickname) {
  657. msg.c('nick', { xmlns: 'http://jabber.org/protocol/nick' })
  658. .t(nickname)
  659. .up()
  660. .up();
  661. }
  662. this.connection.send(msg);
  663. this.eventEmitter.emit(
  664. XMPPEvents.SENDING_PRIVATE_CHAT_MESSAGE, message);
  665. }
  666. /* eslint-enable max-params */
  667. /**
  668. *
  669. * @param subject
  670. */
  671. setSubject(subject) {
  672. const msg = $msg({ to: this.roomjid,
  673. type: 'groupchat' });
  674. msg.c('subject', subject);
  675. this.connection.send(msg);
  676. }
  677. /**
  678. * Called when participant leaves.
  679. * @param jid the jid of the participant that leaves
  680. * @param skipEvents optional params to skip any events, including check
  681. * whether this is the focus that left
  682. */
  683. onParticipantLeft(jid, skipEvents) {
  684. delete this.lastPresences[jid];
  685. if (skipEvents) {
  686. return;
  687. }
  688. this.eventEmitter.emit(XMPPEvents.MUC_MEMBER_LEFT, jid);
  689. this.moderator.onMucMemberLeft(jid);
  690. }
  691. /**
  692. *
  693. * @param pres
  694. * @param from
  695. */
  696. onPresenceUnavailable(pres, from) {
  697. // ignore presence
  698. if ($(pres).find('>ignore[xmlns="http://jitsi.org/jitmeet/"]').length) {
  699. return true;
  700. }
  701. // room destroyed ?
  702. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]'
  703. + '>destroy').length) {
  704. let reason;
  705. const reasonSelect
  706. = $(pres).find(
  707. '>x[xmlns="http://jabber.org/protocol/muc#user"]'
  708. + '>destroy>reason');
  709. if (reasonSelect.length) {
  710. reason = reasonSelect.text();
  711. }
  712. this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
  713. this.connection.emuc.doLeave(this.roomjid);
  714. return true;
  715. }
  716. // Status code 110 indicates that this notification is "self-presence".
  717. const isSelfPresence
  718. = $(pres)
  719. .find(
  720. '>x[xmlns="http://jabber.org/protocol/muc#user"]>'
  721. + 'status[code="110"]')
  722. .length;
  723. const isKick
  724. = $(pres)
  725. .find(
  726. '>x[xmlns="http://jabber.org/protocol/muc#user"]'
  727. + '>status[code="307"]')
  728. .length;
  729. const membersKeys = Object.keys(this.members);
  730. if (isKick) {
  731. const actorSelect
  732. = $(pres)
  733. .find('>x[xmlns="http://jabber.org/protocol/muc#user"]>item>actor');
  734. let actorNick;
  735. if (actorSelect.length) {
  736. actorNick = actorSelect.attr('nick');
  737. }
  738. // if no member is found this is the case we had kicked someone
  739. // and we are not in the list of members
  740. if (membersKeys.find(jid => Strophe.getResourceFromJid(jid) === actorNick)) {
  741. // we first fire the kicked so we can show the participant
  742. // who kicked, before notifying that participant left
  743. // we fire kicked for us and for any participant kicked
  744. this.eventEmitter.emit(
  745. XMPPEvents.KICKED,
  746. isSelfPresence,
  747. actorNick,
  748. Strophe.getResourceFromJid(from));
  749. }
  750. }
  751. if (!isSelfPresence) {
  752. delete this.members[from];
  753. this.onParticipantLeft(from, false);
  754. } else if (membersKeys.length > 0) {
  755. // If the status code is 110 this means we're leaving and we would
  756. // like to remove everyone else from our view, so we trigger the
  757. // event.
  758. membersKeys.forEach(jid => {
  759. const member = this.members[jid];
  760. delete this.members[jid];
  761. this.onParticipantLeft(jid, member.isFocus);
  762. });
  763. this.connection.emuc.doLeave(this.roomjid);
  764. // we fire muc_left only if this is not a kick,
  765. // kick has both statuses 110 and 307.
  766. if (!isKick) {
  767. this.eventEmitter.emit(XMPPEvents.MUC_LEFT);
  768. }
  769. }
  770. }
  771. /**
  772. *
  773. * @param msg
  774. * @param from
  775. */
  776. onMessage(msg, from) {
  777. const nick
  778. = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]')
  779. .text()
  780. || Strophe.getResourceFromJid(from);
  781. const type = msg.getAttribute('type');
  782. if (type === 'error') {
  783. const errorMsg = $(msg).find('>error>text').text();
  784. this.eventEmitter.emit(XMPPEvents.CHAT_ERROR_RECEIVED, errorMsg);
  785. return true;
  786. }
  787. const txt = $(msg).find('>body').text();
  788. const subject = $(msg).find('>subject');
  789. if (subject.length) {
  790. const subjectText = subject.text();
  791. if (subjectText || subjectText === '') {
  792. this.eventEmitter.emit(XMPPEvents.SUBJECT_CHANGED, subjectText);
  793. logger.log(`Subject is changed to ${subjectText}`);
  794. }
  795. }
  796. // xep-0203 delay
  797. let stamp = $(msg).find('>delay').attr('stamp');
  798. if (!stamp) {
  799. // or xep-0091 delay, UTC timestamp
  800. stamp = $(msg).find('>[xmlns="jabber:x:delay"]').attr('stamp');
  801. if (stamp) {
  802. // the format is CCYYMMDDThh:mm:ss
  803. const dateParts
  804. = stamp.match(/(\d{4})(\d{2})(\d{2}T\d{2}:\d{2}:\d{2})/);
  805. stamp = `${dateParts[1]}-${dateParts[2]}-${dateParts[3]}Z`;
  806. }
  807. }
  808. if (from === this.roomjid
  809. && $(msg)
  810. .find(
  811. '>x[xmlns="http://jabber.org/protocol/muc#user"]'
  812. + '>status[code="104"]')
  813. .length) {
  814. this.discoRoomInfo();
  815. }
  816. const jsonMessage = $(msg).find('>json-message').text();
  817. const parsedJson = this.xmpp.tryParseJSONAndVerify(jsonMessage);
  818. // We emit this event if the message is a valid json, and is not
  819. // delivered after a delay, i.e. stamp is undefined.
  820. // e.g. - subtitles should not be displayed if delayed.
  821. if (parsedJson && stamp === undefined) {
  822. this.eventEmitter.emit(XMPPEvents.JSON_MESSAGE_RECEIVED,
  823. from, parsedJson);
  824. return;
  825. }
  826. if (txt) {
  827. if (type === 'chat') {
  828. this.eventEmitter.emit(XMPPEvents.PRIVATE_MESSAGE_RECEIVED,
  829. from, nick, txt, this.myroomjid, stamp);
  830. } else if (type === 'groupchat') {
  831. this.eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
  832. from, nick, txt, this.myroomjid, stamp);
  833. }
  834. }
  835. }
  836. /**
  837. *
  838. * @param pres
  839. * @param from
  840. */
  841. onPresenceError(pres, from) {
  842. if ($(pres)
  843. .find(
  844. '>error[type="auth"]'
  845. + '>not-authorized['
  846. + 'xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]')
  847. .length) {
  848. logger.log('on password required', from);
  849. this.eventEmitter.emit(XMPPEvents.PASSWORD_REQUIRED);
  850. } else if ($(pres)
  851. .find(
  852. '>error[type="cancel"]'
  853. + '>not-allowed['
  854. + 'xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]')
  855. .length) {
  856. const toDomain = Strophe.getDomainFromJid(pres.getAttribute('to'));
  857. if (toDomain === this.xmpp.options.hosts.anonymousdomain) {
  858. // enter the room by replying with 'not-authorized'. This would
  859. // result in reconnection from authorized domain.
  860. // We're either missing Jicofo/Prosody config for anonymous
  861. // domains or something is wrong.
  862. this.eventEmitter.emit(XMPPEvents.ROOM_JOIN_ERROR);
  863. } else {
  864. logger.warn('onPresError ', pres);
  865. this.eventEmitter.emit(
  866. XMPPEvents.ROOM_CONNECT_NOT_ALLOWED_ERROR);
  867. }
  868. } else if ($(pres).find('>error>service-unavailable').length) {
  869. logger.warn('Maximum users limit for the room has been reached',
  870. pres);
  871. this.eventEmitter.emit(XMPPEvents.ROOM_MAX_USERS_ERROR);
  872. } else {
  873. logger.warn('onPresError ', pres);
  874. this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_ERROR);
  875. }
  876. }
  877. /**
  878. *
  879. * @param jid
  880. */
  881. kick(jid) {
  882. const kickIQ = $iq({ to: this.roomjid,
  883. type: 'set' })
  884. .c('query', { xmlns: 'http://jabber.org/protocol/muc#admin' })
  885. .c('item', { nick: Strophe.getResourceFromJid(jid),
  886. role: 'none' })
  887. .c('reason').t('You have been kicked.').up().up().up();
  888. this.connection.sendIQ(
  889. kickIQ,
  890. result => logger.log('Kick participant with jid: ', jid, result),
  891. error => logger.log('Kick participant error: ', error));
  892. }
  893. /* eslint-disable max-params */
  894. /**
  895. *
  896. * @param key
  897. * @param onSuccess
  898. * @param onError
  899. * @param onNotSupported
  900. */
  901. lockRoom(key, onSuccess, onError, onNotSupported) {
  902. // http://xmpp.org/extensions/xep-0045.html#roomconfig
  903. this.connection.sendIQ(
  904. $iq({
  905. to: this.roomjid,
  906. type: 'get'
  907. })
  908. .c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' }),
  909. res => {
  910. if ($(res)
  911. .find(
  912. '>query>x[xmlns="jabber:x:data"]'
  913. + '>field[var="muc#roomconfig_roomsecret"]')
  914. .length) {
  915. const formsubmit
  916. = $iq({
  917. to: this.roomjid,
  918. type: 'set'
  919. })
  920. .c('query', {
  921. xmlns: 'http://jabber.org/protocol/muc#owner'
  922. });
  923. formsubmit.c('x', {
  924. xmlns: 'jabber:x:data',
  925. type: 'submit'
  926. });
  927. formsubmit
  928. .c('field', { 'var': 'FORM_TYPE' })
  929. .c('value')
  930. .t('http://jabber.org/protocol/muc#roomconfig')
  931. .up()
  932. .up();
  933. formsubmit
  934. .c('field', { 'var': 'muc#roomconfig_roomsecret' })
  935. .c('value')
  936. .t(key)
  937. .up()
  938. .up();
  939. // Fixes a bug in prosody 0.9.+
  940. // https://prosody.im/issues/issue/373
  941. formsubmit
  942. .c('field', { 'var': 'muc#roomconfig_whois' })
  943. .c('value')
  944. .t('anyone')
  945. .up()
  946. .up();
  947. // FIXME: is muc#roomconfig_passwordprotectedroom required?
  948. this.connection.sendIQ(formsubmit, onSuccess, onError);
  949. } else {
  950. onNotSupported();
  951. }
  952. },
  953. onError);
  954. }
  955. /* eslint-enable max-params */
  956. /**
  957. *
  958. * @param key
  959. * @param values
  960. */
  961. addToPresence(key, values) {
  962. values.tagName = key;
  963. this.removeFromPresence(key);
  964. this.presMap.nodes.push(values);
  965. }
  966. /**
  967. * Retreives a value from the presence map.
  968. *
  969. * @param {string} key - The key to find the value for.
  970. * @returns {Object?}
  971. */
  972. getFromPresence(key) {
  973. return this.presMap.nodes.find(node => key === node.tagName);
  974. }
  975. /**
  976. *
  977. * @param key
  978. */
  979. removeFromPresence(key) {
  980. const nodes = this.presMap.nodes.filter(node => key !== node.tagName);
  981. this.presMap.nodes = nodes;
  982. }
  983. /**
  984. *
  985. * @param name
  986. * @param handler
  987. */
  988. addPresenceListener(name, handler) {
  989. if (typeof handler !== 'function') {
  990. throw new Error('"handler" is not a function');
  991. }
  992. let tagHandlers = this.presHandlers[name];
  993. if (!tagHandlers) {
  994. this.presHandlers[name] = tagHandlers = [];
  995. }
  996. if (tagHandlers.indexOf(handler) === -1) {
  997. tagHandlers.push(handler);
  998. } else {
  999. logger.warn(
  1000. `Trying to add the same handler more than once for: ${name}`);
  1001. }
  1002. }
  1003. /**
  1004. *
  1005. * @param name
  1006. * @param handler
  1007. */
  1008. removePresenceListener(name, handler) {
  1009. const tagHandlers = this.presHandlers[name];
  1010. const handlerIdx = tagHandlers ? tagHandlers.indexOf(handler) : -1;
  1011. // eslint-disable-next-line no-negated-condition
  1012. if (handlerIdx !== -1) {
  1013. tagHandlers.splice(handlerIdx, 1);
  1014. } else {
  1015. logger.warn(`Handler for: ${name} was not registered`);
  1016. }
  1017. }
  1018. /**
  1019. * Checks if the user identified by given <tt>mucJid</tt> is the conference
  1020. * focus.
  1021. * @param mucJid the full MUC address of the user to be checked.
  1022. * @returns {boolean|null} <tt>true</tt> if MUC user is the conference focus
  1023. * or <tt>false</tt> if is not. When given <tt>mucJid</tt> does not exist in
  1024. * the MUC then <tt>null</tt> is returned.
  1025. */
  1026. isFocus(mucJid) {
  1027. const member = this.members[mucJid];
  1028. if (member) {
  1029. return member.isFocus;
  1030. }
  1031. return null;
  1032. }
  1033. /**
  1034. *
  1035. */
  1036. isModerator() {
  1037. return this.role === 'moderator';
  1038. }
  1039. /**
  1040. *
  1041. * @param peerJid
  1042. */
  1043. getMemberRole(peerJid) {
  1044. if (this.members[peerJid]) {
  1045. return this.members[peerJid].role;
  1046. }
  1047. return null;
  1048. }
  1049. /**
  1050. *
  1051. * @param mute
  1052. * @param callback
  1053. */
  1054. setVideoMute(mute, callback) {
  1055. this.sendVideoInfoPresence(mute);
  1056. if (callback) {
  1057. callback(mute);
  1058. }
  1059. }
  1060. /**
  1061. *
  1062. * @param mute
  1063. * @param callback
  1064. */
  1065. setAudioMute(mute, callback) {
  1066. return this.sendAudioInfoPresence(mute, callback);
  1067. }
  1068. /**
  1069. *
  1070. * @param mute
  1071. */
  1072. addAudioInfoToPresence(mute) {
  1073. this.removeFromPresence('audiomuted');
  1074. this.addToPresence(
  1075. 'audiomuted',
  1076. {
  1077. attributes: { 'xmlns': 'http://jitsi.org/jitmeet/audio' },
  1078. value: mute.toString()
  1079. });
  1080. }
  1081. /**
  1082. *
  1083. * @param mute
  1084. * @param callback
  1085. */
  1086. sendAudioInfoPresence(mute, callback) {
  1087. this.addAudioInfoToPresence(mute);
  1088. if (this.connection) {
  1089. this.sendPresence();
  1090. }
  1091. if (callback) {
  1092. callback();
  1093. }
  1094. }
  1095. /**
  1096. *
  1097. * @param mute
  1098. */
  1099. addVideoInfoToPresence(mute) {
  1100. this.removeFromPresence('videomuted');
  1101. this.addToPresence(
  1102. 'videomuted',
  1103. {
  1104. attributes: { 'xmlns': 'http://jitsi.org/jitmeet/video' },
  1105. value: mute.toString()
  1106. });
  1107. }
  1108. /**
  1109. *
  1110. * @param mute
  1111. */
  1112. sendVideoInfoPresence(mute) {
  1113. this.addVideoInfoToPresence(mute);
  1114. if (!this.connection) {
  1115. return;
  1116. }
  1117. this.sendPresence();
  1118. }
  1119. /**
  1120. * Obtains the info about given media advertised in the MUC presence of
  1121. * the participant identified by the given endpoint JID.
  1122. * @param {string} endpointId the endpoint ID mapped to the participant
  1123. * which corresponds to MUC nickname.
  1124. * @param {MediaType} mediaType the type of the media for which presence
  1125. * info will be obtained.
  1126. * @return {PeerMediaInfo} presenceInfo an object with media presence
  1127. * info or <tt>null</tt> either if there is no presence available or if
  1128. * the media type given is invalid.
  1129. */
  1130. getMediaPresenceInfo(endpointId, mediaType) {
  1131. // Will figure out current muted status by looking up owner's presence
  1132. const pres = this.lastPresences[`${this.roomjid}/${endpointId}`];
  1133. if (!pres) {
  1134. // No presence available
  1135. return null;
  1136. }
  1137. const data = {
  1138. muted: false, // unmuted by default
  1139. videoType: undefined // no video type by default
  1140. };
  1141. let mutedNode = null;
  1142. if (mediaType === MediaType.AUDIO) {
  1143. mutedNode = filterNodeFromPresenceJSON(pres, 'audiomuted');
  1144. } else if (mediaType === MediaType.VIDEO) {
  1145. mutedNode = filterNodeFromPresenceJSON(pres, 'videomuted');
  1146. const videoTypeNode = filterNodeFromPresenceJSON(pres, 'videoType');
  1147. if (videoTypeNode.length > 0) {
  1148. data.videoType = videoTypeNode[0].value;
  1149. }
  1150. } else {
  1151. logger.error(`Unsupported media type: ${mediaType}`);
  1152. return null;
  1153. }
  1154. data.muted = mutedNode.length > 0 && mutedNode[0].value === 'true';
  1155. return data;
  1156. }
  1157. /**
  1158. * Returns true if the SIP calls are supported and false otherwise
  1159. */
  1160. isSIPCallingSupported() {
  1161. if (this.moderator) {
  1162. return this.moderator.isSipGatewayEnabled();
  1163. }
  1164. return false;
  1165. }
  1166. /**
  1167. * Dials a number.
  1168. * @param number the number
  1169. */
  1170. dial(number) {
  1171. return this.connection.rayo.dial(number, 'fromnumber',
  1172. Strophe.getBareJidFromJid(this.myroomjid), this.password,
  1173. this.focusMucJid);
  1174. }
  1175. /**
  1176. * Hangup an existing call
  1177. */
  1178. hangup() {
  1179. return this.connection.rayo.hangup();
  1180. }
  1181. /**
  1182. * Returns the phone number for joining the conference.
  1183. */
  1184. getPhoneNumber() {
  1185. return this.phoneNumber;
  1186. }
  1187. /**
  1188. * Returns the pin for joining the conference with phone.
  1189. */
  1190. getPhonePin() {
  1191. return this.phonePin;
  1192. }
  1193. /**
  1194. * Returns the meeting unique Id if any came from backend.
  1195. */
  1196. getMeetingId() {
  1197. return this.meetingId;
  1198. }
  1199. /**
  1200. * Mutes remote participant.
  1201. * @param jid of the participant
  1202. * @param mute
  1203. */
  1204. muteParticipant(jid, mute) {
  1205. logger.info('set mute', mute);
  1206. const iqToFocus = $iq(
  1207. { to: this.focusMucJid,
  1208. type: 'set' })
  1209. .c('mute', {
  1210. xmlns: 'http://jitsi.org/jitmeet/audio',
  1211. jid
  1212. })
  1213. .t(mute.toString())
  1214. .up();
  1215. this.connection.sendIQ(
  1216. iqToFocus,
  1217. result => logger.log('set mute', result),
  1218. error => logger.log('set mute error', error));
  1219. }
  1220. /**
  1221. * TODO: Document
  1222. * @param iq
  1223. */
  1224. onMute(iq) {
  1225. const from = iq.getAttribute('from');
  1226. if (from !== this.focusMucJid) {
  1227. logger.warn('Ignored mute from non focus peer');
  1228. return;
  1229. }
  1230. const mute = $(iq).find('mute');
  1231. if (mute.length && mute.text() === 'true') {
  1232. this.eventEmitter.emit(XMPPEvents.AUDIO_MUTED_BY_FOCUS, mute.attr('actor'));
  1233. } else {
  1234. // XXX Why do we support anything but muting? Why do we encode the
  1235. // value in the text of the element? Why do we use a separate XML
  1236. // namespace?
  1237. logger.warn('Ignoring a mute request which does not explicitly '
  1238. + 'specify a positive mute command.');
  1239. }
  1240. }
  1241. /**
  1242. * Leaves the room. Closes the jingle session.
  1243. * @returns {Promise} which is resolved if XMPPEvents.MUC_LEFT is received
  1244. * less than 5s after sending presence unavailable. Otherwise the promise is
  1245. * rejected.
  1246. */
  1247. leave() {
  1248. return new Promise((resolve, reject) => {
  1249. const timeout = setTimeout(() => onMucLeft(true), 5000);
  1250. const eventEmitter = this.eventEmitter;
  1251. /**
  1252. *
  1253. * @param doReject
  1254. */
  1255. function onMucLeft(doReject = false) {
  1256. eventEmitter.removeListener(XMPPEvents.MUC_LEFT, onMucLeft);
  1257. clearTimeout(timeout);
  1258. if (doReject) {
  1259. // the timeout expired
  1260. reject(new Error('The timeout for the confirmation about '
  1261. + 'leaving the room expired.'));
  1262. } else {
  1263. resolve();
  1264. }
  1265. }
  1266. eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
  1267. this.doLeave();
  1268. });
  1269. }
  1270. }
  1271. /* eslint-enable newline-per-chained-call */