The JavaScript client library for [crs](https://github.com/Invenietis/crs)
npm install crs-clientjavascript
import { CrsEndpoint, Command } from 'crs-client';
// Create a command class and bound to a CRS commmand
@Command('supercommand')
class SuperCommand {
constructor(hello) {
this.hello = hello;
}
}
// create a new endpoint where {server url} is your server URL (empty is same origin)
// and {crs endpoint} is the path to the CRS endpoint
const endpoint = new CrsEndpoint('{server url}/{crs endpoint}');
// initialize the endpoint
endpoint.connect();
// send the command
emitter.send(new SuperCommand('hello world!'))
.then(response => {
console.log(response);
});
`
$3
First, include the library `crs-client.js` in your HTML
`javascript
`
The script will add the `Crs` object on the `window` object.
`javascript
// Specify the command name.
Crs.Command('supercommand')(SuperCmd)
function SuperCmd(hello) {
this.hello = hello;
}
// create a new endpoint
var endpoint = new Crs.CrsEndpoint('{server url}/{crs endpoint}');
// initialize the endpoint
endpoint.connect();
// send the command
const response = await endpoint.send(new SuperCmd('hello world!'));
``