mtprotoRequest.js 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class MTProtoRequest {
  2. constructor() {
  3. this.sent = false;
  4. this.msgId = 0; //long
  5. this.sequence = 0;
  6. this.dirty = false;
  7. this.sendTime = 0;
  8. this.confirmReceived = false;
  9. // These should be overrode
  10. this.constructorId = 0;
  11. this.confirmed = false;
  12. this.responded = false;
  13. }
  14. // these should not be overrode
  15. onSendSuccess() {
  16. this.sendTime = new Date().getTime();
  17. this.sent = true;
  18. }
  19. onConfirm() {
  20. this.confirmReceived = true;
  21. }
  22. needResend() {
  23. return this.dirty || (this.confirmed && !this.confirmReceived && new Date().getTime() - this.sendTime > 3000);
  24. }
  25. // These should be overrode
  26. onSend() {
  27. throw Error("Not overload " + this.constructor.name);
  28. }
  29. onResponse(buffer) {
  30. }
  31. onException(exception) {
  32. }
  33. }
  34. module.exports = MTProtoRequest;