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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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', null, null);
  14. },
  15. onRayo: function (iq) {
  16. console.info("Rayo IQ", iq);
  17. },
  18. dial: function (to, from, roomName, roomPass) {
  19. var self = this;
  20. var req = $iq(
  21. {
  22. type: 'set',
  23. to: this.connection.emuc.focusMucJid
  24. }
  25. );
  26. req.c('dial',
  27. {
  28. xmlns: this.RAYO_XMLNS,
  29. to: to,
  30. from: from
  31. });
  32. req.c('header',
  33. {
  34. name: 'JvbRoomName',
  35. value: roomName
  36. }).up();
  37. if (roomPass !== null && roomPass.length) {
  38. req.c('header',
  39. {
  40. name: 'JvbRoomPassword',
  41. value: roomPass
  42. }).up();
  43. }
  44. this.connection.sendIQ(
  45. req,
  46. function (result) {
  47. console.info('Dial result ', result);
  48. var resource = $(result).find('ref').attr('uri');
  49. this.call_resource = resource.substr('xmpp:'.length);
  50. console.info(
  51. "Received call resource: " + this.call_resource);
  52. },
  53. function (error) {
  54. console.info('Dial error ', error);
  55. }
  56. );
  57. },
  58. hang_up: function () {
  59. if (!this.call_resource) {
  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. console.info('Hangup result ', result);
  78. self.call_resource = null;
  79. },
  80. function (error) {
  81. console.info('Hangup error ', error);
  82. self.call_resource = null;
  83. }
  84. );
  85. }
  86. }
  87. );
  88. };