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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* jshint -W117 */
  2. var logger = require("jitsi-meet-logger").getLogger(__filename);
  3. module.exports = function() {
  4. Strophe.addConnectionPlugin('rayo',
  5. {
  6. RAYO_XMLNS: 'urn:xmpp:rayo:1',
  7. connection: null,
  8. init: function (conn) {
  9. this.connection = conn;
  10. if (this.connection.disco) {
  11. this.connection.disco.addFeature('urn:xmpp:rayo:client:1');
  12. }
  13. this.connection.addHandler(
  14. this.onRayo.bind(this),
  15. this.RAYO_XMLNS, 'iq', 'set', null, null);
  16. },
  17. onRayo: function (iq) {
  18. logger.info("Rayo IQ", iq);
  19. },
  20. dial: function (to, from, roomName, roomPass) {
  21. var self = this;
  22. var req = $iq(
  23. {
  24. type: 'set',
  25. to: this.connection.emuc.focusMucJid
  26. }
  27. );
  28. req.c('dial',
  29. {
  30. xmlns: this.RAYO_XMLNS,
  31. to: to,
  32. from: from
  33. });
  34. req.c('header',
  35. {
  36. name: 'JvbRoomName',
  37. value: roomName
  38. }).up();
  39. if (roomPass !== null && roomPass.length) {
  40. req.c('header',
  41. {
  42. name: 'JvbRoomPassword',
  43. value: roomPass
  44. }).up();
  45. }
  46. this.connection.sendIQ(
  47. req,
  48. function (result) {
  49. logger.info('Dial result ', result);
  50. var resource = $(result).find('ref').attr('uri');
  51. this.call_resource = resource.substr('xmpp:'.length);
  52. logger.info(
  53. "Received call resource: " + this.call_resource);
  54. },
  55. function (error) {
  56. logger.info('Dial error ', error);
  57. }
  58. );
  59. },
  60. hang_up: function () {
  61. if (!this.call_resource) {
  62. logger.warn("No call in progress");
  63. return;
  64. }
  65. var self = this;
  66. var req = $iq(
  67. {
  68. type: 'set',
  69. to: this.call_resource
  70. }
  71. );
  72. req.c('hangup',
  73. {
  74. xmlns: this.RAYO_XMLNS
  75. });
  76. this.connection.sendIQ(
  77. req,
  78. function (result) {
  79. logger.info('Hangup result ', result);
  80. self.call_resource = null;
  81. },
  82. function (error) {
  83. logger.info('Hangup error ', error);
  84. self.call_resource = null;
  85. }
  86. );
  87. }
  88. }
  89. );
  90. };