Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

strophe.emuc.js 3.4KB

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