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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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(self.call_resource) {
  24. reject(new Error("There is already started call!"));
  25. return;
  26. }
  27. if(!focusMucJid) {
  28. reject(new Error("Internal error!"));
  29. return;
  30. }
  31. var req = $iq(
  32. {
  33. type: 'set',
  34. to: focusMucJid
  35. }
  36. );
  37. req.c('dial',
  38. {
  39. xmlns: self.RAYO_XMLNS,
  40. to: to,
  41. from: from
  42. });
  43. req.c('header',
  44. {
  45. name: 'JvbRoomName',
  46. value: roomName
  47. }).up();
  48. if (roomPass !== null && roomPass.length) {
  49. req.c('header',
  50. {
  51. name: 'JvbRoomPassword',
  52. value: roomPass
  53. }).up();
  54. }
  55. self.connection.sendIQ(
  56. req,
  57. function (result) {
  58. logger.info('Dial result ', result);
  59. var resource = $(result).find('ref').attr('uri');
  60. self.call_resource =
  61. resource.substr('xmpp:'.length);
  62. logger.info(
  63. "Received call resource: " +
  64. self.call_resource);
  65. resolve();
  66. },
  67. function (error) {
  68. logger.info('Dial error ', error);
  69. reject(error);
  70. }
  71. );
  72. });
  73. },
  74. hangup: function () {
  75. var self = this;
  76. return new Promise(function (resolve, reject) {
  77. if (!self.call_resource) {
  78. reject(new Error("No call in progress"));
  79. logger.warn("No call in progress");
  80. return;
  81. }
  82. var req = $iq(
  83. {
  84. type: 'set',
  85. to: self.call_resource
  86. }
  87. );
  88. req.c('hangup',
  89. {
  90. xmlns: self.RAYO_XMLNS
  91. });
  92. self.connection.sendIQ(
  93. req,
  94. function (result) {
  95. logger.info('Hangup result ', result);
  96. self.call_resource = null;
  97. resolve();
  98. },
  99. function (error) {
  100. logger.info('Hangup error ', error);
  101. self.call_resource = null;
  102. reject(new Error('Hangup error '));
  103. }
  104. );
  105. });
  106. }
  107. }
  108. );
  109. };