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 3.1KB

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