简体   繁体   English

如何开始使用 NICE DCV SDK

[英]How to get started using NICE DCV SDK

I am trying out the NICE DCV SDK from AWS, documentation linkedhere But I can't figure out how to run the example given on the docs page.我正在试用来自 AWS 的NICE DCV SDK ,文档链接在这里但我无法弄清楚如何运行文档页面上给出的示例。 I tried running it in a node server but get this error:我尝试在节点服务器上运行它但出现此错误:

ReferenceError: self is not defined

So, it would be fantastic if someone could help me get started with the example .因此,如果有人可以帮助我开始使用该示例,那就太好了。

Edit: I tried simply opening the index.html from a browser as well.编辑:我也尝试从浏览器中简单地打开 index.html。

Simply copying the example from the Developer Guide, hence having:只需从开发人员指南中复制示例,因此具有:

index.html索引.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>DCV first connection</title>
    </head>
    <body>
        <script type="module" src="main.js"></script>
        <div id="dcv-display"></div>
    </body>
</html>

main.js main.js

import "./dcvjs/dcv.js";

let auth,
    connection,
    serverUrl;

function onPromptCredentials(auth, challenge) {
    // Let's check if in challenge we have a username and password request
    if (challengeHasField(challenge, "username") && challengeHasField(challenge, "password")) {
        auth.sendCredentials({username: "my_dcv_user", password: "my_password"})
    } else {
        // Challenge is requesting something else...
    }
}

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

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

// We connect to the first session returned
function onSuccess(_, result) {
    let {sessionId, authToken} = {...result[0]};
    connect(sessionId, authToken);
}

function connect (sessionId, authToken) {
    console.log(sessionId, authToken);
    dcv.connect({
        url: serverUrl,
        sessionId: sessionId,
        authToken: authToken,
        divId: "dcv-display",
        callbacks: {
            firstFrame: () => console.log("First frame received")
        }
    }).then(function (conn) {
        console.log("Connection established!");
        connection= conn;
    }).catch(function (error) {
        console.log("Connection failed with error " + error.message);
    });
}

function main () {
    console.log("Setting log level to INFO");
    dcv.setLogLevel(dcv.LogLevel.INFO);
    serverUrl = "https://your-dcv-server-url:port/";
    console.log("Starting authentication with", serverUrl);
    auth = dcv.authenticate(
        serverUrl,
        {
            promptCredentials: onPromptCredentials,
            error: onError,
            success: onSuccess
        }
    );
}

console.log("Using NICE DCV Web Client SDK version " + dcv.version.versionStr);
document.addEventListener('DOMContentLoaded', main);

changing the username , password and serverUrl , should work in a web environment.更改用户名密码serverUrl应该在 web 环境中工作。

I was also able to serve it from a node.js server set up as in the example here: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework我还能够从 node.js 服务器提供它,如下例所示: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework

We have created a demo of the NICE DCV SDK integration.我们创建了 NICE DCV SDK 集成的演示。 Please try it or download it from https://www.ni-sp.com/DCVSDK/请试用或从https://www.ni-sp.com/DCVSDK/下载

Here are the 2 files including the bonus login form and a couple of issues fixed (please adapt the serverUrl in main.js):以下是 2 个文件,包括奖励登录表单和一些已修复的问题(请调整 main.js 中的 serverUrl):

index.html索引.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>DCV first connection</title>
    </head>
    <body>
        <script type="module" src="main.js"></script>
        <div id="dcv-display"></div>
    </body>
</html>

main.js main.js

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

console.log("Using NICE DCV Web Client SDK version " + dcv.version.versionStr);
document.addEventListener('DOMContentLoaded', main);

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

    serverUrl = "https://your-dcv-server-url:port/";
    
    console.log("Starting authentication with", serverUrl);

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


function onPromptCredentials(auth, challenge) {
    // Let's check if in challege we have a username and password request
    if (challengeHasField(challenge, "username") && challengeHasField(challenge, "password")) {
        auth.sendCredentials({username: "YOURUSER", password: "YOUR_PW"})
    } else {
        // Challenge is requesting something else...
    }
}

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

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

// We connect to the first session returned
function onSuccess(auth, result) {
    let {sessionId, authToken} = {...result[0]};

    connect(sessionId, authToken);
}

function connect (sessionId, authToken) {
    console.log(sessionId, authToken);

    dcv.connect({
        url: serverUrl,
        sessionId: sessionId,
        authToken: authToken,
        divId: "dcv-display",
        callbacks: {
            firstFrame: () => console.log("First frame received")
        }
    }).then(function (conn) {
        console.log("Connection established!");
        connection= conn;
    }).catch(function (error) {
        console.log("Connection failed with error " + error.message);
    });
}


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));
}

If anyone is wondering that Ni-sp site works and not yours.如果有人想知道 Ni-sp 网站有效,而不是您的网站。 Here is solution:这是解决方案:

The web server & DCV Server both needs to have certificate assigned to them when both trust (most probably a internal root CA) and the client connecting to the Web server must have the root certificates so that it can validate the web server and DCV server certificates.当信任(很可能是内部根 CA)时,web 服务器和 DCV 服务器都需要分配证书,并且连接到 Web 服务器的客户端必须具有根证书,以便它可以验证 web 服务器和 DCV 服务器证书.

I tested it worked correctly.我测试它工作正常。 Without valid certificate you will get the exception "Error during the authentication: Failed to communicate with server dcv.js:2 [authentication] Auth WebSocket connection closed. Code 1006"如果没有有效的证书,您将收到异常“身份验证期间出错:无法与服务器 dcv.js 通信:2 [身份验证] Auth WebSocket 连接已关闭。代码 1006”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取 cloudformation 模板中的参数以使用 Amazon Go SDK 启动? - How to get parameters in cloudformation template to launch using Amazon Go SDK? 如何使用适用于 Delphi 的 Appercept AWS SDK 获取存储桶中的对象列表? - How to get list of objects in bucket, using Appercept AWS SDK for Delphi? 如何使用 javascript sdk 获取 aws lambda 调用计数 - how to get aws lambda invocation count using javascript sdk 如何使用模块 Web SDK 的版本 9 获取 Cloud Firestore 集合中的所有文档? - How do I get all documents in a Cloud Firestore collection using Version 9 of the Modular Web SDK? 如何使用 scala 和 aws-java-sdk 从 S3 存储桶中获取所有 S3ObjectSummary? - How to get all S3ObjectSummary from an S3 bucket using scala and the aws-java-sdk? 如何使用 aws-sdk-2.x 从 S3 存储桶中获取 object 的 S3 URL - How to get S3 URL for the object from S3 bucket using aws-sdk-2.x 如何使用 AWS 获取 aws cloudsearch 域的搜索端点 Java sdk - How to get aws cloudsearch domain's search endpoint using AWS Java sdk 如何使用 boto3 (python sdk) 获取 lambda 的指标日志洞察 - How to get metric log insights for lambdas using boto3 (python sdk) 如何使用 aws-sdk Javascript 获取 EC2 public ip - How to get EC2 public ip using aws-sdk Javascript 尝试使用 Python SDK 从 Azure 获取虚拟机列表 - Trying to get list of VMs from Azure using Python SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM