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.

rayo.js 2.8KB

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