Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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