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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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)
  21. {
  22. var self = this;
  23. var req = $iq(
  24. {
  25. type: 'set',
  26. to: config.hosts.call_control
  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. });
  40. this.connection.sendIQ(
  41. req,
  42. function (result)
  43. {
  44. console.info('Dial result ', result);
  45. var resource = $(result).find('ref').attr('uri');
  46. this.call_resource = resource.substr('xmpp:'.length);
  47. console.info(
  48. "Received call resource: " + this.call_resource);
  49. },
  50. function (error)
  51. {
  52. console.info('Dial error ', error);
  53. }
  54. );
  55. },
  56. hang_up: function ()
  57. {
  58. if (!this.call_resource)
  59. {
  60. console.warn("No call in progress");
  61. return;
  62. }
  63. var self = this;
  64. var req = $iq(
  65. {
  66. type: 'set',
  67. to: this.call_resource
  68. }
  69. );
  70. req.c('hangup',
  71. {
  72. xmlns: this.RAYO_XMLNS
  73. });
  74. this.connection.sendIQ(
  75. req,
  76. function (result)
  77. {
  78. console.info('Hangup result ', result);
  79. self.call_resource = null;
  80. },
  81. function (error)
  82. {
  83. console.info('Hangup error ', error);
  84. self.call_resource = null;
  85. }
  86. );
  87. }
  88. }
  89. );