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.

strophe.emuc.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* jshint -W117 */
  2. /* a simple MUC connection plugin
  3. * can only handle a single MUC room
  4. */
  5. var logger = require("jitsi-meet-logger").getLogger(__filename);
  6. var ChatRoom = require("./ChatRoom");
  7. module.exports = function(XMPP) {
  8. Strophe.addConnectionPlugin('emuc', {
  9. connection: null,
  10. rooms: {},//map with the rooms
  11. init: function (conn) {
  12. this.connection = conn;
  13. // add handlers (just once)
  14. this.connection.addHandler(this.onPresence.bind(this), null, 'presence', null, null, null, null);
  15. this.connection.addHandler(this.onPresenceUnavailable.bind(this), null, 'presence', 'unavailable', null);
  16. this.connection.addHandler(this.onPresenceError.bind(this), null, 'presence', 'error', null);
  17. this.connection.addHandler(this.onMessage.bind(this), null, 'message', null, null);
  18. },
  19. createRoom: function (jid, password, options) {
  20. var roomJid = Strophe.getBareJidFromJid(jid);
  21. if (this.rooms[roomJid]) {
  22. logger.error("You are already in the room!");
  23. return;
  24. }
  25. this.rooms[roomJid] = new ChatRoom(this.connection, jid, password, XMPP, options);
  26. return this.rooms[roomJid];
  27. },
  28. doLeave: function (jid) {
  29. this.rooms[jid].doLeave();
  30. delete this.rooms[jid];
  31. },
  32. onPresence: function (pres) {
  33. var from = pres.getAttribute('from');
  34. // What is this for? A workaround for something?
  35. if (pres.getAttribute('type')) {
  36. return true;
  37. }
  38. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  39. if(!room)
  40. return;
  41. // Parse status.
  42. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="201"]').length) {
  43. room.createNonAnonymousRoom();
  44. }
  45. room.onPresence(pres);
  46. return true;
  47. },
  48. onPresenceUnavailable: function (pres) {
  49. var from = pres.getAttribute('from');
  50. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  51. if(!room)
  52. return;
  53. room.onPresenceUnavailable(pres, from);
  54. return true;
  55. },
  56. onPresenceError: function (pres) {
  57. var from = pres.getAttribute('from');
  58. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  59. if(!room)
  60. return;
  61. room.onPresenceError(pres, from);
  62. return true;
  63. },
  64. onMessage: function (msg) {
  65. // FIXME: this is a hack. but jingle on muc makes nickchanges hard
  66. var from = msg.getAttribute('from');
  67. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  68. if(!room)
  69. return;
  70. room.onMessage(msg, from);
  71. return true;
  72. },
  73. setJingleSession: function (from, session) {
  74. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  75. if(!room)
  76. return;
  77. room.setJingleSession(session);
  78. }
  79. });
  80. };