Skip to content

Commit bce99c9

Browse files
committed
Fixed documentation mistakes
1 parent f03f42f commit bce99c9

3 files changed

Lines changed: 58 additions & 26 deletions

File tree

DOCUMENTATION.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Before using the CDP Logger Client, make sure you have the following:
8282

8383
- **ProtoBuf JS** – The library depends on `protobufjs` (included as an npm dependency). If you installed via npm and are using a bundler or Node, this will be installed automatically. If you are using direct script includes, include the `protobuf.min.js` as shown above.
8484

85-
- **CDP Logger API Compatibility** – As noted, the target CDP Logger should be running a version that supports the queries you need. Basic data queries work on older versions (3.0+), but features like tags and advanced event filtering require newer CDP releases (CDP 4.12 for tags support, etc.). If you’re running an older CDP version and some API calls fail or are not supported, consider upgrading CDP Studio or limiting to the supported features.
85+
- **CDP Logger API Compatibility** – As noted, the target CDP Logger should be running a version that supports the queries you need. Basic data queries work on older versions (CDP 4.3+), but features like tags and advanced event filtering require newer CDP releases (CDP 4.12 for tags support, etc.). If you’re running an older CDP version and some API calls fail or are not supported, consider upgrading CDP Studio or limiting to the supported features.
8686

8787
## Setup and Configuration
8888

@@ -149,7 +149,6 @@ A few notes on the above example:
149149
You can also request historical **data points** for one or more signals using `client.requestDataPoints(names, startTimeSec, endTimeSec, numberOfPoints)`. For example:
150150

151151
```js
152-
// Assume we got `limits` from requestLogLimits (which provides start and end of log):
153152
const limits = await client.requestLogLimits();
154153
const start = limits.startS;
155154
const end = limits.endS;
@@ -175,15 +174,15 @@ The above demonstrates retrieving 100 aggregated data points between the earlies
175174
Finally, to retrieve **events**, you can use `client.requestEvents(query)` along with constructing a query object. You can also use `client.countEvents(query)` to just get the count. Here’s a brief Node example for events:
176175

177176
```js
178-
const query = {
177+
const query = { // Note: all query arguments are optional
179178
senderConditions: [
180179
{ value: "MyApp.AlarmManager", matchType: MatchType.Exact }
181180
],
182181
dataConditions: {
183182
// Assume events have a field "Text" and we want those containing "Overheat"
184183
Text: ["Overheat*"] // '*' wildcard is the default option
185184
},
186-
timeRangeStart: Date.now()/1000 - 24*3600, // (optional) last 24 hours in seconds (if time filtering desired)
185+
timeRangeStart: Date.now()/1000 - 24*3600, // last 24 hours in seconds (if time filtering desired)
187186
limit: 50, // max 50 events
188187
offset: 0, // start from the first match
189188
flags: EventQueryFlags.NewestFirst // get newest events first
@@ -218,7 +217,7 @@ Using the client in a browser is similar, except you don’t need to polyfill We
218217

219218
<script>
220219
// Once scripts are loaded, use the global cdplogger
221-
const client = new cdplogger.Client("ws://localhost:17000"); // connect to logger
220+
const client = new cdplogger.Client(window.location.hostname + ":17000"); // Connect to logger
222221
223222
// Example: fetch API version
224223
client.requestApiVersion().then(version => {
@@ -238,11 +237,9 @@ As shown, the usage is very much the same as in Node. The `cdplogger.Client` cla
238237

239238
A few browser-specific notes:
240239

241-
- **Security:** If your CDP Logger is served over HTTPS (or you are accessing it from an HTTPS page), use `wss://` for the WebSocket URL to avoid mixed content issues. Ensure the CDP Logger is configured with TLS if needed. For local testing with `http://localhost` you can use `ws://` without issues.
242-
243240
- **CORS/WebSocket Policy:** WebSocket connections are not subject to the same-origin policy in the way XHR/Fetch are, but some environments might still require the server to accept the connection. The CDP Logger’s WebSocket server should accept connections from any origin by default. If you encounter issues connecting from a web page, check if any firewall or network configuration is blocking the websocket port.
244241

245-
- **Performance:** Retrieving a lot of data points or events in one go can be heavy for the browser. If you plan to visualize large data sets, consider using pagination (e.g., request events 100 at a time using `offset`) or downsampling data points via the `numberOfPoints` parameter. The library itself streams the data efficiently, but rendering thousands of points in the DOM can be slow, so plan accordingly.
242+
- **Performance:** Retrieving a lot of data points or events in one go can be heavy for the browser. If you plan to visualize large data sets, consider using pagination (e.g., request events 100 at a time using `offset`) or downsampling data points via the `noOfDataPoints` parameter. The library itself streams the data efficiently, but rendering thousands of points in the DOM can be slow, so plan accordingly.
246243

247244
## How to Run Tests
248245

@@ -293,4 +290,4 @@ This project is open-source software licensed under the **MIT License**. See the
293290

294291
---
295292

296-
*Thank you for using the JavaScript CDP Logger Client!* We hope this library makes it easier to integrate CDP Studio’s powerful logging capabilities into your own tools and applications. ([GitHub - CDPTechnologies/JavascriptCDPLoggerClient: A simple Javascript interface to communicate with CDP applications containing a CDPLogger component to retrieve historic data.](https://github.com/CDPTechnologies/JavascriptCDPLoggerClient#:~:text=A%20simple%20JavaScript%20interface%20for,com))
293+
*Thank you for using the JavaScript CDP Logger Client!* We hope this library makes it easier to integrate CDP Studio’s powerful logging capabilities into your own tools and applications. ([GitHub - CDPTechnologies/JavascriptCDPLoggerClient](https://github.com/CDPTechnologies/JavascriptCDPLoggerClient#:~:text=A%20simple%20JavaScript%20interface%20for,com))

QUICKSTART.md

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide demonstrates how to get started with the CDPLogger Client in both **N
44

55
## Documentation
66

7-
For documentation on the JS logger see [DOCUMENTATION.md](DOCUMENTATION.md)
7+
For documentation on the JS logger client see [DOCUMENTATION.md](DOCUMENTATION.md)
88

99
## Overview
1010

@@ -14,14 +14,14 @@ For documentation on the JS logger see [DOCUMENTATION.md](DOCUMENTATION.md)
1414
- Requires a WebSocket polyfill (such as the `ws` package) since Node.js lacks a native WebSocket.
1515

1616
- **Browser Version:**
17-
- Uses the browsers native WebSocket.
17+
- Uses the browser's native WebSocket.
1818
- Obtains protobuf definitions from the global scope via `window.root` (set by including `containerPb.js`).
1919

2020
## Installation
2121

2222
### For Node.js
2323

24-
Install the CDPLogger Client and a WebSocket polyfill:
24+
Install the CDPLogger Client and a WebSocket polyfill (for the Node.js version):
2525

2626
```bash
2727
npm install cdp-logger-client ws
@@ -38,7 +38,7 @@ Include the following scripts in your HTML:
3838

3939
To enable web support, ensure your `client.js` file includes these modifications:
4040

41-
1. **Use the Browsers Native WebSocket:**
41+
1. **Use the Browser's Native WebSocket:**
4242
In the web version, remove or comment out any code that requires a WebSocket polyfill. For example:
4343
```js
4444
// const WebSocket = require('ws'); // Do not use this in the browser
@@ -78,16 +78,33 @@ global.WebSocket = require('ws');
7878
// Create a client instance (endpoint can be "127.0.0.1:17000" or "ws://127.0.0.1:17000")
7979
const client = new cdplogger.Client('127.0.0.1:17000');
8080

81-
// Fetch the API version from the CDP Logger
82-
client.requestApiVersion().then(version => {
83-
console.log("CDP Logger API Version:", version);
84-
});
85-
8681
// List logged nodes (displaying name and routing information)
8782
client.requestLoggedNodes().then(nodes => {
8883
nodes.forEach(node => {
8984
console.log(`Name: ${node.name}, Routing: ${node.routing}`);
9085
});
86+
87+
// If we have nodes, request data points for the first one
88+
if (nodes.length > 0) {
89+
const nodeName = nodes[0].name;
90+
console.log(`\nRequesting data points for node: ${nodeName}`);
91+
92+
// Get log limits and request data points
93+
client.requestLogLimits().then(limits => {
94+
return client.requestDataPoints([nodeName], limits.startS, limits.endS, 10, 0);
95+
}).then(dataPoints => {
96+
console.log(`\nReceived ${dataPoints.length} data points:`);
97+
dataPoints.forEach(point => {
98+
console.log(`Timestamp: ${new Date(point.timestamp * 1000).toISOString()}`);
99+
if (point.value && point.value[nodeName]) {
100+
const val = point.value[nodeName];
101+
console.log(` Min: ${val.min}, Max: ${val.max}, Last: ${val.last}`);
102+
}
103+
});
104+
}).catch(err => {
105+
console.error("Error retrieving data points:", err);
106+
});
107+
}
91108
});
92109

93110
// Disconnect after a short delay (for demonstration purposes)
@@ -119,25 +136,43 @@ Create an HTML file that includes the necessary scripts. For example:
119136
<body>
120137
<script>
121138
// The client is now available globally as "cdplogger" (attached to window)
122-
const client = new cdplogger.Client("ws://127.0.0.1:17000");
123-
124-
// Fetch the API version from the CDP Logger and log it
125-
client.requestApiVersion().then(version => {
126-
console.log("CDP Logger API Version:", version);
127-
});
139+
// Use window.location.hostname to connect to the same host as the web page
140+
const client = new cdplogger.Client(window.location.hostname + ":17000");
128141
129142
// List logged nodes and output their names and routings
130143
client.requestLoggedNodes().then(nodes => {
131144
nodes.forEach(node => {
132145
console.log(`Name: ${node.name}, Routing: ${node.routing}`);
133146
});
147+
148+
// If we have nodes, request data points for the first one
149+
if (nodes.length > 0) {
150+
const nodeName = nodes[0].name;
151+
console.log(`\nRequesting data points for node: ${nodeName}`);
152+
153+
// Get log limits and request data points
154+
client.requestLogLimits().then(limits => {
155+
return client.requestDataPoints([nodeName], limits.startS, limits.endS, 10, 0);
156+
}).then(dataPoints => {
157+
console.log(`\nReceived ${dataPoints.length} data points:`);
158+
dataPoints.forEach(point => {
159+
console.log(`Timestamp: ${new Date(point.timestamp * 1000).toISOString()}`);
160+
if (point.value && point.value[nodeName]) {
161+
const val = point.value[nodeName];
162+
console.log(` Min: ${val.min}, Max: ${val.max}, Last: ${val.last}`);
163+
}
164+
});
165+
}).catch(err => {
166+
console.error("Error retrieving data points:", err);
167+
});
168+
}
134169
});
135170
</script>
136171
</body>
137172
</html>
138173
```
139174

140-
*In the browser version, by including `client.js` (with the modifications described above), the client automatically uses the native WebSocket, the global protobuf definitions from `window.root`, and attaches the API to `window.cdplogger`.*
175+
*In the browser version, we use `window.location.hostname` to connect to the same host as the web page, with the default logger port 17000.*
141176

142177
## Prerequisites
143178

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CDPLogger Client for JavaScript
22

33
A simple JavaScript interface for communicating with CDP applications that include a CDPLogger component to retrieve historic data.
4-
- For documentation on the JS logger see [DOCUMENTATION.md](DOCUMENTATION.md).
4+
- For documentation on the JS logger client see [DOCUMENTATION.md](DOCUMENTATION.md).
55
- For a quickstart guide on how to set-up the npm project for either Node or Web see [QUICKSTART.md](QUICKSTART.md)
66
- For more information about CDP Studio see https://cdpstudio.com/.
77

0 commit comments

Comments
 (0)