您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ChatRoom.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /* global Strophe, $, $pres, $iq, $msg */
  2. /* jshint -W101,-W069 */
  3. var logger = require("jitsi-meet-logger").getLogger(__filename);
  4. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  5. var Moderator = require("./moderator");
  6. var EventEmitter = require("events");
  7. var JIBRI_XMLNS = 'http://jitsi.org/protocol/jibri';
  8. var parser = {
  9. packet2JSON: function (packet, nodes) {
  10. var self = this;
  11. $(packet).children().each(function (index) {
  12. var tagName = $(this).prop("tagName");
  13. var node = {
  14. tagName: tagName
  15. };
  16. node.attributes = {};
  17. $($(this)[0].attributes).each(function( index, attr ) {
  18. node.attributes[ attr.name ] = attr.value;
  19. });
  20. var text = Strophe.getText($(this)[0]);
  21. if (text) {
  22. node.value = text;
  23. }
  24. node.children = [];
  25. nodes.push(node);
  26. self.packet2JSON($(this), node.children);
  27. });
  28. },
  29. JSON2packet: function (nodes, packet) {
  30. for(var i = 0; i < nodes.length; i++) {
  31. var node = nodes[i];
  32. if(!node || node === null){
  33. continue;
  34. }
  35. packet.c(node.tagName, node.attributes);
  36. if(node.value)
  37. packet.t(node.value);
  38. if(node.children)
  39. this.JSON2packet(node.children, packet);
  40. packet.up();
  41. }
  42. // packet.up();
  43. }
  44. };
  45. /**
  46. * Returns array of JS objects from the presence JSON associated with the passed nodeName
  47. * @param pres the presence JSON
  48. * @param nodeName the name of the node (videomuted, audiomuted, etc)
  49. */
  50. function filterNodeFromPresenceJSON(pres, nodeName){
  51. var res = [];
  52. for(var i = 0; i < pres.length; i++)
  53. if(pres[i].tagName === nodeName)
  54. res.push(pres[i]);
  55. return res;
  56. }
  57. function ChatRoom(connection, jid, password, XMPP, options) {
  58. this.eventEmitter = new EventEmitter();
  59. this.xmpp = XMPP;
  60. this.connection = connection;
  61. this.roomjid = Strophe.getBareJidFromJid(jid);
  62. this.myroomjid = jid;
  63. this.password = password;
  64. logger.info("Joined MUC as " + this.myroomjid);
  65. this.members = {};
  66. this.presMap = {};
  67. this.presHandlers = {};
  68. this.joined = false;
  69. this.role = 'none';
  70. this.focusMucJid = null;
  71. this.bridgeIsDown = false;
  72. this.options = options || {};
  73. this.moderator = new Moderator(this.roomjid, this.xmpp, this.eventEmitter);
  74. this.initPresenceMap();
  75. this.session = null;
  76. var self = this;
  77. this.lastPresences = {};
  78. }
  79. ChatRoom.prototype.initPresenceMap = function () {
  80. this.presMap['to'] = this.myroomjid;
  81. this.presMap['xns'] = 'http://jabber.org/protocol/muc';
  82. this.presMap["nodes"] = [];
  83. this.presMap["nodes"].push( {
  84. "tagName": "user-agent",
  85. "value": navigator.userAgent,
  86. "attributes": {xmlns: 'http://jitsi.org/jitmeet/user-agent'}
  87. });
  88. };
  89. ChatRoom.prototype.updateDeviceAvailability = function (devices) {
  90. this.presMap["nodes"].push( {
  91. "tagName": "devices",
  92. "children": [
  93. {
  94. "tagName": "audio",
  95. "value": devices.audio,
  96. },
  97. {
  98. "tagName": "video",
  99. "value": devices.video,
  100. }
  101. ]
  102. });
  103. };
  104. ChatRoom.prototype.join = function (password, tokenPassword) {
  105. if(password)
  106. this.password = password;
  107. var self = this;
  108. this.moderator.allocateConferenceFocus(function()
  109. {
  110. self.sendPresence(tokenPassword);
  111. }.bind(this));
  112. };
  113. ChatRoom.prototype.sendPresence = function (tokenPassword) {
  114. if (!this.presMap['to']) {
  115. // Too early to send presence - not initialized
  116. return;
  117. }
  118. var pres = $pres({to: this.presMap['to'] });
  119. pres.c('x', {xmlns: this.presMap['xns']});
  120. if (this.password) {
  121. pres.c('password').t(this.password).up();
  122. }
  123. pres.up();
  124. // Send XEP-0115 'c' stanza that contains our capabilities info
  125. if (this.connection.caps) {
  126. this.connection.caps.node = this.xmpp.options.clientNode;
  127. pres.c('c', this.connection.caps.generateCapsAttrs()).up();
  128. }
  129. if (tokenPassword) {
  130. pres.c('token', { xmlns: 'http://jitsi.org/jitmeet/auth-token'})
  131. .t(tokenPassword).up();
  132. }
  133. parser.JSON2packet(this.presMap.nodes, pres);
  134. this.connection.send(pres);
  135. };
  136. ChatRoom.prototype.doLeave = function () {
  137. logger.log("do leave", this.myroomjid);
  138. var pres = $pres({to: this.myroomjid, type: 'unavailable' });
  139. this.presMap.length = 0;
  140. this.connection.send(pres);
  141. };
  142. ChatRoom.prototype.createNonAnonymousRoom = function () {
  143. // http://xmpp.org/extensions/xep-0045.html#createroom-reserved
  144. var getForm = $iq({type: 'get', to: this.roomjid})
  145. .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'})
  146. .c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  147. var self = this;
  148. this.connection.sendIQ(getForm, function (form) {
  149. if (!$(form).find(
  150. '>query>x[xmlns="jabber:x:data"]' +
  151. '>field[var="muc#roomconfig_whois"]').length) {
  152. logger.error('non-anonymous rooms not supported');
  153. return;
  154. }
  155. var formSubmit = $iq({to: this.roomjid, type: 'set'})
  156. .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
  157. formSubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  158. formSubmit.c('field', {'var': 'FORM_TYPE'})
  159. .c('value')
  160. .t('http://jabber.org/protocol/muc#roomconfig').up().up();
  161. formSubmit.c('field', {'var': 'muc#roomconfig_whois'})
  162. .c('value').t('anyone').up().up();
  163. self.connection.sendIQ(formSubmit);
  164. }, function (error) {
  165. logger.error("Error getting room configuration form");
  166. });
  167. };
  168. ChatRoom.prototype.onPresence = function (pres) {
  169. var from = pres.getAttribute('from');
  170. // Parse roles.
  171. var member = {};
  172. member.show = $(pres).find('>show').text();
  173. member.status = $(pres).find('>status').text();
  174. var tmp = $(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>item');
  175. member.affiliation = tmp.attr('affiliation');
  176. member.role = tmp.attr('role');
  177. // Focus recognition
  178. member.jid = tmp.attr('jid');
  179. member.isFocus = false;
  180. if (member.jid
  181. && member.jid.indexOf(this.moderator.getFocusUserJid() + "/") === 0) {
  182. member.isFocus = true;
  183. }
  184. $(pres).find(">x").remove();
  185. var nodes = [];
  186. parser.packet2JSON(pres, nodes);
  187. this.lastPresences[from] = nodes;
  188. var jibri = null;
  189. for(var i = 0; i < nodes.length; i++)
  190. {
  191. var node = nodes[i];
  192. switch(node.tagName)
  193. {
  194. case "nick":
  195. member.nick = node.value;
  196. if(!member.isFocus) {
  197. var displayName = !this.xmpp.options.displayJids
  198. ? member.nick : Strophe.getResourceFromJid(from);
  199. if (displayName && displayName.length > 0) {
  200. this.eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
  201. }
  202. logger.info("Display name: " + displayName, pres);
  203. }
  204. break;
  205. case "userId":
  206. member.id = node.value;
  207. break;
  208. case "email":
  209. member.email = node.value;
  210. break;
  211. case "bridgeIsDown":
  212. if(!this.bridgeIsDown) {
  213. this.bridgeIsDown = true;
  214. this.eventEmitter.emit(XMPPEvents.BRIDGE_DOWN);
  215. }
  216. break;
  217. case "jibri-recording-status":
  218. var jibri = node;
  219. default :
  220. this.processNode(node, from);
  221. }
  222. }
  223. if (from == this.myroomjid) {
  224. if (member.affiliation == 'owner')
  225. if (this.role !== member.role) {
  226. this.role = member.role;
  227. this.eventEmitter.emit(XMPPEvents.LOCAL_ROLE_CHANGED, this.role);
  228. }
  229. if (!this.joined) {
  230. this.joined = true;
  231. this.recording = new Recording(this.eventEmitter, this.connection,
  232. this.focusMucJid);
  233. console.log("(TIME) MUC joined:\t", window.performance.now());
  234. this.eventEmitter.emit(XMPPEvents.MUC_JOINED, from, member);
  235. }
  236. } else if (this.members[from] === undefined) {
  237. // new participant
  238. this.members[from] = member;
  239. logger.log('entered', from, member);
  240. if (member.isFocus) {
  241. this.focusMucJid = from;
  242. logger.info("Ignore focus: " + from + ", real JID: " + member.jid);
  243. }
  244. else {
  245. this.eventEmitter.emit(XMPPEvents.MUC_MEMBER_JOINED, from, member.id || member.email, member.nick);
  246. }
  247. } else {
  248. // Presence update for existing participant
  249. // Watch role change:
  250. if (this.members[from].role != member.role) {
  251. this.members[from].role = member.role;
  252. this.eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED, from, member.role);
  253. }
  254. // store the new display name
  255. if(member.displayName)
  256. this.members[from].displayName = member.displayName;
  257. }
  258. if(!member.isFocus)
  259. this.eventEmitter.emit(XMPPEvents.USER_ID_CHANGED, from, member.id || member.email);
  260. // Trigger status message update
  261. if (member.status) {
  262. this.eventEmitter.emit(XMPPEvents.PRESENCE_STATUS, from, member);
  263. }
  264. if(this.recording)
  265. {
  266. this.recording.handleJibriPresence(jibri);
  267. }
  268. };
  269. ChatRoom.prototype.processNode = function (node, from) {
  270. if(this.presHandlers[node.tagName])
  271. this.presHandlers[node.tagName](node, from);
  272. };
  273. ChatRoom.prototype.sendMessage = function (body, nickname) {
  274. var msg = $msg({to: this.roomjid, type: 'groupchat'});
  275. msg.c('body', body).up();
  276. if (nickname) {
  277. msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
  278. }
  279. this.connection.send(msg);
  280. this.eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, body);
  281. };
  282. ChatRoom.prototype.setSubject = function (subject) {
  283. var msg = $msg({to: this.roomjid, type: 'groupchat'});
  284. msg.c('subject', subject);
  285. this.connection.send(msg);
  286. logger.log("topic changed to " + subject);
  287. };
  288. ChatRoom.prototype.onParticipantLeft = function (jid) {
  289. delete this.lastPresences[jid];
  290. this.eventEmitter.emit(XMPPEvents.MUC_MEMBER_LEFT, jid);
  291. this.moderator.onMucMemberLeft(jid);
  292. };
  293. ChatRoom.prototype.onPresenceUnavailable = function (pres, from) {
  294. // room destroyed ?
  295. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]' +
  296. '>destroy').length) {
  297. var reason;
  298. var reasonSelect = $(pres).find(
  299. '>x[xmlns="http://jabber.org/protocol/muc#user"]' +
  300. '>destroy>reason');
  301. if (reasonSelect.length) {
  302. reason = reasonSelect.text();
  303. }
  304. this.xmpp.disposeConference(false);
  305. this.eventEmitter.emit(XMPPEvents.MUC_DESTROYED, reason);
  306. delete this.connection.emuc.rooms[Strophe.getBareJidFromJid(from)];
  307. return true;
  308. }
  309. // Status code 110 indicates that this notification is "self-presence".
  310. if (!$(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="110"]').length) {
  311. delete this.members[from];
  312. this.onParticipantLeft(from);
  313. }
  314. // If the status code is 110 this means we're leaving and we would like
  315. // to remove everyone else from our view, so we trigger the event.
  316. else if (Object.keys(this.members).length > 1) {
  317. for (var i in this.members) {
  318. var member = this.members[i];
  319. delete this.members[i];
  320. this.onParticipantLeft(member);
  321. }
  322. }
  323. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
  324. if (this.myroomjid === from) {
  325. this.xmpp.disposeConference(false);
  326. this.eventEmitter.emit(XMPPEvents.KICKED);
  327. }
  328. }
  329. };
  330. ChatRoom.prototype.onMessage = function (msg, from) {
  331. var nick =
  332. $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]')
  333. .text() ||
  334. Strophe.getResourceFromJid(from);
  335. var txt = $(msg).find('>body').text();
  336. var type = msg.getAttribute("type");
  337. if (type == "error") {
  338. this.eventEmitter.emit(XMPPEvents.CHAT_ERROR_RECEIVED,
  339. $(msg).find('>text').text(), txt);
  340. return true;
  341. }
  342. var subject = $(msg).find('>subject');
  343. if (subject.length) {
  344. var subjectText = subject.text();
  345. if (subjectText || subjectText === "") {
  346. this.eventEmitter.emit(XMPPEvents.SUBJECT_CHANGED, subjectText);
  347. logger.log("Subject is changed to " + subjectText);
  348. }
  349. }
  350. // xep-0203 delay
  351. var stamp = $(msg).find('>delay').attr('stamp');
  352. if (!stamp) {
  353. // or xep-0091 delay, UTC timestamp
  354. stamp = $(msg).find('>[xmlns="jabber:x:delay"]').attr('stamp');
  355. if (stamp) {
  356. // the format is CCYYMMDDThh:mm:ss
  357. var dateParts = stamp.match(/(\d{4})(\d{2})(\d{2}T\d{2}:\d{2}:\d{2})/);
  358. stamp = dateParts[1] + "-" + dateParts[2] + "-" + dateParts[3] + "Z";
  359. }
  360. }
  361. if (txt) {
  362. logger.log('chat', nick, txt);
  363. this.eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
  364. from, nick, txt, this.myroomjid, stamp);
  365. }
  366. };
  367. ChatRoom.prototype.onPresenceError = function (pres, from) {
  368. if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
  369. logger.log('on password required', from);
  370. this.eventEmitter.emit(XMPPEvents.PASSWORD_REQUIRED);
  371. } else if ($(pres).find(
  372. '>error[type="cancel"]>not-allowed[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
  373. var toDomain = Strophe.getDomainFromJid(pres.getAttribute('to'));
  374. if (toDomain === this.xmpp.options.hosts.anonymousdomain) {
  375. // enter the room by replying with 'not-authorized'. This would
  376. // result in reconnection from authorized domain.
  377. // We're either missing Jicofo/Prosody config for anonymous
  378. // domains or something is wrong.
  379. this.eventEmitter.emit(XMPPEvents.ROOM_JOIN_ERROR, pres);
  380. } else {
  381. logger.warn('onPresError ', pres);
  382. this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_ERROR, pres);
  383. }
  384. } else {
  385. logger.warn('onPresError ', pres);
  386. this.eventEmitter.emit(XMPPEvents.ROOM_CONNECT_ERROR, pres);
  387. }
  388. };
  389. ChatRoom.prototype.kick = function (jid) {
  390. var kickIQ = $iq({to: this.roomjid, type: 'set'})
  391. .c('query', {xmlns: 'http://jabber.org/protocol/muc#admin'})
  392. .c('item', {nick: Strophe.getResourceFromJid(jid), role: 'none'})
  393. .c('reason').t('You have been kicked.').up().up().up();
  394. this.connection.sendIQ(
  395. kickIQ,
  396. function (result) {
  397. logger.log('Kick participant with jid: ', jid, result);
  398. },
  399. function (error) {
  400. logger.log('Kick participant error: ', error);
  401. });
  402. };
  403. ChatRoom.prototype.lockRoom = function (key, onSuccess, onError, onNotSupported) {
  404. //http://xmpp.org/extensions/xep-0045.html#roomconfig
  405. var ob = this;
  406. this.connection.sendIQ($iq({to: this.roomjid, type: 'get'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'}),
  407. function (res) {
  408. if ($(res).find('>query>x[xmlns="jabber:x:data"]>field[var="muc#roomconfig_roomsecret"]').length) {
  409. var formsubmit = $iq({to: ob.roomjid, type: 'set'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
  410. formsubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  411. formsubmit.c('field', {'var': 'FORM_TYPE'}).c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up();
  412. formsubmit.c('field', {'var': 'muc#roomconfig_roomsecret'}).c('value').t(key).up().up();
  413. // Fixes a bug in prosody 0.9.+ https://code.google.com/p/lxmppd/issues/detail?id=373
  414. formsubmit.c('field', {'var': 'muc#roomconfig_whois'}).c('value').t('anyone').up().up();
  415. // FIXME: is muc#roomconfig_passwordprotectedroom required?
  416. ob.connection.sendIQ(formsubmit,
  417. onSuccess,
  418. onError);
  419. } else {
  420. onNotSupported();
  421. }
  422. }, onError);
  423. };
  424. ChatRoom.prototype.addToPresence = function (key, values) {
  425. values.tagName = key;
  426. this.presMap["nodes"].push(values);
  427. };
  428. ChatRoom.prototype.removeFromPresence = function (key) {
  429. for(var i = 0; i < this.presMap.nodes.length; i++)
  430. {
  431. if(key === this.presMap.nodes[i].tagName)
  432. this.presMap.nodes.splice(i, 1);
  433. }
  434. };
  435. ChatRoom.prototype.addPresenceListener = function (name, handler) {
  436. this.presHandlers[name] = handler;
  437. };
  438. ChatRoom.prototype.removePresenceListener = function (name) {
  439. delete this.presHandlers[name];
  440. };
  441. ChatRoom.prototype.isModerator = function () {
  442. return this.role === 'moderator';
  443. };
  444. ChatRoom.prototype.getMemberRole = function (peerJid) {
  445. if (this.members[peerJid]) {
  446. return this.members[peerJid].role;
  447. }
  448. return null;
  449. };
  450. ChatRoom.prototype.setJingleSession = function(session){
  451. this.session = session;
  452. this.session.room = this;
  453. };
  454. ChatRoom.prototype.removeStream = function (stream, callback) {
  455. if(!this.session)
  456. return;
  457. this.session.removeStream(stream, callback);
  458. };
  459. ChatRoom.prototype.switchStreams = function (stream, oldStream, callback, isAudio) {
  460. if(this.session) {
  461. // FIXME: will block switchInProgress on true value in case of exception
  462. this.session.switchStreams(stream, oldStream, callback, isAudio);
  463. } else {
  464. // We are done immediately
  465. logger.warn("No conference handler or conference not started yet");
  466. callback();
  467. }
  468. };
  469. ChatRoom.prototype.addStream = function (stream, callback) {
  470. if(this.session) {
  471. // FIXME: will block switchInProgress on true value in case of exception
  472. this.session.addStream(stream, callback);
  473. } else {
  474. // We are done immediately
  475. logger.warn("No conference handler or conference not started yet");
  476. callback();
  477. }
  478. };
  479. ChatRoom.prototype.setVideoMute = function (mute, callback, options) {
  480. var self = this;
  481. var localCallback = function (mute) {
  482. self.sendVideoInfoPresence(mute);
  483. if(callback)
  484. callback(mute);
  485. };
  486. if(this.session)
  487. {
  488. this.session.setVideoMute(
  489. mute, localCallback, options);
  490. }
  491. else {
  492. localCallback(mute);
  493. }
  494. };
  495. ChatRoom.prototype.setAudioMute = function (mute, callback) {
  496. //This will be for remote streams only
  497. // if (this.forceMuted && !mute) {
  498. // logger.info("Asking focus for unmute");
  499. // this.connection.moderate.setMute(this.connection.emuc.myroomjid, mute);
  500. // // FIXME: wait for result before resetting muted status
  501. // this.forceMuted = false;
  502. // }
  503. return this.sendAudioInfoPresence(mute, callback);
  504. };
  505. ChatRoom.prototype.addAudioInfoToPresence = function (mute) {
  506. this.removeFromPresence("audiomuted");
  507. this.addToPresence("audiomuted",
  508. {attributes:
  509. {"audions": "http://jitsi.org/jitmeet/audio"},
  510. value: mute.toString()});
  511. };
  512. ChatRoom.prototype.sendAudioInfoPresence = function(mute, callback) {
  513. this.addAudioInfoToPresence(mute);
  514. if(this.connection) {
  515. this.sendPresence();
  516. }
  517. if(callback)
  518. callback();
  519. };
  520. ChatRoom.prototype.addVideoInfoToPresence = function (mute) {
  521. this.removeFromPresence("videomuted");
  522. this.addToPresence("videomuted",
  523. {attributes:
  524. {"videons": "http://jitsi.org/jitmeet/video"},
  525. value: mute.toString()});
  526. };
  527. ChatRoom.prototype.sendVideoInfoPresence = function (mute) {
  528. this.addVideoInfoToPresence(mute);
  529. if(!this.connection)
  530. return;
  531. this.sendPresence();
  532. };
  533. ChatRoom.prototype.addListener = function(type, listener) {
  534. this.eventEmitter.on(type, listener);
  535. };
  536. ChatRoom.prototype.removeListener = function (type, listener) {
  537. this.eventEmitter.removeListener(type, listener);
  538. };
  539. ChatRoom.prototype.remoteStreamAdded = function(data, sid, thessrc) {
  540. if(this.lastPresences[data.peerjid])
  541. {
  542. var pres = this.lastPresences[data.peerjid];
  543. var audiomuted = filterNodeFromPresenceJSON(pres, "audiomuted");
  544. var videomuted = filterNodeFromPresenceJSON(pres, "videomuted");
  545. data.videomuted = ((videomuted.length > 0
  546. && videomuted[0]
  547. && videomuted[0]["value"] === "true")? true : false);
  548. data.audiomuted = ((audiomuted.length > 0
  549. && audiomuted[0]
  550. && audiomuted[0]["value"] === "true")? true : false);
  551. }
  552. this.eventEmitter.emit(XMPPEvents.REMOTE_STREAM_RECEIVED, data, sid, thessrc);
  553. };
  554. ChatRoom.prototype.getJidBySSRC = function (ssrc) {
  555. if (!this.session)
  556. return null;
  557. return this.session.getSsrcOwner(ssrc);
  558. };
  559. /**
  560. * Returns true if the recording is supproted and false if not.
  561. */
  562. ChatRoom.prototype.isRecordingSupported = function () {
  563. if(this.recording)
  564. return this.recording.isSupported();
  565. return false;
  566. };
  567. /**
  568. * Returns null if the recording is not supported, "on" if the recording started
  569. * and "off" if the recording is not started.
  570. */
  571. ChatRoom.prototype.getRecordingState = function () {
  572. if(this.recording)
  573. return this.recording.getState();
  574. return "off";
  575. }
  576. /**
  577. * Returns the url of the recorded video.
  578. */
  579. ChatRoom.prototype.getRecordingURL = function () {
  580. if(this.recording)
  581. return this.recording.getURL();
  582. return null;
  583. }
  584. /**
  585. * Starts/stops the recording
  586. * @param token token for authentication
  587. */
  588. ChatRoom.prototype.toggleRecording = function (token) {
  589. if(this.recording && this.moderator.isModerator())
  590. this.recording.toggleRecording(token);
  591. }
  592. module.exports = ChatRoom;