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

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