@@ -122,6 +122,30 @@ WaveformBuilder.prototype.init = function(options, callback) {
122
122
}
123
123
} ;
124
124
125
+ function hasValidContentRangeHeader ( xhr ) {
126
+ const contentRange = xhr . getResponseHeader ( 'content-range' ) ;
127
+
128
+ if ( ! contentRange ) {
129
+ return false ;
130
+ }
131
+
132
+ const matches = contentRange . match ( / ^ b y t e s ( \d + ) - ( \d + ) \/ ( \d + ) $ / ) ;
133
+
134
+ if ( matches && matches . length === 4 ) {
135
+ const firstPos = parseInt ( matches [ 1 ] , 10 ) ;
136
+ const lastPos = parseInt ( matches [ 2 ] , 10 ) ;
137
+ const length = parseInt ( matches [ 3 ] , 10 ) ;
138
+
139
+ if ( firstPos === 0 && ( lastPos + 1 ) === length ) {
140
+ return true ;
141
+ }
142
+
143
+ return false ;
144
+ }
145
+
146
+ return false ;
147
+ }
148
+
125
149
/* eslint-disable max-len */
126
150
127
151
/**
@@ -178,7 +202,10 @@ WaveformBuilder.prototype._getRemoteWaveformData = function(options, callback) {
178
202
return ;
179
203
}
180
204
181
- if ( this . status !== 200 ) {
205
+ // See https://github.com/bbc/peaks.js/issues/491
206
+
207
+ if ( this . status !== 200 &&
208
+ ! ( this . status === 206 && hasValidContentRangeHeader ( this ) ) ) {
182
209
callback (
183
210
new Error ( 'Unable to fetch remote data. HTTP status ' + this . status )
184
211
) ;
@@ -368,7 +395,10 @@ WaveformBuilder.prototype._requestAudioAndBuildWaveformData = function(url,
368
395
return ;
369
396
}
370
397
371
- if ( this . status !== 200 ) {
398
+ // See https://github.com/bbc/peaks.js/issues/491
399
+
400
+ if ( this . status !== 200 &&
401
+ ! ( this . status === 206 && hasValidContentRangeHeader ( this ) ) ) {
372
402
callback (
373
403
new Error ( 'Unable to fetch remote data. HTTP status ' + this . status )
374
404
) ;
0 commit comments