@crestron/ch5-webxpanel

中文文档
2.8.0发布于 2024/01/09SEE LICENSE IN LICENSE.txtTypeScriptCommonJS零依赖近 30 天下载 3954

Browser control of ch5 components library

原始使用文档
文档目录14 节
  1. IMPORTANT: WebXPanel instance without import statement
  2. Installation
  3. Checking if WebXPanel is active
  4. Checking the WebXPanel version and build date
  5. Contract file
  6. WebXPanel logging
  7. Listening to WebXPanel Events
  8. Available events and their descriptions
  9. Listening to the LICENSE_WS event from a CH5 project
  10. Listening to the NOT_AUTHORIZED event from a CH5 project
  11. Listening to the CONNECT_CIP event from a CH5 project
  12. Listening to the DISCONNECT_CIP event from a CH5 project
  13. Test
  14. Build

Crestron WebXPanel - Getting Started

IMPORTANT: WebXPanel instance without import statement

Use WebXPanel.default to access the WebXPanel instance if the project doesn't use ES6 import statements.


Installation

Make your package available by running one of the following commands in the root folder of the WebXPanel project:

# NPM
npm link

Add WebXPanel to a CH5 Project by running one of the following commands in the root folder of the CH5 project:

# NPM
npm link "@crestron/ch5-webxpanel"

Please make sure that WebXPanel is the first library that is initialized in the CH5 Project!

All configuration parameters are optional. Only the parameters that need to be overwritten should be defined. Do not pass empty string values for parameters that should not be defined.

Example: (app.module.ts)

import WebXPanel, {WebXPanelConfigParams, isActive} from "@crestron/ch5-webxpanel";

const configuration: Partial<WebXPanelConfigParams> = {
    host: 'ip_address | hostname', // defaults to window.location.host
    ipId: '3|0x03', // string representing a hex value. Might contain "0x" or not. Defaults to "0x03"
    roomId: 'virtual_control_room_id', // defaults to empty string
};
// other rarely used options
//     port: 49200, // port for Secure WebSocket connection. Defaults to 49200
//     tokenUrl: 'https://url/cws/websocket/getWebSocketToken', // defaults to `${location.origin}/cws/websocket/getWebSocketToken`,
//     tokenSource: 'CSSelf|Fusion', // defaults to CSSelf

const webXPanelFactory = () => () => {
  if (isActive) {
    WebXPanel.initialize(configuration);
  }
}
// ...

@NgModule({
  // ...
  providers: [
    { provide: APP_INITIALIZER, useFactory: webXPanelFactory, multi: true },
    // ...
  ],
  // ...
})

// ...

Checking if WebXPanel is active

import {isActive} from "@crestron/ch5-webxpanel";

console.log(`WebXPanel isActive: ${isActive}`);

Checking the WebXPanel version and build date

import {getVersion, getBuildDate} from "@crestron/ch5-webxpanel";

console.log(`WebXPanel version: ${getVersion()}`);
console.log(`WebXPanel build date: ${getBuildDate()}`);

Contract file

The WebXPanel library expects to find a contract file named contract.cse2j at the following path in the CH5 project: ./config/contract.cse2j. If a contract file is not found at the specified path, WebXPanel will fallback to an empty contract file.


WebXPanel logging

The WebXPanel library provides a logger which is enabled by default, with the log level set to WARN. This can be changed from the CH5 project and logs can be seen in the browser console, if needed.

import { 
  getDebuggingState, 
  enableDebugging, 
  disableDebugging,
  getLogLevel,
  setLogLevel,
  LogLevel
} from "@crestron/ch5-webxpanel";

const isLoggingEnabled = getDebuggingState();

// to enable logging
enableDebugging();

// to disable debugging
disableDebugging();

// get current log level
getLogLevel();

// set log level to LOG
setLogLevel(LogLevel.LOG);


Listening to WebXPanel Events

All events dispatched by WebXPanel are CustomEvents. The relevant data within each event can be found in the detail property.

Available events and their descriptions

Event nameDispatch reasonOther information
CONNECT_WSA successful WebSocket connection has been establishedSimilar to WebSocket.onopen
DISCONNECT_WSThe WebSocket connection was disconnectedSimilar to WebSocket.onclose
ERROR_WSAn error occurred over websocketSimilar to WebSocket.onerror
FETCH_TOKEN_FAILEDFailed to fetch the fusion token
WEB_WORKER_FAILEDWorker is not supported in the current browser
CONNECT_CIPSuccessfully connected to Control System over CIP protocolProvides information about the current connection.
Not the same as CONNECT_WS
DISCONNECT_CIPDisconnected from the Control System over CIP protocolNot the same as DISCONNECT_WS
AUTHENTICATION_FAILEDFailed to authenticate to the Control System
AUTHENTICATION_REQUIREDAuthentication token is required by the Control System
LICENSE_WSA change occurred in the license (e.g. received license, license/trial period update)
NOT_AUTHORIZEDThe /cws/websocket/getWebSocketToken endpoint response is a redirect

Listening to the LICENSE_WS event from a CH5 project

import WebXPanel, {WebXPanelEvents} from "@crestron/ch5-webxpanel";

WebXPanel.addEventListener(WebXPanelEvents.LICENSE_WS, ({detail}) => {
  const {
    resourceAvailable,
    controlSystemSupportsLicense,
    licenseApplied,
    licenseNotRequired,
    licenseHasExpiry,
    licenseDaysRemaining,
    trialPeriod,
    trialPeriodDaysRemaining,
    licenseNotRequired
  } = detail;

  // other callback code
});

Listening to the NOT_AUTHORIZED event from a CH5 project


  WebXPanel.addEventListener(WebXPanelEvents.NOT_AUTHORIZED, ({detail}) => {
    const {redirectTo} = detail;
    console.log(`Received a redirect to: ${redirectTo}`);
    
    // login on the redirectTo page then try authenticating
    WebXPanel.authenticate();
    // or refreshing the page
    window.reload();
  });

Listening to the CONNECT_CIP event from a CH5 project


  WebXPanel.addEventListener(WebXPanelEvents.CONNECT_CIP, ({detail}) => {
    const {url, ipId, roomId, tokenSource, tokenUrl} = detail;
    console.log(`Connected to ${{url, ipId, roomId, tokenSource, tokenUrl}}`);
  });

Listening to the DISCONNECT_CIP event from a CH5 project


  WebXPanel.addEventListener(WebXPanelEvents.DISCONNECT_CIP, ({detail}) => {
    const {reason} = detail;
    console.log(`Disconnected from CIP. Reason: ${reason}`);
  });

Test

# NPM
npm test

Build

# NPM
npm build

版本与发布记录

@crestron/ch5-webxpanel 共发布 9 个版本,首次发布于 2021/02/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.8.0latest2024/01/092 年前
2.6.12023/10/273 年前
2.6.02023/10/243 年前
2.5.02023/09/063 年前
2.0.02022/08/224 年前
1.2.52021/11/194 年前

其他发布通道:latest-beta → 1.0.3-beta1。

关于 @crestron/ch5-webxpanel 的常见问题

@crestron/ch5-webxpanel 是什么?

Browser control of ch5 components library

如何安装 @crestron/ch5-webxpanel?

在项目目录运行 npm install @crestron/ch5-webxpanel,或使用 pnpm add / yarn add / bun add。

@crestron/ch5-webxpanel 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crestron/ch5-webxpanel 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@crestron/ch5-webxpanel 可以商用吗?

@crestron/ch5-webxpanel 使用 SEE LICENSE IN LICENSE.txt 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@crestron/ch5-webxpanel 的下载量有多少?

根据 npm 官方下载统计,@crestron/ch5-webxpanel 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,954 次,日均约 132 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crestron/ch5-webxpanel 还在维护吗?

最新版本 2.8.0 发布于 2024/01/09(2 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/02/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。