Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

strophe.rayo.js 3.0KB

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