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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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,
  15. 'presence', null, null, null, null);
  16. this.connection.addHandler(this.onPresenceUnavailable.bind(this),
  17. null, 'presence', 'unavailable', null);
  18. this.connection.addHandler(this.onPresenceError.bind(this), null,
  19. 'presence', 'error', null);
  20. this.connection.addHandler(this.onMessage.bind(this), null,
  21. 'message', null, null);
  22. this.connection.addHandler(this.onMute.bind(this),
  23. 'http://jitsi.org/jitmeet/audio', 'iq', 'set',null,null);
  24. },
  25. createRoom: function (jid, password, options, settings) {
  26. var roomJid = Strophe.getBareJidFromJid(jid);
  27. if (this.rooms[roomJid]) {
  28. logger.error("You are already in the room!");
  29. throw new Error("You are already in the room!");
  30. return;
  31. }
  32. this.rooms[roomJid] = new ChatRoom(this.connection, jid,
  33. password, XMPP, options, settings);
  34. return this.rooms[roomJid];
  35. },
  36. doLeave: function (jid) {
  37. delete this.rooms[jid];
  38. },
  39. onPresence: function (pres) {
  40. var from = pres.getAttribute('from');
  41. // What is this for? A workaround for something?
  42. if (pres.getAttribute('type')) {
  43. return true;
  44. }
  45. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  46. if(!room)
  47. return;
  48. // Parse status.
  49. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="201"]').length) {
  50. room.createNonAnonymousRoom();
  51. }
  52. room.onPresence(pres);
  53. return true;
  54. },
  55. onPresenceUnavailable: function (pres) {
  56. var from = pres.getAttribute('from');
  57. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  58. if(!room)
  59. return;
  60. room.onPresenceUnavailable(pres, from);
  61. return true;
  62. },
  63. onPresenceError: function (pres) {
  64. var from = pres.getAttribute('from');
  65. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  66. if(!room)
  67. return;
  68. room.onPresenceError(pres, from);
  69. return true;
  70. },
  71. onMessage: function (msg) {
  72. // FIXME: this is a hack. but jingle on muc makes nickchanges hard
  73. var from = msg.getAttribute('from');
  74. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  75. if(!room)
  76. return;
  77. room.onMessage(msg, from);
  78. return true;
  79. },
  80. setJingleSession: function (from, session) {
  81. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  82. if(!room)
  83. return;
  84. room.setJingleSession(session);
  85. },
  86. onMute: function(iq) {
  87. var from = iq.getAttribute('from');
  88. var room = this.rooms[Strophe.getBareJidFromJid(from)];
  89. if(!room)
  90. return;
  91. room.onMute(iq);
  92. return true;
  93. }
  94. });
  95. };