e275934535209178088817ce5efae9d19ba9dc3873c775fdbb76b06442c58f637e7354a60c2880fd5bdfdf617ce2bdcc142fd87ce4eef5a6387a02a9ad58e3 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict'
  2. var util = require('util')
  3. var transport = require('../../../spdy-transport')
  4. var base = require('./')
  5. var Scheduler = base.Scheduler
  6. function Framer (options) {
  7. Scheduler.call(this)
  8. this.version = null
  9. this.compress = null
  10. this.window = options.window
  11. this.timeout = options.timeout
  12. // Wait for `enablePush`
  13. this.pushEnabled = null
  14. }
  15. util.inherits(Framer, Scheduler)
  16. module.exports = Framer
  17. Framer.prototype.setVersion = function setVersion (version) {
  18. this.version = version
  19. this.emit('version')
  20. }
  21. Framer.prototype.setCompression = function setCompresion (pair) {
  22. this.compress = new transport.utils.LockStream(pair.compress)
  23. }
  24. Framer.prototype.enablePush = function enablePush (enable) {
  25. this.pushEnabled = enable
  26. this.emit('_pushEnabled')
  27. }
  28. Framer.prototype._checkPush = function _checkPush (callback) {
  29. if (this.pushEnabled === null) {
  30. this.once('_pushEnabled', function () {
  31. this._checkPush(callback)
  32. })
  33. return
  34. }
  35. var err = null
  36. if (!this.pushEnabled) {
  37. err = new Error('PUSH_PROMISE disabled by other side')
  38. }
  39. process.nextTick(function () {
  40. return callback(err)
  41. })
  42. }
  43. Framer.prototype._resetTimeout = function _resetTimeout () {
  44. if (this.timeout) {
  45. this.timeout.reset()
  46. }
  47. }