diff --git a/src/resource_requester.js b/src/resource_requester.js index 9e93500..db129c3 100644 --- a/src/resource_requester.js +++ b/src/resource_requester.js @@ -15,24 +15,23 @@ class ResourceRequester extends BaseObject { this.cdnRequester = new CDNRequester() this.p2pManager = new P2PManager(params) this.isInitialBuffer = true - this.sameSource = 0 + this.decodingError = false } requestResource(resource, bufferLength, callback) { - if (resource === this.resource) { - this.sameSource += 1 - } this.resource = resource this.callback = callback - if (bufferLength < Settings.lowBufferLength || this.isInitialBuffer || _.size(this.p2pManager.swarm.utils.contributors) === 0 || this.sameSource >= 3) { + if (this.decodingError) { + this.requestToCDN() + } else if (bufferLength < Settings.lowBufferLength || this.isInitialBuffer || _.size(this.p2pManager.swarm.utils.contributors) === 0) { this.requestToCDN() - this.sameSource = 0 } else { this.requestToP2P() } } requestToCDN() { + log.info("getting from CDN: " + this.resource) this.cdnRequester.requestResource(this.resource, this.callback) }