Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

strophe.emuc.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* a simple MUC connection plugin
  2. * can only handle a single MUC room
  3. */
  4. /* global $, Strophe */
  5. import { getLogger } from 'jitsi-meet-logger';
  6. const logger = getLogger(__filename);
  7. import ChatRoom from './ChatRoom';
  8. import { ConnectionPluginListenable } from './ConnectionPlugin';
  9. import XMPPEvents from '../../service/xmpp/XMPPEvents';
  10. class MucConnectionPlugin extends ConnectionPluginListenable {
  11. constructor(xmpp) {
  12. super();
  13. this.xmpp = xmpp;
  14. this.rooms = {};
  15. }
  16. init(connection) {
  17. super.init(connection);
  18. // add handlers (just once)
  19. this.connection.addHandler(this.onPresence.bind(this), null,
  20. 'presence', null, null, null, null);
  21. this.connection.addHandler(this.onPresenceUnavailable.bind(this),
  22. null, 'presence', 'unavailable', null);
  23. this.connection.addHandler(this.onPresenceError.bind(this), null,
  24. 'presence', 'error', null);
  25. this.connection.addHandler(this.onMessage.bind(this), null,
  26. 'message', null, null);
  27. this.connection.addHandler(this.onMute.bind(this),
  28. 'http://jitsi.org/jitmeet/audio', 'iq', 'set', null, null);
  29. }
  30. createRoom(jid, password, options) {
  31. const roomJid = Strophe.getBareJidFromJid(jid);
  32. if (this.rooms[roomJid]) {
  33. const errmsg = 'You are already in the room!';
  34. logger.error(errmsg);
  35. throw new Error(errmsg);
  36. }
  37. this.rooms[roomJid] = new ChatRoom(this.connection, jid,
  38. password, this.xmpp, options);
  39. this.eventEmitter.emit(
  40. XMPPEvents.EMUC_ROOM_ADDED, this.rooms[roomJid]);
  41. return this.rooms[roomJid];
  42. }
  43. doLeave(jid) {
  44. this.eventEmitter.emit(
  45. XMPPEvents.EMUC_ROOM_REMOVED, this.rooms[jid]);
  46. delete this.rooms[jid];
  47. }
  48. onPresence(pres) {
  49. const from = pres.getAttribute('from');
  50. // What is this for? A workaround for something?
  51. if (pres.getAttribute('type')) {
  52. return true;
  53. }
  54. const room = this.rooms[Strophe.getBareJidFromJid(from)];
  55. if (!room) {
  56. return;
  57. }
  58. // Parse status.
  59. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]'
  60. + '>status[code="201"]').length) {
  61. room.createNonAnonymousRoom();
  62. }
  63. room.onPresence(pres);
  64. return true;
  65. }
  66. onPresenceUnavailable(pres) {
  67. const from = pres.getAttribute('from');
  68. const room = this.rooms[Strophe.getBareJidFromJid(from)];
  69. if (!room) {
  70. return;
  71. }
  72. room.onPresenceUnavailable(pres, from);
  73. return true;
  74. }
  75. onPresenceError(pres) {
  76. const from = pres.getAttribute('from');
  77. const room = this.rooms[Strophe.getBareJidFromJid(from)];
  78. if (!room) {
  79. return;
  80. }
  81. room.onPresenceError(pres, from);
  82. return true;
  83. }
  84. onMessage(msg) {
  85. // FIXME: this is a hack. but jingle on muc makes nickchanges hard
  86. const from = msg.getAttribute('from');
  87. const room = this.rooms[Strophe.getBareJidFromJid(from)];
  88. if (!room) {
  89. return;
  90. }
  91. room.onMessage(msg, from);
  92. return true;
  93. }
  94. onMute(iq) {
  95. const from = iq.getAttribute('from');
  96. const room = this.rooms[Strophe.getBareJidFromJid(from)];
  97. if (!room) {
  98. return;
  99. }
  100. room.onMute(iq);
  101. return true;
  102. }
  103. }
  104. export default function(XMPP) {
  105. Strophe.addConnectionPlugin('emuc', new MucConnectionPlugin(XMPP));
  106. }