mtprotoRequest.js 835 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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(buffer){
  27. }
  28. onResponse(buffer){
  29. }
  30. onException(exception){
  31. }
  32. }