modified lib-jitsi-meet dev repo
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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. class RayoConnectionPlugin extends ConnectionPlugin {
  7. init(connection) {
  8. super.init(connection);
  9. this.connection.addHandler(
  10. this.onRayo.bind(this), RAYO_XMLNS, 'iq', 'set', null, null);
  11. }
  12. onRayo(iq) {
  13. logger.info('Rayo IQ', iq);
  14. }
  15. /* eslint-disable max-params */
  16. dial(to, from, roomName, roomPass, focusMucJid) {
  17. return new Promise((resolve, reject) => {
  18. if (!focusMucJid) {
  19. reject(new Error('Internal error!'));
  20. return;
  21. }
  22. const req = $iq({
  23. type: 'set',
  24. to: focusMucJid
  25. });
  26. req.c('dial', {
  27. xmlns: RAYO_XMLNS,
  28. to,
  29. from
  30. });
  31. req.c('header', {
  32. name: 'JvbRoomName',
  33. value: roomName
  34. }).up();
  35. if (roomPass && roomPass.length) {
  36. req.c('header', {
  37. name: 'JvbRoomPassword',
  38. value: roomPass
  39. }).up();
  40. }
  41. this.connection.sendIQ(
  42. req,
  43. result => {
  44. logger.info('Dial result ', result);
  45. // eslint-disable-next-line newline-per-chained-call
  46. const resource = $(result).find('ref').attr('uri');
  47. this.callResource = resource.substr('xmpp:'.length);
  48. logger.info(`Received call resource: ${this.callResource}`);
  49. resolve();
  50. },
  51. error => {
  52. logger.info('Dial error ', error);
  53. reject(error);
  54. });
  55. });
  56. }
  57. /* eslint-enable max-params */
  58. hangup() {
  59. return new Promise((resolve, reject) => {
  60. if (!this.callResource) {
  61. reject(new Error('No call in progress'));
  62. logger.warn('No call in progress');
  63. return;
  64. }
  65. const req = $iq({
  66. type: 'set',
  67. to: this.callResource
  68. });
  69. req.c('hangup', {
  70. xmlns: RAYO_XMLNS
  71. });
  72. this.connection.sendIQ(req, result => {
  73. logger.info('Hangup result ', result);
  74. this.callResource = null;
  75. resolve();
  76. }, error => {
  77. logger.info('Hangup error ', error);
  78. this.callResource = null;
  79. reject(new Error('Hangup error '));
  80. });
  81. });
  82. }
  83. }
  84. export default function() {
  85. Strophe.addConnectionPlugin('rayo', new RayoConnectionPlugin());
  86. }