NICE DCV SDK not showing in full width and height

0

so i start my dcv session with dcv create-session --owner dcv --init init.sh elliot the screen is how dcv gets displayed on my frontend

on my code i have something like this:

import "./dcvjs/dcv.js";
let auth,
    connection,
    serverUrl;

console.log("Using NICE DCV Web Client SDK version " + dcv.version.versionStr);

function main() {
    console.log("Setting log level to INFO");
    dcv.setLogLevel(dcv.LogLevel.INFO);

    serverUrl = "https://IP:PORT";
    
    console.log("Starting authentication with", serverUrl);

    auth = dcv.authenticate(
        serverUrl,
        {
            promptCredentials: onPromptCredentials2,
            error: onError,
            success: onSuccess
        }
    );

window.main = main;

function onPromptCredentials(auth, challenge) {
    if (challengeHasField(challenge, "username") && challengeHasField(challenge, "password")) {
        auth.sendCredentials({ username: "YOURUSER", password: "YOUR_PW" });
    }
}

function challengeHasField(challenge, field) {
    return challenge.requiredCredentials.some(credential => credential.name === field);
}

function onError(auth, error) {
    console.log("Error during the authentication: ", error.message);
}

function onSuccess(auth, result) {
    let { sessionId, authToken } = { ...result[0] };

    connect(sessionId, authToken);
}

function connect(sessionId, authToken) {
    dcv.connect({
        url: serverUrl,
        sessionId: sessionId,
        authToken: authToken,
        divId: "dcv-display", // The div where the NICE DCV session will be rendered
        callbacks: {
            firstFrame: () => {
                console.log("First frame received");
                document.getElementById('form-container').style.display = 'none';
                document.getElementById('dcv-display').style.display = 'block';
                resizeDisplay(); // Ensure the display resizes when the first frame is received
                enterFullScreen(document.getElementById('dcv-display')); // Ensure full-screen mode
            },
            resize: () => {
                resizeDisplay(); // Resizes the display when the browser is resized
            }
        }
    }).then(function (conn) {
        // Request resolution explicitly after connection
        connection = conn;
        requestResolution(); // Explicitly ask for client resolution
    }).catch(function (error) {
        console.log("Connection failed with error " + error.message);
    });
}

function requestResolution() {
    const width = window.innerWidth;
    const height = window.innerHeight;
    console.log(`Requesting resolution change to ${width}x${height}`);
    // Send the resolution request to the server (NICE DCV server should handle this)
    connection.setResolution(width, height); // Assuming setResolution is supported in your SDK
}


function enterFullScreen(element) {
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    }
}

function resizeDisplay() {
    let display = document.getElementById('dcv-display');
    
    // Set the canvas size to match the viewport dimensions
    display.style.width = `${window.innerWidth}px`;
    display.style.height = `${window.innerHeight}px`;

    // Log the requested resolution
    console.log(`Requesting resolution change to ${window.innerWidth}x${window.innerHeight}`);
    
    // Request resolution change from the DCV server
    if (connection && connection.setResolution) {
        connection.setResolution(window.innerWidth, window.innerHeight)
            .then(() => {
                console.log(`Resolution successfully set to ${window.innerWidth}x${window.innerHeight}`);
            })
            .catch(err => {
                console.error('Failed to set resolution:', err);
            });
    } else {
        console.error('connection.setResolution is not available');
    }
}


function submitCredentials(e) {
    var credentials = {};
    fieldSet.childNodes.forEach(input => credentials[input.id] = input.value);
    auth.sendCredentials(credentials);
    e.preventDefault();
}

var fieldSet;

function createLoginForm() {
    var submitButton = document.createElement("button");

    submitButton.type = "submit";
    submitButton.textContent = "Login";

    var form = document.createElement("form");
    fieldSet = document.createElement("fieldset");

    form.onsubmit = submitCredentials;
    form.appendChild(fieldSet);
    form.appendChild(submitButton);

    document.body.appendChild(form);
}

function addInput(name) {
    var type = name === "password" ? "password" : "text";

    var inputField = document.createElement("input");
    inputField.name = name;
    inputField.id = name;
    inputField.placeholder = name;
    inputField.type = type;
    fieldSet.appendChild(inputField);
}

function onPromptCredentials2(_, credentialsChallenge) {
    createLoginForm();
    credentialsChallenge.requiredCredentials.forEach(challenge => addInput(challenge.name));
}

see images: Enter image description here

Enter image description here

how can i make this to be full width in the display, i see in the logs (from the image) it is setting the display to a small screen, but i want it to be full depending on the screen of the device i am using this on

Elliot
asked 5 days ago18 views
1 Answer
0
  1. Update your CSS: Make sure your CSS is set up to allow the DCV display to take up the full viewport. Add these styles:
html, body, #dcv-display {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
  1. Modify the resizeDisplay function: Update your resizeDisplay function to use the full viewport dimensions:
function resizeDisplay() {
let display = document.getElementById('dcv-display');

// Set the canvas size to match the viewport dimensions
display.style.width = '100vw';
display.style.height = '100vh';

// Get the actual dimensions of the display element
const displayRect = display.getBoundingClientRect();
const width = Math.floor(displayRect.width);
const height = Math.floor(displayRect.height);

console.log(`Requesting resolution change to ${width}x${height}`);

if (connection && connection.setResolution) {
connection.setResolution(width, height)
.then(() => {
console.log(`Resolution successfully set to ${width}x${height}`);
})
.catch(err => {
console.error('Failed to set resolution:', err);
});
} else {
console.error('connection.setResolution is not available');
}
}
  1. Call resizeDisplay on window resize: Add an event listener to handle window resizing:
window.addEventListener('resize', resizeDisplay);
  1. Update server-side configuration: Ensure that your NICE DCV server is configured to allow resolution changes. You may need to modify the server configuration to allow larger resolutions.

  2. Adjust the create-session command: When starting your DCV session, you can specify the initial resolution. Modify your command to use a larger initial resolution:

dcv create-session --owner dcv --init init.sh --max-concurrent-clients 1 --storage-root /home/dcv --resolution 1920x1080 elliot

Adjust the resolution (1920x1080 in this example) to match your desired initial size.

  1. Handle full-screen mode: Implement a function to request full-screen mode and call it when appropriate:
function requestFullScreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}

// Call this function when you want to enter full-screen mode
requestFullScreen(document.getElementById('dcv-display'));

By implementing these changes, your NICE DCV display should adjust to the full width and height of your device's screen. Remember to test on different devices and screen sizes to ensure it works as expected across various displays.

Sources
Connect to the head and login nodes through NICE DCV - AWS ParallelCluster
Starting Amazon DCV sessions - Amazon DCV
NICE DCV Releases Version 2019.0 with Multi-Monitor Support on Web Client

profile picture
answered 5 days ago
  • i know this is Ai generated, but there's no dcv command like --resolution

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions