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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. dial (to, from, roomName, roomPass, focusMucJid) {
  16. return new Promise((resolve, reject) => {
  17. if(!focusMucJid) {
  18. reject(new Error("Internal error!"));
  19. return;
  20. }
  21. const req = $iq({
  22. type: 'set',
  23. to: focusMucJid
  24. });
  25. req.c('dial', {
  26. xmlns: RAYO_XMLNS,
  27. to: to,
  28. from: from
  29. });
  30. req.c('header', {
  31. name: 'JvbRoomName',
  32. value: roomName
  33. }).up();
  34. if (roomPass && roomPass.length) {
  35. req.c('header', {
  36. name: 'JvbRoomPassword',
  37. value: roomPass
  38. }).up();
  39. }
  40. this.connection.sendIQ(req, (result) => {
  41. logger.info('Dial result ', result);
  42. let resource = $(result).find('ref').attr('uri');
  43. this.call_resource =
  44. resource.substr('xmpp:'.length);
  45. logger.info("Received call resource: " + this.call_resource);
  46. resolve();
  47. }, (error) => {
  48. logger.info('Dial error ', error);
  49. reject(error);
  50. });
  51. });
  52. }
  53. hangup () {
  54. return new Promise((resolve, reject) => {
  55. if (!this.call_resource) {
  56. reject(new Error("No call in progress"));
  57. logger.warn("No call in progress");
  58. return;
  59. }
  60. const req = $iq({
  61. type: 'set',
  62. to: this.call_resource
  63. });
  64. req.c('hangup', {
  65. xmlns: RAYO_XMLNS
  66. });
  67. this.connection.sendIQ(req, (result) => {
  68. logger.info('Hangup result ', result);
  69. this.call_resource = null;
  70. resolve();
  71. }, (error) => {
  72. logger.info('Hangup error ', error);
  73. this.call_resource = null;
  74. reject(new Error('Hangup error '));
  75. });
  76. });
  77. }
  78. }
  79. export default function() {
  80. Strophe.addConnectionPlugin('rayo', new RayoConnectionPlugin());
  81. }