1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Replace deprecated String.prototype.substr() (#2948)

String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() or substring() which work similarily but aren't deprecated.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
This commit is contained in:
CommanderRoot 2022-03-07 01:02:27 +01:00 committed by GitHub
parent 84951cbc74
commit 8a75e8a165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 72 additions and 72 deletions

View file

@ -558,7 +558,7 @@ scApp.filter("sc_filter_number", function(){
scApp.filter("sc_filter_less", function(){
return function(v) {
return v? (v.length > 15? v.substr(0, 15) + "...":v):v;
return v? (v.length > 15? v.slice(0, 15) + "...":v):v;
};
});
@ -636,7 +636,7 @@ scApp.provider("$sc_server", [function(){
var $location = self.$location;
var url = $location.absUrl();
if (url.indexOf('?') > 0) {
url = url.substr(0, url.indexOf('?'));
url = url.slice(0, url.indexOf('?'));
}
url += '?';

View file

@ -158,11 +158,11 @@ function system_string_trim(str, flag) {
}
while (system_string_startswith(str, flag)) {
str = str.substr(flag.length);
str = str.slice(flag.length);
}
while (system_string_endswith(str, flag)) {
str = str.substr(0, str.length - flag.length);
str = str.slice(0, str.length - flag.length);
}
return str;
@ -227,8 +227,8 @@ function parse_query_string(){
obj.dir = "/";
obj.filename = "";
} else {
obj.dir = obj.pathname.substr(0, obj.pathname.lastIndexOf("/"));
obj.filename = obj.pathname.substr(obj.pathname.lastIndexOf("/"));
obj.dir = obj.pathname.slice(0, obj.pathname.lastIndexOf("/"));
obj.filename = obj.pathname.slice(obj.pathname.lastIndexOf("/"));
}
// pure user query object.
@ -298,19 +298,19 @@ function parse_rtmp_url(rtmp_url) {
.replace("rtc://", "http://");
var vhost = a.hostname;
var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
var stream = a.pathname.substr(a.pathname.lastIndexOf("/") + 1);
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
// parse the vhost in the params of app, that srs supports.
app = app.replace("...vhost...", "?vhost=");
if (app.indexOf("?") >= 0) {
var params = app.substr(app.indexOf("?"));
app = app.substr(0, app.indexOf("?"));
var params = app.slice(app.indexOf("?"));
app = app.slice(0, app.indexOf("?"));
if (params.indexOf("vhost=") > 0) {
vhost = params.substr(params.indexOf("vhost=") + "vhost=".length);
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
if (vhost.indexOf("&") > 0) {
vhost = vhost.substr(0, vhost.indexOf("&"));
vhost = vhost.slice(0, vhost.indexOf("&"));
}
}
}
@ -327,7 +327,7 @@ function parse_rtmp_url(rtmp_url) {
// parse the schema
var schema = "rtmp";
if (rtmp_url.indexOf("://") > 0) {
schema = rtmp_url.substr(0, rtmp_url.indexOf("://"));
schema = rtmp_url.slice(0, rtmp_url.indexOf("://"));
}
var port = a.port;

View file

@ -81,7 +81,7 @@ function build_default_flv_url() {
}
uri += "/" + app + "/" + stream + "?" + queries.join('&');
while (uri.indexOf("?") === uri.length - 1) {
uri = uri.substr(0, uri.length - 1);
uri = uri.slice(0, uri.length - 1);
}
return uri;
@ -110,7 +110,7 @@ function build_default_rtc_url(query) {
var uri = "webrtc://" + server + api + "/" + app + "/" + stream + "?" + queries.join('&');
while (uri.lastIndexOf("?") === uri.length - 1) {
uri = uri.substr(0, uri.length - 1);
uri = uri.slice(0, uri.length - 1);
}
return uri;

View file

@ -148,7 +148,7 @@ function SrsRtcPublisherAsync() {
return {
apiUrl: apiUrl, streamUrl: streamUrl, schema: schema, urlObject: urlObject, port: port,
tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).substr(0, 7)
tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0, 7)
};
},
parse: function (url) {
@ -159,19 +159,19 @@ function SrsRtcPublisherAsync() {
.replace("rtc://", "http://");
var vhost = a.hostname;
var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
var stream = a.pathname.substr(a.pathname.lastIndexOf("/") + 1);
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
// parse the vhost in the params of app, that srs supports.
app = app.replace("...vhost...", "?vhost=");
if (app.indexOf("?") >= 0) {
var params = app.substr(app.indexOf("?"));
app = app.substr(0, app.indexOf("?"));
var params = app.slice(app.indexOf("?"));
app = app.slice(0, app.indexOf("?"));
if (params.indexOf("vhost=") > 0) {
vhost = params.substr(params.indexOf("vhost=") + "vhost=".length);
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
if (vhost.indexOf("&") > 0) {
vhost = vhost.substr(0, vhost.indexOf("&"));
vhost = vhost.slice(0, vhost.indexOf("&"));
}
}
}
@ -188,7 +188,7 @@ function SrsRtcPublisherAsync() {
// parse the schema
var schema = "rtmp";
if (url.indexOf("://") > 0) {
schema = url.substr(0, url.indexOf("://"));
schema = url.slice(0, url.indexOf("://"));
}
var port = a.port;
@ -383,7 +383,7 @@ function SrsRtcPlayerAsync() {
return {
apiUrl: apiUrl, streamUrl: streamUrl, schema: schema, urlObject: urlObject, port: port,
tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).substr(0, 7)
tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0, 7)
};
},
parse: function (url) {
@ -394,19 +394,19 @@ function SrsRtcPlayerAsync() {
.replace("rtc://", "http://");
var vhost = a.hostname;
var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
var stream = a.pathname.substr(a.pathname.lastIndexOf("/") + 1);
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
// parse the vhost in the params of app, that srs supports.
app = app.replace("...vhost...", "?vhost=");
if (app.indexOf("?") >= 0) {
var params = app.substr(app.indexOf("?"));
app = app.substr(0, app.indexOf("?"));
var params = app.slice(app.indexOf("?"));
app = app.slice(0, app.indexOf("?"));
if (params.indexOf("vhost=") > 0) {
vhost = params.substr(params.indexOf("vhost=") + "vhost=".length);
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
if (vhost.indexOf("&") > 0) {
vhost = vhost.substr(0, vhost.indexOf("&"));
vhost = vhost.slice(0, vhost.indexOf("&"));
}
}
}
@ -423,7 +423,7 @@ function SrsRtcPlayerAsync() {
// parse the schema
var schema = "rtmp";
if (url.indexOf("://") > 0) {
schema = url.substr(0, url.indexOf("://"));
schema = url.slice(0, url.indexOf("://"));
}
var port = a.port;

View file

@ -158,11 +158,11 @@ function system_string_trim(str, flag) {
}
while (system_string_startswith(str, flag)) {
str = str.substr(flag.length);
str = str.slice(flag.length);
}
while (system_string_endswith(str, flag)) {
str = str.substr(0, str.length - flag.length);
str = str.slice(0, str.length - flag.length);
}
return str;
@ -227,8 +227,8 @@ function parse_query_string(){
obj.dir = "/";
obj.filename = "";
} else {
obj.dir = obj.pathname.substr(0, obj.pathname.lastIndexOf("/"));
obj.filename = obj.pathname.substr(obj.pathname.lastIndexOf("/"));
obj.dir = obj.pathname.slice(0, obj.pathname.lastIndexOf("/"));
obj.filename = obj.pathname.slice(obj.pathname.lastIndexOf("/"));
}
// pure user query object.
@ -298,19 +298,19 @@ function parse_rtmp_url(rtmp_url) {
.replace("rtc://", "http://");
var vhost = a.hostname;
var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
var stream = a.pathname.substr(a.pathname.lastIndexOf("/") + 1);
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
// parse the vhost in the params of app, that srs supports.
app = app.replace("...vhost...", "?vhost=");
if (app.indexOf("?") >= 0) {
var params = app.substr(app.indexOf("?"));
app = app.substr(0, app.indexOf("?"));
var params = app.slice(app.indexOf("?"));
app = app.slice(0, app.indexOf("?"));
if (params.indexOf("vhost=") > 0) {
vhost = params.substr(params.indexOf("vhost=") + "vhost=".length);
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
if (vhost.indexOf("&") > 0) {
vhost = vhost.substr(0, vhost.indexOf("&"));
vhost = vhost.slice(0, vhost.indexOf("&"));
}
}
}
@ -327,7 +327,7 @@ function parse_rtmp_url(rtmp_url) {
// parse the schema
var schema = "rtmp";
if (rtmp_url.indexOf("://") > 0) {
schema = rtmp_url.substr(0, rtmp_url.indexOf("://"));
schema = rtmp_url.slice(0, rtmp_url.indexOf("://"));
}
var port = a.port;

View file

@ -556,19 +556,19 @@
.replace("rtc://", "http://");
var vhost = a.hostname;
var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
var stream = a.pathname.substr(a.pathname.lastIndexOf("/") + 1);
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
// parse the vhost in the params of app, that srs supports.
app = app.replace("...vhost...", "?vhost=");
if (app.indexOf("?") >= 0) {
var params = app.substr(app.indexOf("?"));
app = app.substr(0, app.indexOf("?"));
var params = app.slice(app.indexOf("?"));
app = app.slice(0, app.indexOf("?"));
if (params.indexOf("vhost=") > 0) {
vhost = params.substr(params.indexOf("vhost=") + "vhost=".length);
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
if (vhost.indexOf("&") > 0) {
vhost = vhost.substr(0, vhost.indexOf("&"));
vhost = vhost.slice(0, vhost.indexOf("&"));
}
}
}
@ -585,7 +585,7 @@
// parse the schema
var schema = "rtmp";
if (url.indexOf("://") > 0) {
schema = url.substr(0, url.indexOf("://"));
schema = url.slice(0, url.indexOf("://"));
}
var port = a.port;

View file

@ -56,7 +56,7 @@
url = window.location.href.replace('http:', 'https:');
}
url = url.substr(0, url.lastIndexOf('/')) + '/srs_publisher_flash.html';
url = url.substring(0, url.lastIndexOf('/')) + '/srs_publisher_flash.html';
$('#https_publisher').attr('href', url);
});
</script>

View file

@ -335,7 +335,7 @@
$("#btn_publish").click(on_user_publish);
// for publish, we use randome stream name.
$("#txt_url").val($("#txt_url").val() + "." + Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).substr(0, 7));
$("#txt_url").val($("#txt_url").val() + "." + Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0, 7));
// start the publisher.
srs_publisher = new SrsPublisher("local_publisher", 430, 185);