@jxstjh/jhvideo
Version:
HTML5 jhvideo base on MPEG2-TS Stream Player
70 lines • 2.57 kB
JavaScript
/*
* Copyright (C) 2016 Bilibili. All Rights Reserved.
*
* @author zheng qian <xqq@xqq.im>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var ParamSeekHandler = /** @class */ (function () {
function ParamSeekHandler(paramStart, paramEnd) {
this._startName = paramStart;
this._endName = paramEnd;
}
ParamSeekHandler.prototype.getConfig = function (baseUrl, range) {
var url = baseUrl;
if (range.from !== 0 || range.to !== -1) {
var needAnd = true;
if (url.indexOf('?') === -1) {
url += '?';
needAnd = false;
}
if (needAnd) {
url += '&';
}
url += "".concat(this._startName, "=").concat(range.from.toString());
if (range.to !== -1) {
url += "&".concat(this._endName, "=").concat(range.to.toString());
}
}
return {
url: url,
headers: {}
};
};
ParamSeekHandler.prototype.removeURLParameters = function (seekedURL) {
var baseURL = seekedURL.split('?')[0];
var params = undefined;
var queryIndex = seekedURL.indexOf('?');
if (queryIndex !== -1) {
params = seekedURL.substring(queryIndex + 1);
}
var resultParams = '';
if (params != undefined && params.length > 0) {
var pairs = params.split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
var requireAnd = (i > 0);
if (pair[0] !== this._startName && pair[0] !== this._endName) {
if (requireAnd) {
resultParams += '&';
}
resultParams += pairs[i];
}
}
}
return (resultParams.length === 0) ? baseURL : baseURL + '?' + resultParams;
};
return ParamSeekHandler;
}());
export default ParamSeekHandler;
//# sourceMappingURL=param-seek-handler.js.map