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

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