Add API to get WebSocket URL

This commit is contained in:
Ilia Ross
2024-06-04 19:07:34 +03:00
parent 5b31c7df84
commit af912d9539
3 changed files with 21 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@@ -13558,6 +13558,25 @@ $miniserv{'websockets_'.$wspath} = "host=127.0.0.1 port=$port wspath=/ user=$rem
return $port;
}
# get_miniserv_websocket_url(port, [host])
# Returns the URL for a websocket
sub get_miniserv_websocket_url
{
my ($port, $host) = @_;
my $ws_proto = lc($ENV{'HTTPS'}) eq 'on' ? 'wss' : 'ws';
my %miniserv;
&get_miniserv_config(\%miniserv);
my $http_host_conf = &trim($miniserv{'websocket_host'} || $host);
if ($http_host_conf) {
if ($http_host_conf !~ /^wss?:\/\//) {
$http_host_conf = "$ws_proto://$http_host_conf";
}
$http_host_conf =~ s/[\/]+$//g;
}
my $http_host = $http_host_conf || "$ws_proto://$ENV{'HTTP_HOST'}";
return "$http_host/$module_name/ws-$port";
}
# remove_miniserv_websocket(port)
# Remove old websocket
# from miniserv.conf

View File

@@ -200,18 +200,7 @@ $ENV{'SESSION_ID'} = $main::session_id;
" >$module_var_directory/websocket-connection-$port.out 2>&1 </dev/null");
# Open the terminal
my $ws_proto = lc($ENV{'HTTPS'}) eq 'on' ? 'wss' : 'ws';
my %miniserv;
&get_miniserv_config(\%miniserv);
my $http_host_conf = &trim($miniserv{'websocket_host'} || $config{'host'});
if ($http_host_conf) {
if ($http_host_conf !~ /^wss?:\/\//) {
$http_host_conf = "$ws_proto://$http_host_conf";
}
$http_host_conf =~ s/[\/]+$//g;
}
my $http_host = $http_host_conf || "$ws_proto://$ENV{'HTTP_HOST'}";
my $url = "$http_host/$module_name/ws-$port";
my $url = &get_miniserv_websocket_url($port, $config{'host'});
my $canvasAddon = $termlinks->{'js'}[3];
my $webGLAddon = $termlinks->{'js'}[4];
my $term_script = <<EOF;