1. 'use strict';
  2. const Base = require('./Base');
  3. /**
  4. * Represents a Call on WhatsApp
  5. * @extends {Base}
  6. */
  7. class Call extends Base {
  8. constructor(client, data) {
  9. super(client);
  10. if (data) this._patch(data);
  11. }
  12. _patch(data) {
  13. /**
  14. * Call ID
  15. * @type {string}
  16. */
  17. this.id = data.id;
  18. /**
  19. * From
  20. * @type {string}
  21. */
  22. this.from = data.peerJid;
  23. /**
  24. * Unix timestamp for when the call was created
  25. * @type {number}
  26. */
  27. this.timestamp = data.offerTime;
  28. /**
  29. * Is video
  30. * @type {boolean}
  31. */
  32. this.isVideo = data.isVideo;
  33. /**
  34. * Is Group
  35. * @type {boolean}
  36. */
  37. this.isGroup = data.isGroup;
  38. /**
  39. * Indicates if the call was sent by the current user
  40. * @type {boolean}
  41. */
  42. this.fromMe = data.outgoing;
  43. /**
  44. * Indicates if the call can be handled in waweb
  45. * @type {boolean}
  46. */
  47. this.canHandleLocally = data.canHandleLocally;
  48. /**
  49. * Indicates if the call Should be handled in waweb
  50. * @type {boolean}
  51. */
  52. this.webClientShouldHandle = data.webClientShouldHandle;
  53. /**
  54. * Object with participants
  55. * @type {object}
  56. */
  57. this.participants = data.participants;
  58. return super._patch(data);
  59. }
  60. /**
  61. * Reject the call
  62. */
  63. async reject() {
  64. return this.client.pupPage.evaluate((peerJid, id) => {
  65. return window.WWebJS.rejectCall(peerJid, id);
  66. }, this.from, this.id);
  67. }
  68. }
  69. module.exports = Call;