您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

strophe.emuc.js 3.7KB

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