all files / lib/spdy-transport/protocol/base/ framer.js

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