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.

strophe.rayo.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* jshint -W117 */
  2. var logger = require("jitsi-meet-logger").getLogger(__filename);
  3. module.exports = function() {
  4. Strophe.addConnectionPlugin('rayo',
  5. {
  6. RAYO_XMLNS: 'urn:xmpp:rayo:1',
  7. connection: null,
  8. init: function (conn) {
  9. this.connection = conn;
  10. if (this.connection.disco) {
  11. this.connection.disco.addFeature('urn:xmpp:rayo:client:1');
  12. }
  13. this.connection.addHandler(
  14. this.onRayo.bind(this), this.RAYO_XMLNS, 'iq', 'set',
  15. null, null);
  16. },
  17. onRayo: function (iq) {
  18. logger.info("Rayo IQ", iq);
  19. },
  20. dial: function (to, from, roomName, roomPass, focusMucJid) {
  21. var self = this;
  22. return new Promise(function (resolve, reject) {
  23. if(!focusMucJid) {
  24. reject(new Error("Internal error!"));
  25. return;
  26. }
  27. var req = $iq(
  28. {
  29. type: 'set',
  30. to: focusMucJid
  31. }
  32. );
  33. req.c('dial',
  34. {
  35. xmlns: self.RAYO_XMLNS,
  36. to: to,
  37. from: from
  38. });
  39. req.c('header',
  40. {
  41. name: 'JvbRoomName',
  42. value: roomName
  43. }).up();
  44. if (roomPass !== null && roomPass.length) {
  45. req.c('header',
  46. {
  47. name: 'JvbRoomPassword',
  48. value: roomPass
  49. }).up();
  50. }
  51. self.connection.sendIQ(
  52. req,
  53. function (result) {
  54. logger.info('Dial result ', result);
  55. var resource = $(result).find('ref').attr('uri');
  56. self.call_resource =
  57. resource.substr('xmpp:'.length);
  58. logger.info(
  59. "Received call resource: " +
  60. self.call_resource);
  61. resolve();
  62. },
  63. function (error) {
  64. logger.info('Dial error ', error);
  65. reject(error);
  66. }
  67. );
  68. });
  69. },
  70. hangup: function () {
  71. var self = this;
  72. return new Promise(function (resolve, reject) {
  73. if (!self.call_resource) {
  74. reject(new Error("No call in progress"));
  75. logger.warn("No call in progress");
  76. return;
  77. }
  78. var req = $iq(
  79. {
  80. type: 'set',
  81. to: self.call_resource
  82. }
  83. );
  84. req.c('hangup',
  85. {
  86. xmlns: self.RAYO_XMLNS
  87. });
  88. self.connection.sendIQ(
  89. req,
  90. function (result) {
  91. logger.info('Hangup result ', result);
  92. self.call_resource = null;
  93. resolve();
  94. },
  95. function (error) {
  96. logger.info('Hangup error ', error);
  97. self.call_resource = null;
  98. reject(new Error('Hangup error '));
  99. }
  100. );
  101. });
  102. }
  103. }
  104. );
  105. };