Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

strophe.rayo.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* jshint -W117 */
  17. module.exports = function() {
  18. Strophe.addConnectionPlugin('rayo',
  19. {
  20. RAYO_XMLNS: 'urn:xmpp:rayo:1',
  21. connection: null,
  22. init: function (conn) {
  23. this.connection = conn;
  24. if (this.connection.disco) {
  25. this.connection.disco.addFeature('urn:xmpp:rayo:client:1');
  26. }
  27. this.connection.addHandler(
  28. this.onRayo.bind(this), this.RAYO_XMLNS, 'iq', 'set', null, null);
  29. },
  30. onRayo: function (iq) {
  31. console.info("Rayo IQ", iq);
  32. },
  33. dial: function (to, from, roomName, roomPass) {
  34. var self = this;
  35. var req = $iq(
  36. {
  37. type: 'set',
  38. to: this.connection.emuc.focusMucJid
  39. }
  40. );
  41. req.c('dial',
  42. {
  43. xmlns: this.RAYO_XMLNS,
  44. to: to,
  45. from: from
  46. });
  47. req.c('header',
  48. {
  49. name: 'JvbRoomName',
  50. value: roomName
  51. }).up();
  52. if (roomPass !== null && roomPass.length) {
  53. req.c('header',
  54. {
  55. name: 'JvbRoomPassword',
  56. value: roomPass
  57. }).up();
  58. }
  59. this.connection.sendIQ(
  60. req,
  61. function (result) {
  62. console.info('Dial result ', result);
  63. var resource = $(result).find('ref').attr('uri');
  64. this.call_resource = resource.substr('xmpp:'.length);
  65. console.info(
  66. "Received call resource: " + this.call_resource);
  67. },
  68. function (error) {
  69. console.info('Dial error ', error);
  70. }
  71. );
  72. },
  73. hang_up: function () {
  74. if (!this.call_resource) {
  75. console.warn("No call in progress");
  76. return;
  77. }
  78. var self = this;
  79. var req = $iq(
  80. {
  81. type: 'set',
  82. to: this.call_resource
  83. }
  84. );
  85. req.c('hangup',
  86. {
  87. xmlns: this.RAYO_XMLNS
  88. });
  89. this.connection.sendIQ(
  90. req,
  91. function (result) {
  92. console.info('Hangup result ', result);
  93. self.call_resource = null;
  94. },
  95. function (error) {
  96. console.info('Hangup error ', error);
  97. self.call_resource = null;
  98. }
  99. );
  100. }
  101. }
  102. );
  103. };