diff --git a/.gitignore b/.gitignore index 1d57ba1..77dcfc5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .idea/ node_modules/ +package-lock.json diff --git a/README.md b/README.md index 48adfdb..3a7a61d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Therefore, you need to install the CometD JavaScript Client, version 3.1.2 or gr npm install cometd ``` -### Usage +### Usage (CommonJS) ```javascript // Run the adapter code that implements XMLHttpRequest. @@ -38,4 +38,16 @@ var cometd = new lib.CometD(); ... ``` +### Usage (ES Modules) + +```javascript +import { CometD } from 'cometd'; +import { adapt } from 'cometd-nodejs-client'; +// Shim XMLHTTPRequest for Node.js (required by CometD). +adapt(); + +// Your normal CometD client application here. +const client = new CometD(); +``` + See [here](https://github.com/cometd/cometd-javascript/blob/master/README.md) for an example CometD client application. diff --git a/cometd-nodejs-client.d.ts b/cometd-nodejs-client.d.ts new file mode 100644 index 0000000..e172e03 --- /dev/null +++ b/cometd-nodejs-client.d.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export interface HttpProxy { + uri?: string; + includes?: string[]; + excludes?: string[]; +} + +export interface Options { + logLevel?: "debug" | "info"; + httpProxy?: HttpProxy; +} + +export function adapt(options?: Options): void; diff --git a/package.json b/package.json index f12d787..4c26028 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "license": "Apache-2.0", "main": "cometd-nodejs-client.js", + "types": "cometd-nodejs-client.d.ts", "repository": { "type": "git", "url": "https://github.com/cometd/cometd-nodejs-client.git"