Skip to content

Commit

Permalink
The most significant changes involve the modification of the `Websock…
Browse files Browse the repository at this point in the history
…ifyMiddleware.cs` and `ui.js` files to accept `vnc_host` and `vnc_port` as query parameters from the request, replacing the previously hardcoded `_hostname` and `_port`. Additionally, the `vnc.html` file has been updated to include input fields for `vnc_host` and `vnc_port`, enabling the user to specify these values in the UI.

1. The `WebsockifyMiddleware.cs` file has been updated to accept `vnc_host` and `vnc_port` as query parameters from the request. This replaces the previously hardcoded `_hostname` and `_port`. The `TcpClient` and `NetworkStream` objects are now wrapped in a `using` statement for better resource management.

2. The `ui.js` file has been modified so that the `UI` object initializes `vnc_host` and `vnc_port` settings from the URL. These settings are then retrieved and appended to the URL when creating a new `RFB` object.

3. The `vnc.html` file has been updated to include input fields for `vnc_host` and `vnc_port`. This allows the user to specify these values in the UI.
  • Loading branch information
seungyongshim committed Mar 2, 2024
1 parent 55f5e76 commit 5c64520
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/VncApp/Middleware/WebsockifyMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ public async Task InvokeAsync(HttpContext context)
WebSocket webSocket =
await context.WebSockets.AcceptWebSocketAsync();

TcpClient tcpClient = new TcpClient();
var vncHost = context.Request.Query["vnc_host"][0];
var vncPort = context.Request.Query["vnc_port"][0];

tcpClient.Connect(_hostname, _port);
using TcpClient tcpClient = new TcpClient();

NetworkStream networkStream = tcpClient.GetStream();
tcpClient.Connect(vncHost, int.Parse(vncPort));

using NetworkStream networkStream = tcpClient.GetStream();

Task receiveTask = Task.Run(async () =>
{
Expand Down
10 changes: 9 additions & 1 deletion src/VncApp/wwwroot/app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ const UI = {
}
}

/* Populate the controls if defaults are provided in the URL */
/* Populate the controls if defaults are provided in the URL */
UI.initSetting('vnc_host', window.location.hostname);
UI.initSetting('vnc_port', port);

UI.initSetting('host', window.location.hostname);
UI.initSetting('port', port);
UI.initSetting('encrypt', (window.location.protocol === "https:"));
Expand Down Expand Up @@ -1010,6 +1013,10 @@ const UI = {
const port = UI.getSetting('port');
const path = UI.getSetting('path');

const vnc_host = UI.getSetting('vnc_host');
const vnc_port = UI.getSetting('vnc_port');


if (typeof password === 'undefined') {
password = WebUtil.getConfigVar('password');
UI.reconnectPassword = password;
Expand Down Expand Up @@ -1040,6 +1047,7 @@ const UI = {
url += ':' + port;
}
url += '/' + path;
url += '?' + 'vnc_host=' + vnc_host + '&vnc_port=' + vnc_port;

UI.rfb = new RFB(document.getElementById('noVNC_container'), url,
{ shared: UI.getSetting('shared'),
Expand Down
8 changes: 8 additions & 0 deletions src/VncApp/wwwroot/vnc.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ <h1 class="noVNC_logo" translate="no"><span>no</span><br>VNC</h1>
<label for="noVNC_setting_port">Port:</label>
<input id="noVNC_setting_port" type="number">
</li>
<li>
<label for="noVNC_setting_vnc_host">VNCHost:</label>
<input id="noVNC_setting_vnc_host">
</li>
<li>
<label for="noVNC_setting_vnc_port">VNCPort:</label>
<input id="noVNC_setting_vnc_port" type="number">
</li>
<li>
<label for="noVNC_setting_path">Path:</label>
<input id="noVNC_setting_path" type="text" value="websockify">
Expand Down

0 comments on commit 5c64520

Please sign in to comment.